bloc

Bloc: is it possible to yield 2 time the same state?

久未见 提交于 2020-05-17 08:40:45
问题 In the login view, if the user taps on the login button without having inserted his credentials, the LoginFailState is yield and the view reacts to it. If he taps again, this LoginFailstate is yield again, but the view doesn't react to it. So, is there a way to yield more times the same state? There is some code to better explain my situation: class LoginBloc extends Bloc<LoginEvent, LoginState> { @override LoginState get initialState => LoginUninitialized(); @override Stream<LoginState>

Flutter BLoC: Is using nested StreamBuilders a bad practice?

三世轮回 提交于 2020-05-15 04:21:09
问题 Is there a better way to expose a widget to two or more streams from different BLoCs? So far I have been using nested StreamBuilder 's for as many streams as I need listening to like the pasted code below. Is this a good practice? StreamBuilder( stream: firstBloc.stream1, builder: (_, AsyncSnapshot snapshot1) { return StreamBuilder( stream: secondBloc.stream2, builder: (_, AsyncSnapshot snapshot2) { return CustomWidget(snapshot1.data, snapshot2.data); } ) } ) Using rxdart operators like

Repository provider in the flutter_bloc library doesn't provide repository with when pushing new route

六月ゝ 毕业季﹏ 提交于 2020-05-13 11:54:16
问题 I am using the flutter_bloc library to architect my app. In addition to the BlocProvider I am using the Repository Provider, since I will be using a specific repository extensively throughout my app. But I am having an issue with regards to context . Below is snippets of my code: main.dart void main() async { ....... appRepository _appRepository = AppRepository(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { runApp( BlocProvider( builder: (context) =>

Repository provider in the flutter_bloc library doesn't provide repository with when pushing new route

蹲街弑〆低调 提交于 2020-05-13 11:50:09
问题 I am using the flutter_bloc library to architect my app. In addition to the BlocProvider I am using the Repository Provider, since I will be using a specific repository extensively throughout my app. But I am having an issue with regards to context . Below is snippets of my code: main.dart void main() async { ....... appRepository _appRepository = AppRepository(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { runApp( BlocProvider( builder: (context) =>

Question mark before dot in Dart

大兔子大兔子 提交于 2020-01-30 11:22:28
问题 What's the meaning of the question mark in this piece of code? And when am I supposed to use it? My code functions the same way with or without the question mark. void dispose(){ bloc?.dispose(); super.dispose(); } 回答1: The question mark is one of the null-aware operators in Dart. In this example it says: call the dispose() method only if bloc is not null. Without the question mark, if bloc was null when it tried to call dispose() a NoSuchMethodError would be thrown. There is a useful section

How to access Provided (Provider.of()) value inside showModalBottomSheet?

折月煮酒 提交于 2020-01-20 07:23:56
问题 I have a FloatingActionButton inside a widget tree which has a BlocProvider from flutter_bloc. Something like this: BlocProvider( builder: (context) { SomeBloc someBloc = SomeBloc(); someBloc.dispatch(SomeEvent()); return someBloc; }, child: Scaffold( body: ... floatingActionButton: FloatingActionButton( onPressed: _openFilterSchedule, child: Icon(Icons.filter_list), ), ) ); Which opens a modal bottom sheet: void _openFilterSchedule() { showModalBottomSheet<void>( context: context, builder:

How to access Provided (Provider.of()) value inside showModalBottomSheet?

浪子不回头ぞ 提交于 2020-01-20 07:23:05
问题 I have a FloatingActionButton inside a widget tree which has a BlocProvider from flutter_bloc. Something like this: BlocProvider( builder: (context) { SomeBloc someBloc = SomeBloc(); someBloc.dispatch(SomeEvent()); return someBloc; }, child: Scaffold( body: ... floatingActionButton: FloatingActionButton( onPressed: _openFilterSchedule, child: Icon(Icons.filter_list), ), ) ); Which opens a modal bottom sheet: void _openFilterSchedule() { showModalBottomSheet<void>( context: context, builder:

Bloc Pattern to hide and unhide Widgets

北城余情 提交于 2020-01-15 07:37:05
问题 I am trying to fetch some data from the internet and show it int a list. Following is my bloc code class StudentsBloc { final _repository = Repository(); final _students = BehaviorSubject<StudentModel>(); final BehaviorSubject<bool> _showProgress = BehaviorSubject<bool>(); final BehaviorSubject<bool> _showNoInternetViews = BehaviorSubject<bool>(); Observable<StudentModel> get students => _students.stream; Observable<bool> get showProgress => _showProgress.stream; Observable<bool> get

Can BlocBuilder of flutter_bloc avoid rebuild part of Widget which not changing?

こ雲淡風輕ζ 提交于 2020-01-03 02:31:11
问题 BlocBuilder of flutter_bloc is kind of put all state of page together. There's a case for pulling a list there's 2 data ( isPullingState , dataList ), how can I avoid build widget part of dataList when dataList not change, but build widget part of isPullingState which changed from true to false ? BlocBuilderCondition looks like only avoid rebuild when hole state not change. 回答1: The BlocBuilder have a optinal parameter condition that have type bool Function(State previous, State current) ,

How to use json and serialization with firebase and bloc? Error: Converting object to an encodable object failed

≡放荡痞女 提交于 2019-12-24 20:52:09
问题 this is my cloud firestore looks like: Error Message: Unhandled Exception: Converting object to an encodable object failed: Photography used jsonSerialization for my database import 'package:json_annotation/json_annotation.dart'; part 'Model.g.dart'; @JsonSerializable() class Photography{ String couplePhoto; String female; String image_url; String info; String male; AllImages all_images; Photography(); factory Photography.fromJson(Map<String, dynamic> json) => _$PhotographyFromJson(json); Map