Questions tagged [flutter-bloc]

For questions relating to the "flutter_bloc" package for the Flutter framework. Use this tag in combination with the general [flutter] tag. If your question applies to Flutter more generally, use the [flutter] tag only.

This tag should be used for any questions regarding the flutter_bloc package for the Flutter framework.

flutter_bloc is a package implementing the BloC pattern for Flutter, specifically the BlocProvider and BlocBuilder classes.

To get started, you can read through the README document on GitHub.

932 questions
44
votes
16 answers

Flutter error: Each child must be laid out exactly once. On building layout

I'm using flutter_bloc. I've got code like this: class Settings extends StatelessWidget { final _formKey = GlobalKey(); @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( …
Tomaszeek
  • 483
  • 1
  • 4
  • 11
41
votes
6 answers

BlocProvider.of() called with a context that does not contain a Bloc - even that it does

First of, I do know how BLoC suppose to work, the idea behind it and I know the difference between BlocProvider() and BlocProvider.value() constructors. For simplicity, my application has 3 pages with a widget tree like this: App() => LoginPage() =>…
Stahp
  • 972
  • 1
  • 9
  • 16
32
votes
3 answers

Triggering initial event in BLoC

example_states: abstract class ExampleState extends Equatable { const ExampleState(); } class LoadingState extends ExampleState { // } class LoadedState extends ExampleState { // } class FailedState extends ExampleState { …
vendrick
  • 478
  • 1
  • 5
  • 12
25
votes
5 answers

Flutter listen Bloc state from Other Bloc

Hello I'm trying to listen state of bloc form other bloc. I'm using this package https://pub.dev/packages/bloc From my UserBloc I want listen AuthBloc and when It has the state AuthenticationAuthenticated the UserBloc should fire an event. final…
LorenzoBerti
  • 6,704
  • 8
  • 47
  • 89
24
votes
2 answers

Can anyone tell the difference of "flutter_bloc" and "bloc" packages in Flutter

I am getting started with Bloc in Flutter. Can anyone tell what is really "flutter_bloc" and "bloc" packages I have these questions. are they same. when/how to use this. Thank you
21
votes
3 answers

using Equatable class with flutter_bloc

Why do we need to use the Equatable class with flutter_bloc? Also, what do we use the props for? Below is sample code for making a state using the bloc pattern in Flutter. abstract class LoginStates extends Equatable{} class…
Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61
17
votes
2 answers

BlocBuilder not updating after cubit emit

UPDATE After finding the onChange override method it appears that the updated state is not being emitted #confused UPDATE 2 Further debugging revealed that the StreamController appears to be closed when the updated state attempts to emit. For some…
RemeJuan
  • 823
  • 9
  • 25
14
votes
3 answers

flutter_bloc : Make initialState method async

I am using the flutter_bloc package to manage state in my app. I have a usecase where I have to load the initial state from the remote DB. This requires the initialState method to be async, which it is not. If not by using the initialState method,…
sharath
  • 3,501
  • 9
  • 47
  • 72
13
votes
2 answers

How can Bloc listen to stream and emit state

In my flutter app, I use flutter_bloc for state management. The bloc in question uses a repository. The repository subscribes to a websocket, and new data is added to a stream. Problem: My bloc listens to the stream: InvestmentClubBloc({ …
Vingtoft
  • 13,368
  • 23
  • 86
  • 135
13
votes
2 answers

The method 'bloc' isn't defined for the type 'BuildContext'

Widget build(BuildContext context) { final appBar = AppBar( title: Text( "Romantic Comedy", ), actions: [ IconButton( icon: Icon(Icons.search), onPressed: () { showSearch( …
Abraham Mathew
  • 2,029
  • 3
  • 21
  • 42
13
votes
6 answers

BlocProvider.value Vs BlocProvider(create:)

i am using flutter_bloc, and i am wondering which method should i use and what is the difference between these two ways?: i read that the first one with (value) the bloc will not automatically closed, but actually i don't understand what is…
Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61
12
votes
3 answers

Flutter how to get brightness without MediaQuery?

My goal is to create an app where the user can choose his preferred theme. I'm saving the user's choice with shared preferences so I can load it the next app start. The user can either select: - Dark Mode (Independent from the OS Settings) - Light…
Just A Question
  • 423
  • 6
  • 21
11
votes
3 answers

What is the use of BlocSelector in flutter_bloc

There is no example found for the usage of BlocSelector. Anyone knows the real usage of it?
viki
  • 404
  • 3
  • 14
11
votes
2 answers

Provider .read() vs .watch()

I just updated my flutter_bloc library to 6.1.1 in which states: bloc' is deprecated and shouldn't be used. Use context.read or context.watch instead. Will be removed in v7.0.0. Try replacing the use of the deprecated member with the…
Georgios
  • 861
  • 2
  • 12
  • 30
11
votes
3 answers

Flutter Bloc does not change TextFormField initialValue

I'm using Bloc library and noticed after yielding a new state my TextFormField initialValue does not change. My app is more complicated than this but I did a minimal example. Also tracking the state it is changing after pushing the events. Bloc is…
loki
  • 2,271
  • 5
  • 32
  • 46
1
2 3
62 63