fix: ontap not working when custom header is set

This commit is contained in:
Jacques Doeleman 2022-10-26 16:39:47 +02:00
parent 610012ca5b
commit 485e1c6952
3 changed files with 57 additions and 43 deletions

View file

@ -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

View file

@ -1,4 +1,4 @@
export './audio_service.dart';
export './media_picker_input.dart';
export './media_picker_service.dart';
export './video_player_factory.dart';
export './video_player_factory.dart';

View file

@ -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<String, dynamic> 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<void> 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<String, dynamic> 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;
}