sms_autofill
sms_autofill copied to clipboard
setState() or markNeedsBuild() called during build.
This issue arises when I call setState in onChange button.
I'm using this widget inside a stateful widget.
PinFieldAutoFill( codeLength: 4, onCodeChanged: (v) { setState(() {}); print("code change $v"); }, onCodeSubmitted: (v) { print("code submitted $v"); setState(() { otpInput = v; }); }, ),
Another exception was thrown: setState() or markNeedsBuild() called during build.
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following assertion was thrown building Container(margin: EdgeInsets(50.0, 0.0, 50.0, 0.0)): setState() or markNeedsBuild() called during build.
This OtpPage widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: OtpPage
state: _OtpPageState#73493
The widget which was currently being built when the offending call was made was: Container
margin: EdgeInsets(50.0, 0.0, 50.0, 0.0)
The relevant error-causing widget was:
Container file:///Users/eapple/git/ponasasa-doctor/lib/ui/auth/otp/otp_page.dart:117:25
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.
facing same issue
I guess the onChange method is being activated initially, which shouldn't happen since it didn't change.
getting same issue
can you tell me if it's better on 2.2.0 please?