From d9c0c53106c7881b85ae4ab2c46775ed132972c4 Mon Sep 17 00:00:00 2001 From: Xin Yao Date: Wed, 23 Jun 2021 09:54:53 -0700 Subject: [PATCH] Update _pickImageDesktop method --- lib/src/widgets/toolbar/image_button.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/widgets/toolbar/image_button.dart b/lib/src/widgets/toolbar/image_button.dart index a94fa89a..813015de 100644 --- a/lib/src/widgets/toolbar/image_button.dart +++ b/lib/src/widgets/toolbar/image_button.dart @@ -64,10 +64,11 @@ class ImageButton extends StatelessWidget { if (kIsWeb) { imageUrl = await _pickImageWeb(onImagePickCallback!); } else if (Platform.isAndroid || Platform.isIOS) { - imageUrl = await _pickImage(imageSource); + imageUrl = await _pickImage(imageSource, onImagePickCallback!); } else { assert(filePickImpl != null, 'Desktop must provide filePickImpl'); - imageUrl = await _pickImageDesktop(context, filePickImpl!); + imageUrl = await _pickImageDesktop( + context, filePickImpl!, onImagePickCallback!); } } @@ -89,21 +90,24 @@ class ImageButton extends StatelessWidget { return onImagePickCallback(file); } - Future _pickImage(ImageSource source) async { + Future _pickImage( + ImageSource source, OnImagePickCallback onImagePickCallback) async { final pickedFile = await ImagePicker().getImage(source: source); if (pickedFile == null) { return null; } - return onImagePickCallback!(File(pickedFile.path)); + return onImagePickCallback(File(pickedFile.path)); } Future _pickImageDesktop( - BuildContext context, FilePickImpl filePickImpl) async { + BuildContext context, + FilePickImpl filePickImpl, + OnImagePickCallback onImagePickCallback) async { final filePath = await filePickImpl(context); if (filePath == null || filePath.isEmpty) return null; final file = File(filePath); - return onImagePickCallback!(file); + return onImagePickCallback(file); } }