Color BLoC Drill
For repetition
Create new project for Bloc
- New Project: create new project, add flutter_bloc, equatable
- Flutter Color Container: delete all code below runApp, create new StatelessWidget with MaterialApp wrapped with Container with FloatingActionButton
- template bloc files: create event, state, bloc files using extension in
lib/blocs/color/
- BlocProvider: wrap MaterialApp
- BlocBuilder: wrap Container
Configure State, Event, Bloc files
- state: delete code. create new ColorState class that extends Equatable. Create final Color color. import material
- contructor – change to required
- equatable
- toString
- copyWith
- factory – ColorState.initial return pink
- event: add ChangeColorEvent
- bloc:
- ColorState.initial()
- ChangeColorEvent – emit ColorState amber
Show Bloc Information on UI
- set color to container from Bloc state
Change Bloc State from Button
- add new state to Bloc stream from FloatingActionButton
Modify Bloc to emit random color
- organize callback function into separate method
- emit random color