Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Teye-Doku
@Teye-Doku
hello family, any guide for flutter ui building
Felix Angelov
@felangel
please join the discord server at https://discord.gg/Hc5KD3g
We’ve migrated off of gitter
Absolute Virtue
@AbsoluteVirtueXI
hi all i am reading an asnwer from stackover flow saying: "The flutter bloc requires you to yield a new instance of the state, instead of modifying the currentState."
Is it true ? i mean ofc i like the functional way of returning a total new state, and i am pretty it is the way to go to avoid bug in the future. But can i mutate a state instead of instantiating a new one ?
for example i have this counter state:
// State
class Counter extends Equatable{
  final int value;
  Counter(this.value);

  @override
  List<Object> get props => [value];

  @override
  bool get stringify => true;

  Counter increment() => Counter(this.value + 1);
  Counter decrement() => Counter(this.value - 1);
}
i feel like it is a bit bad to increment() and decrement() this way, by returning a new instance
oh i will switch to discord
harnit-bakshi
@harnit-bakshi
I am testing my widget and mocking my bloc to do so
I had a question about setting up the states via the whenListen method, I was expecting that the states would not be fired until the widgetTester.pump is called. But seems like when I call widgetTester.pumpWidget all the states are triggered straightaway?
My sample code below, the _buildApp which calls the pumpWidget starts triggering all states straightaway. Please let me know if I am doing something wrong? I have followed the suggestions in this ticket: felangel/bloc#655

void main() {
  group("AccountLinking Screen", () {
    MockUserDataSourceBloc mockUserDataSourceBloc;
    NavigatorObserver mockNavigatorObserver;

    setUp(() {

      TestWidgetsFlutterBinding.ensureInitialized();
      mockUserDataSourceBloc = di.sl<UserDataSourceBloc>();
      mockNavigatorObserver = MockNavigatorObserver();
    });

    tearDown(() {
      mockUserDataSourceBloc.close();
    });

    Future<void> _buildApp(WidgetTester tester) async {
      await tester.pumpWidget(
        MaterialApp(
          title: "Test App",
          home: Scaffold(
            body: BlocProvider<UserDataSourceBloc>(
              create: (_) => mockUserDataSourceBloc,
              child: UserDataSourceView(),
            ),
          ),
          navigatorObservers: [mockNavigatorObserver],
          routes: routes,
        ),
      );
    }

    testWidgets("should update datasource list when linking succeeds",
        (WidgetTester tester) async {
      final expectedStates = [
        UserDataSourceInitial(),
        GetUserDataSourcesLoaded(userDataSources: []),
        LinkUserDataSourceLoading(),
        LinkUserDataSourceLoaded(
          userDataSource: UserDataSource(
            userDataSourceId: "1",
            userId: "uuid",
            status: DataSourceStatus.LINKED,
          ),
        ),
      ];

      whenListen(
        mockUserDataSourceBloc,
        Stream.fromIterable(expectedStates),
      );

      await _buildApp(tester);
    });
  });
}
Gerald
@campanagerald
Hi, are there any in depth video tutorials about flutter_bloc?
Gerald
@campanagerald
is it okay to have more than 1 blocs in a page? is it still a best practice?
areejmayadeh
@areejmayadeh
how to call api inside block builder and wait for response to return widget
@felangel
Felix Angelov
@felangel
please join the discord server at https://discord.gg/Hc5KD3g
We’ve migrated off of gitter
UX KAHUÊ
@kahuem
guys
image.png
image.png
I'm newbie into flutter
can someone help me pls
Kalam Azad
@KalamAzad11_twitter
Hello

