Skip to content

Commit 8fd43ef

Browse files
authored
Create future-unwrap-in-flutter.dart
1 parent ad6a79b commit 8fd43ef

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
Ā (0)