This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return RepositoryProvider( | |
builder: (context) => MyRepository(), | |
child: MyChild(), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Navigator.of(context).push( | |
MaterialPageRoute<MyPage>( | |
builder: (context) { | |
return BlocProvider.value( | |
value: BlocProvider.of<MyBloc>(context), | |
child: MyPage(), | |
); | |
}, | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWidget extends StatefulWidget { | |
State<MyWidget> createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
MyBloc _myBloc; | |
@override | |
void initState() { | |
super.initState(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return BlocProvider( | |
builder: (BuildContext context) => MyBloc(), | |
child: MyChild(), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:bloc/bloc.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:equatable/equatable.dart'; | |
abstract class StepperEvent extends Equatable { | |
StepperEvent([List props = const []]) : super(props); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeatherBloc extends HydratedBloc<WeatherEvent, WeatherState> { | |
final WeatherRepository weatherRepository; | |
WeatherBloc({@required this.weatherRepository}) | |
: assert(weatherRepository != null); | |
@override | |
WeatherState get initialState => super.initialState ?? WeatherEmpty(); | |
@override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThemeBloc extends HydratedBloc<ThemeEvent, ThemeState> { | |
@override | |
ThemeState get initialState => | |
super.initialState ?? | |
ThemeState( | |
theme: ThemeData.light(), | |
color: Colors.lightBlue, | |
); | |
@override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SettingsBloc extends HydratedBloc<SettingsEvent, SettingsState> { | |
@override | |
SettingsState get initialState => | |
super.initialState ?? | |
SettingsState(temperatureUnits: TemperatureUnits.celsius); | |
@override | |
Stream<SettingsState> mapEventToState(SettingsEvent event) async* { | |
if (event is TemperatureUnitsToggled) { | |
yield SettingsState( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc/bloc.dart'; | |
import 'package:hydrated_bloc/hydrated_bloc.dart'; | |
void main() async { | |
BlocSupervisor.delegate = await HydratedBlocDelegate.build(); | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc/bloc.dart'; | |
import 'package:hydrated_bloc/hydrated_bloc.dart'; | |
void main() async { | |
BlocSupervisor.delegate = SimpleBlocDelegate( | |
await HydratedBlocStorage.getInstance(), | |
); | |
... | |
} |