File tree 1 file changed +30
-0
lines changed
tipsandtricks/future-unwrap-in-flutter
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ // š¦ Twitter https://twitter.com/vandadnp
2
+ // šµ LinkedIn https://linkedin.com/in/vandadnp
3
+ // š„ YouTube https://youtube.com/c/vandadnp
4
+ // š Free Flutter Course https://linktr.ee/vandadnp
5
+ // š¦ 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY
6
+ // š¶ 7+ Hours MobX Course https://youtu.be/7Od55PBxYkI
7
+ // š¦ 8+ Hours RxSwift Coursde https://youtu.be/xBFWMYmm9ro
8
+ // š¤ Want to support my work? https://buymeacoffee.com/vandad
9
+
10
+ import 'dart:async' ;
11
+ import 'dart:io' ;
12
+ import 'package:image_picker/image_picker.dart' ;
13
+
14
+ extension Unwrap <T > on Future <T ?> {
15
+ Future <T > unwrap () => then (
16
+ (value) => value != null
17
+ ? Future <T >.value (value)
18
+ : Future .any ([]),
19
+ );
20
+ }
21
+
22
+ @immutable
23
+ class ImagePickerHelper {
24
+ static final ImagePicker _imagePicker = ImagePicker ();
25
+ static Future <File > pickImageFromGallery () => _imagePicker
26
+ .pickImage (source: ImageSource .gallery)
27
+ .unwrap ()
28
+ .then ((xFile) => xFile.path)
29
+ .then ((filePath) => File (filePath));
30
+ }
You canāt perform that action at this time.
0 commit comments