class JournalBloc extends Bloc<JournalEvent, JournalState> {
final JournalRepository journalRepository;
final AddJournalBloc addJournalBloc;
StreamSubscription subscription;
JournalBloc({@required this.journalRepository, this.addJournalBloc})
: super(JournalInitial()) {
subscription = addJournalBloc.listen((state) {
print("I AM LISTENING");
if (state is AddJournalSuccess) {
print("I AM LISTENING AND FIRED");
add(LoadJournal(keyword: '', pageno: 0));
}
});
}

@override
JournalState get initialState => JournalInitial();

@override
Stream<JournalState> mapEventToState(
JournalEvent event,
) async {
if (event is LoadJournal) {
yield
_mapLoadJournalToState(event);
}
}

Stream<JournalState> mapLoadJournalToState(LoadJournal event) async* {
print("I AM LISTENING AND FIRED INSIDE STATA");
yield JournalLoading();
List<Journal> journal;
try {
journal = await journalRepository.getJournalList();
print("LENGTH:" + journal[0].title);
if (journal.length == 0) {
yield JournalEmpty();
} else {
yield JournalLoaded(journal: journal);
}
} catch (
) {
yield JournalError();
}
}

@override
Future<void> close() {
subscription.cancel();
return super.close();
}
}

StreamSubscription is working and firing new Event -> Event is also working Properly
But UI not updating
Please Help Me
I am stuck in the issue since Long
fernan542
@fernan542
Hello. I want to ask if is it ok to put almost all the Blocs using the MultiBlocProvider in the main.dart file?
statsss
@statsss

Hello. I want to ask if is it ok to put almost all the Blocs using the MultiBlocProvider in the main.dart file?

why not?

wissemo
@wissemo

hello

test(
      'should emit [Error] when the input is invalid',
      () async {
        //arrange
        when(mockInputConverter.stringToUnsignedInteger(any))
            .thenReturn(Left(InvalidInputFailure()));
        //assert later
        final expected = [
          Empty(),
          Error(message: INVALID_INPUT_FAILURE_MESSAGE),
        ];
        expectLater(
            bloc,
            emitsInOrder(
              expected,
            ));
        //act
        bloc.add(GetTriviaForConcreteNumber(tNumberString));
      },
    );
  @override
  Stream<NumberTriviaState> mapEventToState(
    NumberTriviaEvent event,
  ) async* {
    if (event is GetTriviaForConcreteNumber) {
      final inputEither =
          inputConverter.stringToUnsignedInteger(event.numberString);

      yield* inputEither.fold(
        (failure) async* {
          yield Error(message: INVALID_INPUT_FAILURE_MESSAGE);
        },
        (integer) async* {
          yield null;
        },
      );
    }
  }

i tried to resolve this problem but in vain
i get this error

Expected: should do the following in order:
          • emit an event that Empty:<Empty()>
          • emit an event that Error:<Error(Invalid Input - The number must be a positive integer or zero.)>
  Actual: <Instance of 'NumberTriviaBloc'>
   Which: was not a Stream or a StreamQueue
Does anyone know where i missed
Fausto Davila
@faustodc
Hey there guys, one question, can I have one main bloc (for navigation) being provided by a BlocProvider in the root of the widget tree and have other blocs being provided by different BlocProviders in different screens?
in the end, having nested BlocProviders
(as an alternative to have them all in the root with a MultiBlocProvider)
Fausto Davila
@faustodc
Or am I overoptimizing?
Oops just realized you guys migrated to discord, sorry!
MD ASIF
@mdasifcse
Hello ,when i am navigating(pop) to previous page my bloc is loosing data ,i called Api on initstate method ? can anybody help
Maximiliano Malvido
@maximalvido_twitter
Hello is this still active?
Felix Angelov
@felangel
Hey we've moved to discord at https://discord.gg/bloc
is cubit package down?
When I use emit(state), flutter says state does not defined??
yesterday it did not give an error
@felangel
Felix Angelov
@felangel
@efe_m8_twitter we have moved to discord (https://discord.gg/bloc)
Elbarqy
@Elbarqy
Hello everyone
I was wondering if someone faced this issue before
: Error: 'uthrow' isn't a type.
../…/src/bloc_provider.dart:103
uthrow FlutterError(
^^^^^^
the file line that's throwing the error says 'BlocProvider.of() called with a context that does not contain a $T.
No ancestor could be found starting from the context that was passed to BlocProvider.of<$T>().'
I've tried building online examples from github but it didn't work either
runApp( MultiBlocProvider( providers: [ BlocProvider<TestCubit>(lazy: false, create: (context) => TestCubit()) ], child: Builder( builder: (context) { return const MyApp(); }, ), ), )
this is how I'm initilizing the bloc