Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class HomePage extends StatelessWidget implements ConnectivityHandler {
  2. final _keyScaffold = new GlobalKey<ScaffoldState>();
  3. HomeBloc _bloc;
  4.  
  5. @override
  6. Widget build(BuildContext context) {
  7. _bloc = BlocProvider.of<HomeBloc>(context);
  8. return Scaffold(
  9. key: _keyScaffold,
  10. appBar: AppBar(title: Text('Flutter Ready to Go')),
  11. body: StreamBuilder(
  12. stream: _bloc.personStream,
  13. builder: (context, AsyncSnapshot<Person> snapshot) {
  14. if(!snapshot.hasData) return Center(child: CircularProgressIndicator());
  15. final person = snapshot.data;
  16. return _buildPersonInfo(person);
  17. }
  18. ),
  19. );
  20. }
  21.  
  22. // omitted data
  23.  
  24. @override
  25. void onConnectivityChanged(ConnectivityResult connectivity) {
  26. showSnackBar("Connectivity changed to ${connectivity}");
  27. if (!_bloc.dataLoaded && (connectivity == ConnectivityResult.wifi ||
  28. connectivity == ConnectivityResult.mobile)) {
  29. _bloc.fetchData(this);
  30. }
  31. }
  32.  
  33. @override
  34. void onError(String error) {
  35. showSnackBar(error);
  36. }
  37.  
  38. void showSnackBar(String text, [int time = 2000]){
  39. final snackbar = new SnackBar(
  40. content: new Text(text),
  41. duration: Duration(milliseconds: time),
  42. );
  43. _keyScaffold?.currentState.showSnackBar(snackbar);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement