ingestMultiple function
Implementation
Future<List<dynamic>> ingestMultiple(
BuildContext context, List<DataField<dynamic>> fields) {
List<dynamic> selected = List.generate(fields.length, (index) => null);
int mindex = 0;
PageController controller = PageController(viewportFraction: 1);
return showDialog(
context: context,
builder: (context) => Dialog(
child: ExpandablePageView(
controller: controller,
children: [
...fields.map((e) {
int index = mindex;
mindex++;
Widget w = Padding(
padding: const EdgeInsets.all(14),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
e.getDataType().getSupportedFetchers().first(
context, e, (value) => selected[index] = value, () {
if (index < fields.length - 1) {
controller.nextPage(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOutCirc);
} else {
Navigator.pop(context, selected);
}
}),
Row(
children: [
const Spacer(),
TextButton(
onPressed: () {
if (index == 0) {
Navigator.pop(context, null);
} else {
controller.previousPage(
duration:
const Duration(milliseconds: 500),
curve: Curves.easeInOutCirc);
}
},
child: Text(index == 0 ? "Cancel" : "Back")),
TextButton(
onPressed: () {
if (index < fields.length - 1) {
controller.nextPage(
duration:
const Duration(milliseconds: 500),
curve: Curves.easeInOutCirc);
} else {
Navigator.pop(context, selected);
}
},
child: Text(index == fields.length - 1
? "Done"
: "Next")),
],
)
],
),
);
return w;
})
],
),
)).then((value) => value ?? selected);
}