readImagePath function
Future<String?>
readImagePath({
- required dynamic context,
- ImageSource source = ImageSource.camera,
- bool preview = true,
Implementation
Future<String?> readImagePath({
required context,
ImageSource source = ImageSource.camera,
bool preview = true,
}) async {
String? data;
if (kIsWeb) {
data = await _getImageWeb(context);
return data;
} else {
var ip = ImagePicker();
var image = await ip.getImage(source: source);
if (image != null) {
data = image.path;
} else {
return null;
}
}
var prefs = await SharedPreferences.getInstance();
if (kIsWeb) {
prefs.setString(LOC_STORAGE_KEY, data);
data = LOC_STORAGE_KEY;
}
if (preview) {
var result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => kIsWeb
? ImageFilePreviewRoute()
: ImageFilePreviewRoute(path: data),
),
);
return result;
} else {
return data;
}
}