From bd53221bdc4a5f2ddaa0df6a9a3b27cff0577ab0 Mon Sep 17 00:00:00 2001 From: Joey Boerwinkel Date: Mon, 19 Jun 2023 10:56:06 +0200 Subject: [PATCH] fix: remove null check operator and perform appropriate null check Now it is no longer possible to break the widget by providing a null value to the disabledPickers property. Making the property to a non-nullable list would remove more complexity, but introduces breaking changes. --- CHANGELOG.md | 4 ++++ lib/src/media_picker.dart | 10 ++++++---- pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3225c74..c0372f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2 + +- Remove null check operator for disabledPickers and perform appropriate null check + ## 0.6.1 - Gave disabledPickers a default value to stop null errors. diff --git a/lib/src/media_picker.dart b/lib/src/media_picker.dart index 4503f6e..dfd6a59 100644 --- a/lib/src/media_picker.dart +++ b/lib/src/media_picker.dart @@ -145,9 +145,7 @@ class _MediaPickerState extends State { ), ]; - if (widget.mediaPickerInputs != null) { - inputs = widget.mediaPickerInputs!; - } + inputs = widget.mediaPickerInputs ?? inputs; var theme = Theme.of(context); return Wrap( @@ -166,7 +164,7 @@ class _MediaPickerState extends State { ), ] else ...[ for (final input in inputs) ...[ - if (widget.disabledPickers!.contains(input.label) == true) ...[ + if (isInputDisabled(input)) ...[ IgnorePointer( child: gestureDetectorWidget(input, theme), ) @@ -179,6 +177,10 @@ class _MediaPickerState extends State { ); } + bool isInputDisabled(MediaPickerInput input) { + return widget.disabledPickers?.contains(input.label) ?? false; + } + Future onPressedMediaType( BuildContext context, MediaPickerInput input) async { MediaResult content = await input.onPressed(context); diff --git a/pubspec.yaml b/pubspec.yaml index f4d93cd..5f87caf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_media_picker description: A new Flutter package project. -version: 0.6.1 +version: 0.6.2 homepage: https://github.com/Iconica-Development/flutter_media_picker publish_to: "none"