SHARE
TWEET

Untitled

a guest Oct 10th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:bloc/bloc.dart';
  2. import 'package:meta/meta.dart';
  3. import 'package:bloc_pattern/bloc/users.dart';
  4. import 'package:bloc_pattern/repositories/repositories.dart';
  5. import 'package:bloc_pattern/models/models.dart';
  6.  
  7. class UsersBloc extends Bloc<UsersEvent, UsersState> {
  8.   final UsersRepository usersRepository;
  9.  
  10.   UsersBloc({@required this.usersRepository}) : assert(usersRepository != null);
  11.  
  12.   @override
  13.   UsersState get initialState => InitialUsersState();
  14.  
  15.   @override
  16.   Stream<UsersState> mapEventToState(UsersEvent event) async* {
  17.     if (event is FetchUsers) {
  18.       yield UsersLoading();
  19.       try {
  20.         final List<User> users = await usersRepository.getUsers();
  21.         yield UsersLoaded(users: users);
  22.       } catch (e) {
  23.         print(e);
  24.         yield UsersError();
  25.       }
  26.     }
  27.   }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top