Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
PFM-5009
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldevgarg committed Nov 24, 2023
1 parent 9fd21e0 commit 9d4da61
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion frontend/mgramseva/lib/repository/core_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:universal_html/html.dart' as html;

enum FileUploadStatus {
NOT_ACTIVE,STARTED,COMPLETED
}
class CoreRepository extends BaseService {
Future<List<LocalizationLabel>> getLocilisation(
Map<String, dynamic> query) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class _ExpenseDetailsState extends State<ExpenseDetails> {
key: expensesDetailsProvider.filePickerKey,
callBack:
expensesDetailsProvider.fileStoreIdCallBack,
extensions: ['jpg', 'pdf', 'png'],
extensions: ['jpg', 'pdf', 'png', 'jpeg'],
contextKey: expenseProvider
.expenseWalkthrougList[5].key,
),
Expand Down
27 changes: 27 additions & 0 deletions frontend/mgramseva/lib/widgets/file_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FilePickerDemoState extends State<FilePickerDemo> {
FileType _pickingType = FileType.custom;
TextEditingController _controller = TextEditingController();
final ImagePicker _picker = ImagePicker();
FileUploadStatus fileUploading = FileUploadStatus.NOT_ACTIVE;

@override
void initState() {
Expand Down Expand Up @@ -92,11 +93,20 @@ class FilePickerDemoState extends State<FilePickerDemo> {

uploadFiles(List<dynamic> files) async {
try{
setState(() {
fileUploading = FileUploadStatus.STARTED;
});
var response = await CoreRepository().uploadFiles(files, widget.moduleName ?? APIConstants.API_MODULE_NAME);
setState(() {
fileUploading = FileUploadStatus.COMPLETED;
});
_fileStoreList.addAll(response);
if(_selectedFiles.isNotEmpty)
widget.callBack(_fileStoreList);
}catch(e){
setState(() {
fileUploading = FileUploadStatus.NOT_ACTIVE;
});
Notifiers.getToastMessage(context, e.toString(), 'ERROR');
}
}
Expand Down Expand Up @@ -190,6 +200,19 @@ class FilePickerDemoState extends State<FilePickerDemo> {
: Text(
"${ApplicationLocalizations.of(context).translate(i18.common.NO_FILE_UPLOADED)}",
style: TextStyle(color: Colors.black, fontSize: 16),
),
Row(
children: [
fileUploading==FileUploadStatus.STARTED?Text("Uploading File",style: TextStyle(
color: Colors.black
),):SizedBox(),
fileUploading==FileUploadStatus.STARTED?Transform.scale(
scale: 0.5,
child: CircularProgressIndicator(),
)
:fileUploading==FileUploadStatus.COMPLETED?Icon(Icons.check_circle,color: Theme.of(context).primaryColor,)
:SizedBox(),
],
)
],
))
Expand All @@ -199,12 +222,16 @@ class FilePickerDemoState extends State<FilePickerDemo> {
void onClickOfClear(int index){
setState(() {
_selectedFiles.removeAt(index);
fileUploading = FileUploadStatus.NOT_ACTIVE;
if(index < _fileStoreList.length) _fileStoreList.removeAt(index);
});
widget.callBack(_fileStoreList);
}

void reset(){
setState(() {
fileUploading = FileUploadStatus.NOT_ACTIVE;
});
_selectedFiles.clear();
_fileStoreList.clear();
}
Expand Down

0 comments on commit 9d4da61

Please sign in to comment.