Flutter Heroes
25.9K subscribers
272 photos
2 videos
31.1K links
Download Telegram
New post on /r/flutterdev subreddit:

<b>setState() or markNeedsBuild() called during build Flutter StreamBuilder</b>
Hi,I want to design login page, and login will be done via http post, get etc..For simplicity, and also to learn flutter easy way, I have created login page, when user enters email and password, I am just doing http get via this url "<a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts/1</a>"&#8203;I have also followed this medium article: <a href="https://medium.com/flutterpub/architecting-your-flutter-project-bd04e144a8f1">https://medium.com/flutterpub/architecting-your-flutter-project-bd04e144a8f1</a>When users clicks the login button, I just want to show AlertDiaglog => "Succesfull" otherwise empty container. The problem is beginning when the user clicks the button, I have got an exception like this:<pre> I/flutter ( 5383): &#9552;&#9552;&#9569; EXCEPTION CAUGHT BY WIDGETS LIBRARY &#9566;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552; I/flutter ( 5383): The following assertion was thrown building StreamBuilder<Person>(dirty, state: I/flutter ( 5383): _StreamBuilderBaseState<Person, AsyncSnapshot<Person>>#f7943): I/flutter ( 5383): setState() or markNeedsBuild() called during build. I/flutter ( 5383): This Overlay widget cannot be marked as needing to build because the framework is already in the I/flutter ( 5383): process of building widgets. A widget can be marked as needing to be built during the build phase I/flutter ( 5383): only if one of its ancestors is currently building. This exception is allowed because the framework I/flutter ( 5383): builds parent widgets before children, which means a dirty descendant will always be built. I/flutter ( 5383): Otherwise, the framework might not visit this widget during this build phase. Here is the login bloc code: ````dart import 'package:tez_flutter_app/src/model/person.dart'; import 'package:tez_flutter_app/src/repository/repository.dart'; import 'package:rxdart/rxdart.dart'; class LoginBlocTry{ final Repository _repository = Repository(); final PublishSubject<Person> _logInFetcher = PublishSubject<Person>(); Observable<Person> get getUserToken => _logInFetcher.stream; logIn() async{ Person person = await _repository.logIn(); _logInFetcher.sink.add(person); } dispose(){ _logInFetcher.close(); } } final bloc = LoginBlocTry(); </pre>Here is the ui (I will copy the build method of stateful widget)<pre>@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(Localization.of(context).getText(text: "title")), ), body: Container( child: Form( key: _formKey, child: buildContainerChild(context), ), ) ); } ListView buildContainerChild(BuildContext context) { return ListView( children: <Widget>[ buildLoginTextView(context), SizedBox(height: 60.0,), buildUserInputForm(Localization.of(context).getText(text: "enterMail"), Localization.of(context).getText(text: "email"), context), buildUserInputForm(Localization.of(context).getText(text: "password"), Localization.of(context).getText(text: "passwordHint"), context, showPasswordIcon: true), SizedBox(height: 20.0,), buildLogInButton(context), SizedBox(height: 20.0,), buildClickableTextView(context, text: Localization.of(context).getText(text: "createAccount")), SizedBox(height: 20.0,), buildClickableTextView(context, text: Localization.of(context).getText(text: "forgetPassword")), SizedBox(height: 20.0,), StreamBuilder( stream: bloc.getUserToken, builder:streamSample ) ], ); } Widget streamSample(context, AsyncSnapshot<Person> snapshot) { if (snapshot.hasData) { setState(() { showDialog( context:…