sms_autofill icon indicating copy to clipboard operation
sms_autofill copied to clipboard

setState() or markNeedsBuild() called during build.

Open haroonkhan9426 opened this issue 5 years ago • 4 comments
trafficstars

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. (package:flutter/src/widgets/framework.dart:4211:11) #1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4226:6) #2 State.setState (package:flutter/src/widgets/framework.dart:1260:14) #3 _OtpPageState.build.. (package:ponasasadoctor/ui/auth/otp/otp_page.dart:124:31) #4 _PinFieldAutoFillState.codeUpdated (package:sms_autofill/sms_autofill.dart:134:29)

haroonkhan9426 avatar Sep 16 '20 12:09 haroonkhan9426

facing same issue

sudo-ulmas avatar Oct 22 '20 11:10 sudo-ulmas

I guess the onChange method is being activated initially, which shouldn't happen since it didn't change.

cedvdb avatar Feb 02 '21 16:02 cedvdb

getting same issue

yash365 avatar Mar 02 '21 14:03 yash365

can you tell me if it's better on 2.2.0 please?

jaumard avatar Oct 12 '21 08:10 jaumard