I was trying to implement a checkbox that would disable and enable a button. But I was blocked by this following error:
I/flutter (19999): The following assertion was thrown building DisclaimerPage(dirty, state: DisclaimerPageState#24b3d):
I/flutter (19999): setState() or markNeedsBuild() called during build.
I/flutter (19999): This Overlay widget cannot be marked as needing to build because the framework is already in the
I/flutter (19999): process of building widgets. A widget can be marked as needing to be built during the build phase
I/flutter (19999): only if one of its ancestors is currently building. This exception is allowed because the framework
I/flutter (19999): builds parent widgets before children, which means a dirty descendant will always be built.
I/flutter (19999): Otherwise, the framework might not visit this widget during this build phase.
Here is my code for building the page:
class DisclaimerPageState extends State<DisclaimerPage> {
bool checkBoxValue = false;
@override
Widget build(BuildContext context) {
var _floatButtonOnPressed;
if (checkBoxValue) {
_floatButtonOnPressed = navToHome();
}
return new Scaffold(
appBar: AppBar(
title: Text("Disclaimer"),
leading: Container(),
),
body: Container(
child: Card(
child: Column(
children: <Widget>[
Text("ADHJASDKHKDAD"),
Row(
children: <Widget>[
Checkbox(
value: checkBoxValue,
onChanged: (bool newValue) {
setState(() {
checkBoxValue = newValue;
});
}),
Text("I understand"),
],
),
],
),
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _floatButtonOnPressed,
label: Text("PROCEED"),
icon: Container(),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
navToHome() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImmunityHomePage(title: 'ImMUnity')),
);
}
}
Am I doing something wrong? My checkbox implementation is based on the documentation of checkbox.dart. So I am a little confused here. Help is appreciated. Thank you so much!
Aucun commentaire:
Enregistrer un commentaire