From 4ff9d995e74531fc5eebb0965a5e85fcdc7d0cfe Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Mon, 13 Aug 2018 07:23:18 +0200 Subject: [PATCH] Spinner class. Fire notifications loading --- lib/activeFires.dart | 3 ++- lib/fireNotificationList.dart | 16 +++++++++++----- lib/firesSpinner.dart | 10 ++++++++++ lib/monitoredAreas.dart | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 lib/firesSpinner.dart diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 46afa3d..11884ea 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -17,6 +17,7 @@ import 'mainDrawer.dart'; import 'models/appState.dart'; import 'placesAutocompleteUtils.dart'; import 'redux/actions.dart'; +import 'firesSpinner.dart'; @immutable class _ViewModel { @@ -217,7 +218,7 @@ class _ActiveFiresPageState extends State { FloatingActionButtonLocation.centerFloat, bottomNavigationBar: new GlobalFiresBottomStats(), body: view.isLoading - ? new SpinKitPulse(color: fires600) + ? new FiresSpinner() : hasLocations ? new Stack(children: [ new RefreshIndicator( diff --git a/lib/fireNotificationList.dart b/lib/fireNotificationList.dart index 54b049d..da131e5 100644 --- a/lib/fireNotificationList.dart +++ b/lib/fireNotificationList.dart @@ -13,9 +13,11 @@ import 'genericMap.dart'; import 'mainDrawer.dart'; import 'models/appState.dart'; import 'redux/actions.dart'; +import 'firesSpinner.dart'; @immutable class _ViewModel { + final bool isLoaded; final List fireNotifications; final int fireNotificationsUnread; final List yourLocations; @@ -24,7 +26,8 @@ class _ViewModel { final DeleteAllFireNotificationFunction onDeleteAll; _ViewModel( - {@required this.onTap, + {@required this.isLoaded, + @required this.onTap, @required this.onDelete, @required this.onDeleteAll, @required this.fireNotifications, @@ -36,12 +39,14 @@ class _ViewModel { identical(this, other) || other is _ViewModel && runtimeType == other.runtimeType && + isLoaded == other.isLoaded && fireNotifications == other.fireNotifications && fireNotificationsUnread == other.fireNotificationsUnread && yourLocations == other.yourLocations; @override int get hashCode => + isLoaded.hashCode ^ fireNotifications.hashCode ^ fireNotificationsUnread.hashCode ^ yourLocations.hashCode; @@ -144,8 +149,10 @@ class _FireNotificationListState extends State { return new StoreConnector( distinct: true, converter: (store) { - print('New ViewModel of Fires Notifications (unread: ${store.state.fireNotificationsUnread})'); + print('New ViewModel of Fires Notifications (unread: ${store.state + .fireNotificationsUnread})'); return new _ViewModel( + isLoaded: store.state.isLoaded, onDeleteAll: () { store.dispatch(new DeleteAllFireNotificationAction()); }, @@ -179,8 +186,7 @@ class _FireNotificationListState extends State { return Scaffold( key: _scaffoldKey, - drawer: new MainDrawer(context, FireNotificationList.routeName), - + drawer: new MainDrawer(context, FireNotificationList.routeName), appBar: new AppBar( title: Text(title), leading: IconButton( @@ -196,7 +202,7 @@ class _FireNotificationListState extends State { onPressed: () => _showConfirmDialog(view)) : null ])), - body: !hasFireNotifications + body: !view.isLoaded ? new FiresSpinner() : !hasFireNotifications ? Padding( padding: const EdgeInsets.all(20.0), child: new Card( diff --git a/lib/firesSpinner.dart b/lib/firesSpinner.dart new file mode 100644 index 0000000..d13c94b --- /dev/null +++ b/lib/firesSpinner.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'colors.dart'; + +class FiresSpinner extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new SpinKitPulse(color: fires600); + } +} diff --git a/lib/monitoredAreas.dart b/lib/monitoredAreas.dart index 83ce128..8b18604 100644 --- a/lib/monitoredAreas.dart +++ b/lib/monitoredAreas.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_redux/flutter_redux.dart'; -import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:latlong/latlong.dart'; import 'colors.dart'; @@ -9,6 +8,7 @@ import 'customBottomAppBar.dart'; import 'generated/i18n.dart'; import 'mainDrawer.dart'; import 'models/appState.dart'; +import 'firesSpinner.dart'; class _ViewModel { List monitoredAreas; @@ -61,7 +61,7 @@ class MonitoredAreasPage extends StatelessWidget { ]))) ]), body: !(view.monitoredAreas is List) - ? new SpinKitPulse(color: fires600) + ? new FiresSpinner() : new Padding( padding: new EdgeInsets.all(10.0), child: new Column(