Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HomePage extends StatelessWidget implements ConnectivityHandler {
- final _keyScaffold = new GlobalKey<ScaffoldState>();
- HomeBloc _bloc;
- @override
- Widget build(BuildContext context) {
- _bloc = BlocProvider.of<HomeBloc>(context);
- return Scaffold(
- key: _keyScaffold,
- appBar: AppBar(title: Text('Flutter Ready to Go')),
- body: StreamBuilder(
- stream: _bloc.personStream,
- builder: (context, AsyncSnapshot<Person> snapshot) {
- if(!snapshot.hasData) return Center(child: CircularProgressIndicator());
- final person = snapshot.data;
- return _buildPersonInfo(person);
- }
- ),
- );
- }
- // omitted data
- @override
- void onConnectivityChanged(ConnectivityResult connectivity) {
- showSnackBar("Connectivity changed to ${connectivity}");
- if (!_bloc.dataLoaded && (connectivity == ConnectivityResult.wifi ||
- connectivity == ConnectivityResult.mobile)) {
- _bloc.fetchData(this);
- }
- }
- @override
- void onError(String error) {
- showSnackBar(error);
- }
- void showSnackBar(String text, [int time = 2000]){
- final snackbar = new SnackBar(
- content: new Text(text),
- duration: Duration(milliseconds: time),
- );
- _keyScaffold?.currentState.showSnackBar(snackbar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement