Introduction
I am working on Flutter and Dart.
In the app, I have a screen that displays the result of the invoice scan,
It doesn’t matter whats the content there,
because the question not related to it.
Within this screen I added a button named Finish
,
which suppose to take the user to the HomeScreen
.
Actually, this button takes the user to the HomeScreen
as expected,
but then, trying to scan another invoice face an error.
e.g, For the first scan it succeeds, but comes back to home
by the Finish
button probably causes a Bug,
so the next try to scan is failed.
Actually, I tried two approaches, where the first works well,
but the second faces a Bug.
The relevant code snippet
Attention:
Share
Button (and its implementation code,
consist of _showExportOptions
),
dose not relevant for the question.
Attention:
You have to uncomment the approach you want to test.
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start, // Align all buttons to the start
children: [
// 'Share' Button
InkWell(
onTap: () => _showExportOptions(context, widget.vendor),
child: _buildIconButton(Icons.share, 'Share', color: Colors.white),
),
SizedBox(width: 16), // Space between buttons
// 'Finish' Button
InkWell(
onTap: () async {
/*
// The first approch: you see 3 `Navigator lines`
// because for my app this takes you to `HomePage`.
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop();
Provider.of<SupplierModel>(context, listen: false).reset();
*/
/*
// The second approach
Navigator.of(context).pushNamed(HomeScreen.routename, arguments: 1);
Provider.of<SupplierModel>(context, listen: false).reset();
*/
},
child: _buildIconButton(Icons.check, 'Finish', color: Colors.white),
),
],
);
}
Widget _buildIconButton(IconData icon, String label, {Color? color}) {
return Column(
children: [
Icon(icon, color: color),
Text(label, style: TextStyle(color: color)),
],
);
}
The issue
Expected:
A button for going back to HomeScreen
.
Actually:
The user came back to Home Screen
, but after that, trying to scan a new invoice failed.
With this approcah, all works well:
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop();
Provider.of<SupplierModel>(context, listen: false).reset();
However, with this approach, an error occurs:
Provider.of<SupplierModel>(context, listen: false).reset();
Navigator.of(context).pushNamed(HomeScreen.routename, arguments: 1);
The error massage
@pragma("vm:external-name", "Error_throwWithStackTrace")
Concurrent modification during iteration: Instance(length:36) of '_GrowableList'.
Somtimes, insted of the error massage i see:
“Your invoice is not align”.
Attention:
I also tried to place the Provider
after the Navigator
,
but that does not solve it.
Moreever, I also tried to use Future delay of 100 miliseconds,
but its is also failed.
Yogev Arye is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.