diff --git a/CHANGELOG.md b/CHANGELOG.md index d5924d4..bc73175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.1.1 - [22/03/2022] + +* Updated example project to null safety. +* Fixed potential issue with null value for methods `getImageInfo`, `getVideoAsBytes` and `getVideoInfo`. + ## 2.1.0 - [14/12/2021] * Deprecated `getImage`, `getMultiImages` and `getVideo` methods. diff --git a/example/lib/sample/sample_page.dart b/example/lib/sample/sample_page.dart index d0b7b6d..b113f9d 100644 --- a/example/lib/sample/sample_page.dart +++ b/example/lib/sample/sample_page.dart @@ -48,12 +48,12 @@ class _SamplePageState extends State { Future _getImgInfo() async { final infos = await ImagePickerWeb.getImageInfo; - final data = infos.data; + final data = infos?.data; if (data != null) { setState(() { _pickedImages.clear(); - _pickedImages.add(Image.memory(data, semanticLabel: infos.fileName)); - _imageInfo = '${infos.toJson()}'; + _pickedImages.add(Image.memory(data, semanticLabel: infos?.fileName)); + _imageInfo = '${infos?.toJson()}'; }); } } diff --git a/lib/image_picker_web.dart b/lib/image_picker_web.dart index f351a3a..3e24055 100644 --- a/lib/image_picker_web.dart +++ b/lib/image_picker_web.dart @@ -193,10 +193,11 @@ class ImagePickerWeb { /// Help to retrieve further image's informations about your picked source. /// /// Return an object [MediaInfo] containing image's informations. - static Future get getImageInfo async { + static Future get getImageInfo async { final data = await (_methodChannel.invokeMapMethod('pickImage')); - return MediaInfo.fromJson(data!); + if (data == null) return null; + return MediaInfo.fromJson(data); } /// Picker that allows multi-image selection. Here are the different instance @@ -286,11 +287,9 @@ class ImagePickerWeb { static Future getVideoAsBytes() async { final data = await _methodChannel.invokeMapMethod('pickVideo'); - if (data != null) { - final imageData = base64.decode(data['data']); - return imageData; - } - return null; + if (data == null) return null; + final imageData = base64.decode(data['data']); + return imageData; } /// Picker that close after selecting 1 video and return a [html.File] of the @@ -305,7 +304,7 @@ class ImagePickerWeb { static Future get getVideoInfo async { final data = await _methodChannel.invokeMapMethod('pickVideo'); - if (data != null) return MediaInfo.fromJson(data); - return null; + if (data == null) return null; + return MediaInfo.fromJson(data); } } diff --git a/pubspec.yaml b/pubspec.yaml index 1168fad..0c075af 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: image_picker_web description: Flutter Web Plugin to pick Images (as Widget, File or Uint8List) and Videos (as File or Uint8List) -version: 2.1.0 +version: 2.1.1 repository: https://github.com/Ahmadre/image_picker_web environment: