-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:file_picker/file_picker.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:tarka_ui/components/button/button.dart'; | ||
import 'package:tarka_ui/components/button/style.dart'; | ||
|
||
class TUIFilePicker extends StatelessWidget { | ||
final bool allowMultipleFiles; | ||
final String title; | ||
final AllowedFileType allowedFileType; | ||
final List<String>? allowedFileExtensions; | ||
final Function(List<PlatformFile>?) filesPicked; | ||
|
||
const TUIFilePicker({ | ||
super.key, | ||
required this.title, | ||
this.allowMultipleFiles = false, | ||
this.allowedFileType = AllowedFileType.any, | ||
this.allowedFileExtensions, | ||
required this.filesPicked, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return TUIButton( | ||
label: title, | ||
type: TUIButtonType.primary, | ||
onPressed: () { | ||
openFiles(); | ||
}); | ||
} | ||
|
||
Future<void> openFiles() async { | ||
List<String> allowedFileExtensions = this.allowedFileExtensions ?? []; | ||
|
||
FilePickerResult? resultFile = await FilePicker.platform.pickFiles( | ||
type: allowedFileType.getFileType(), | ||
allowedExtensions: allowedFileExtensions, | ||
allowMultiple: allowMultipleFiles); | ||
|
||
if (resultFile != null) { | ||
List<PlatformFile> pickedFiles = resultFile.files; | ||
filesPicked(pickedFiles); | ||
} | ||
} | ||
} | ||
|
||
enum AllowedFileType { any, media, image, video, audio, custom } | ||
|
||
extension AllowedFileTypeExtension on AllowedFileType { | ||
FileType getFileType() { | ||
switch (this) { | ||
case AllowedFileType.any: | ||
return FileType.any; | ||
case AllowedFileType.media: | ||
return FileType.media; | ||
case AllowedFileType.image: | ||
return FileType.image; | ||
case AllowedFileType.video: | ||
return FileType.video; | ||
case AllowedFileType.audio: | ||
return FileType.audio; | ||
case AllowedFileType.custom: | ||
return FileType.custom; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.