Questions tagged [cubit]
153 questions
15
votes
4 answers
Flutter BLoC library: Where to keep the TextEditingController object: in State, in BLoC / Cubit class or in the widget?
While using BLoC library we store all the variables in a state class. But where to store TextEditingController, which does not change, but the value of it does?
Let's say I have a state class like this (Just as example):
@freezed
abstract class…

Thomas
- 851
- 9
- 15
11
votes
2 answers
How to use flutter internationalization inside BLOC, Cubit And Repositories for translate messages?
I am working on a multilingual app in Flutter.
I used flutter_localizations package for localization and intl package for internationalization.
In the normal way inside Widgets, I can use it with help of Context.
But the problem is when I want to…

Taleb
- 1,944
- 2
- 11
- 36
6
votes
1 answer
Can i call cubit from another cubit?
i'm working on an application that uses cubits, to manage the state.
Very often when i need to make an api request i need to get my current localization (handle possible exceptions) and then send it to backend. So i guess i should use cubit for the…

Nepath
- 61
- 3
6
votes
1 answer
How to use BlocBuilder to refresh a Dialog in Flutter
I have a dialog and I wrap it in a blocbuilder to update it according to the type of state but the dialog just is built First time and after state has changed it doesn't rebuild.
showDialog(
context: context,
builder: (_) {
…

Parisa Baastani
- 1,713
- 14
- 31
5
votes
4 answers
How to call a function in cubit class in initState?
So, I have made a function in Cubit Class it is to get data from API. For now I just can get the data if I pressed a button. I wanna make the function automatically called when the page/screen is open. For your information, this page is the first…

Alun Paranggi Wicaksono
- 329
- 4
- 9
5
votes
1 answer
How to add multiple state in one cubit in flutter bloc pattern?
I was developing an application in flutter which does OTP based authentication to log in. Earlier I was managing the states in the class itself so that I can use the setState method to render the UI accordingly. Then I changed into flutter_bloc…

Musthafa
- 87
- 1
- 2
- 6
4
votes
1 answer
Using PageView with Bloc to programmatically 'swipe' pages. Prevent the bloc builder from building on certain states?
I've built a PageView and want to control page swiping programmatically using a Bloc.
I'm using a PageController and listening for my bloc's ShowPage state. Then calling pageController.animateTo to animate the PageView to the desired page.
The bloc…

Simon Hutton
- 1,677
- 3
- 22
- 35
4
votes
1 answer
How I can change theme with a switch in flutter using bloc?
I am new in Flutter and bloc. I am making a app with bloc state management that can change the theme as the system theme changed. Now it work fine but I need switch that can override the theme. How can I implement that? I am making this app by…

Sunny Rahi
- 99
- 1
- 6
3
votes
2 answers
Flutter Bloc Listen to stream and emit state with Cubit
How can I listen to stream and emit state with Cubit?
With Bloc we can do something like this:
on(
(event, emit) async {
if (event.play) {
await emit.forEach(
…

Soliev
- 1,180
- 1
- 1
- 12
3
votes
1 answer
Constructor definition error due to non-constant value
I'm working on a project using bloc pattern and I have a problem with the initial state of my home page state class. Here's the code:
class HomeState extends Equatable {
const HomeState({
this.screenTittle = LocaleKeys.mainMenu.tr(),
…

F7085
- 49
- 3
3
votes
2 answers
bloc_test: Bad state: Cannot emit new states after calling close
I have a problem in Test section of flutter, I wrote a test for simple counter app which uses cubit, but while I run all test it gives me the error mentioned in header, any body knows why?
it is necessary to say that while I run the tests one by one…

Jafar ashrafi
- 511
- 6
- 18
3
votes
1 answer
Flutter - cubit - changing boolean value inside cubit
I would like to change bool values from the cubit, but I can't figure out how to do it.
What I want to achieve is, for instance: if (boolean value stored in cubit is true) "show widget A" : "show widget B"
My code:
class ChangeBoolCubit extends…

mmcib
- 131
- 1
- 10
3
votes
1 answer
How to implement widget tests by using mock cubit?
I tried to follow the answer to this question, but I was not able to make it work.
I reproduced my issue on the counter app, changing it as follow.
main.dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
…

Federico Conte
- 93
- 2
- 6
3
votes
1 answer
'ImagePickerCubit' doesn't conform to the bound 'BlocBase' of the type parameter 'B'
I'm getting an error trying to create a BlocBuilder in my app:
"'ImagePickerCubit' doesn't conform to the bound 'BlocBase' of the type parameter 'B'. Try using a type that is or is a subclass of 'BlocBase'."
I'm implementing it according to…

sdobrzan
- 47
- 6
3
votes
0 answers
Using subscription with Cubit, need to create Timer (streamsubscription with cubit flutter)
I tried to create a timer with bloc cubit but without using it in the state but it make a memory leakage.
How i can create a timer with Cubit? i.e, probably using a subscription to this timer (streamsubscription with cubit flutter)

AIX
- 61
- 2