From 485e1c695215ce10a4a2eeb3f9fc583e3c7b28db Mon Sep 17 00:00:00 2001 From: Jacques Doeleman Date: Wed, 26 Oct 2022 16:39:47 +0200 Subject: [PATCH] fix: ontap not working when custom header is set --- CHANGELOG.md | 8 +++ lib/src/abstracts/abstracts.dart | 2 +- lib/src/media_picker.dart | 90 +++++++++++++++++--------------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6172925..a29731e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ ## 0.0.1 - Initial port + +## 0.0.2 + +- Updated flutter_form version + +## 0.0.3 + +- Fixed bug where onTap was not working when header is set \ No newline at end of file diff --git a/lib/src/abstracts/abstracts.dart b/lib/src/abstracts/abstracts.dart index 4571087..b93977d 100644 --- a/lib/src/abstracts/abstracts.dart +++ b/lib/src/abstracts/abstracts.dart @@ -1,4 +1,4 @@ export './audio_service.dart'; export './media_picker_input.dart'; export './media_picker_service.dart'; -export './video_player_factory.dart'; \ No newline at end of file +export './video_player_factory.dart'; diff --git a/lib/src/media_picker.dart b/lib/src/media_picker.dart index 0718183..4f181c1 100644 --- a/lib/src/media_picker.dart +++ b/lib/src/media_picker.dart @@ -134,50 +134,12 @@ class MediaPicker extends ConsumerWidget { children: [ for (final input in inputs) ...[ const SizedBox(height: 2.5), - header?.call(input.label, input.onPressed) ?? + header?.call(input.label, (BuildContext ct) async { + await onPressedMediaType(ct, input); + }) ?? GestureDetector( onTap: () async { - MediaResult content = await input.onPressed(context); - - if (mediaCheckPage != null && - (input.runtimeType == MediaPickerInputText || - _hasContent(content))) { - var checkPage = mediaCheckPage!( - await input.displayResult(content), - input.checkPageSettings, - (Map results) { - MediaResult result = MediaResult( - fileValue: content.fileValue, - textValue: content.textValue, - checkPageResults: results, - ); - - if (input.onComplete != null) { - input.onComplete!(result); - } - - if (onComplete != null) { - onComplete!(result); - } - }, - ); - - // ignore: use_build_context_synchronously - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => checkPage, - ), - ); - } else { - if (input.onComplete != null) { - input.onComplete!(content); - } - - if (onComplete != null) { - onComplete!(content); - } - } + await onPressedMediaType(context, input); }, child: Container( height: 55, @@ -208,6 +170,50 @@ class MediaPicker extends ConsumerWidget { ); } + Future onPressedMediaType( + BuildContext context, MediaPickerInput input) async { + MediaResult content = await input.onPressed(context); + + if (mediaCheckPage != null && + (input.runtimeType == MediaPickerInputText || _hasContent(content))) { + var checkPage = mediaCheckPage!( + await input.displayResult(content), + input.checkPageSettings, + (Map results) { + MediaResult result = MediaResult( + fileValue: content.fileValue, + textValue: content.textValue, + checkPageResults: results, + ); + + if (input.onComplete != null) { + input.onComplete!(result); + } + + if (onComplete != null) { + onComplete!(result); + } + }, + ); + + // ignore: use_build_context_synchronously + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => checkPage, + ), + ); + } else { + if (input.onComplete != null) { + input.onComplete!(content); + } + + if (onComplete != null) { + onComplete!(content); + } + } + } + bool _hasContent(MediaResult content) { return content.fileValue != null || content.textValue != null; }