Reputation: 652
I'm having an issue with my Dialog.
I have a home screen with code to navigate to a second screen like so:
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return SecondScreen("myData");
}
));
This goes to the next screen as it should. On the second screen I eventually show a dialog, it shows up correctly but once I click on an TextFormField within the dialog the above builder function is called again, creating my SecondScreen all over again. Then, once I dismiss the dialog with a pop() it calls the above code yet again.
I want to be able to use my dialog without it triggering the above code snippet. Does anyone know how to do that or why this is happening?
EDIT - Here is the code showing how the dialog is shown:
StreamBuilder<String>(
stream: model.taxStream,
builder: (context, snapshot) {
return ListTile(
onTap: () async {
double taxAmount = await showEditAmountDialog(
context, "Tax", model.taxValue());
if (taxAmount != null) {
model.setTax(taxAmount);
}
},
title: Text("Tax"),
trailing: Text(snapshot.hasData ? snapshot.data : ""),
);
},
);
Upvotes: 1
Views: 1109
Reputation: 728
According to the flutter developers, rebuilding the widgets is the desired scenario. They have mentioned this in git issues. The architecture design should be designed by keeping in mind that the widgets are supposed to be rebuilt. Not rebuilding widgets again and again, is an optimization that flutter provides. But it shouldn't be assumed that this is the default behavior of widgets in flutter. The default behavior is to rebuild. Hope this helps!
Upvotes: 1