Created
August 17, 2020 16:31
-
-
Save AdamMusa/d41c523d254c06ff5b237ccf801c5754 to your computer and use it in GitHub Desktop.
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
import 'dart:io'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter_absolute_path/flutter_absolute_path.dart'; | |
import 'package:multi_image_picker/multi_image_picker.dart'; | |
class FetchImage with ChangeNotifier { | |
List<File> _files; | |
List<String> _list; | |
List<File> get files => _files; | |
List<String> get list => _list; | |
Future<void> init() async { | |
/// uri can be of android scheme content or file | |
/// for iOS PHAsset identifier is supported as well | |
List<Asset> assets = await selectImagesFromGallery(); | |
List<File> files = []; | |
for (Asset asset in assets) { | |
final filePath = | |
await FlutterAbsolutePath.getAbsolutePath(asset.identifier); | |
files.add(File(filePath)); | |
} | |
List<String> data = []; | |
_files = files; | |
notifyListeners(); | |
if(files==null){ | |
return null; | |
} | |
else{ | |
files.forEach((element) { | |
data.add(element.path); | |
}); | |
} | |
_list = data; | |
notifyListeners(); | |
} | |
Future<List<Asset>> selectImagesFromGallery() async { | |
return await MultiImagePicker.pickImages( | |
maxImages: 65536, | |
enableCamera: true, | |
materialOptions: MaterialOptions( | |
actionBarColor: "#FF147cfa", | |
statusBarColor: "#FF147cfa", | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment