Spinner class. Fire notifications loading

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-13 07:23:18 +02:00
parent fa63734ff2
commit 4ff9d995e7
4 changed files with 25 additions and 8 deletions

View file

@ -17,6 +17,7 @@ import 'mainDrawer.dart';
import 'models/appState.dart'; import 'models/appState.dart';
import 'placesAutocompleteUtils.dart'; import 'placesAutocompleteUtils.dart';
import 'redux/actions.dart'; import 'redux/actions.dart';
import 'firesSpinner.dart';
@immutable @immutable
class _ViewModel { class _ViewModel {
@ -217,7 +218,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
FloatingActionButtonLocation.centerFloat, FloatingActionButtonLocation.centerFloat,
bottomNavigationBar: new GlobalFiresBottomStats(), bottomNavigationBar: new GlobalFiresBottomStats(),
body: view.isLoading body: view.isLoading
? new SpinKitPulse(color: fires600) ? new FiresSpinner()
: hasLocations : hasLocations
? new Stack(children: <Widget>[ ? new Stack(children: <Widget>[
new RefreshIndicator( new RefreshIndicator(

View file

@ -13,9 +13,11 @@ import 'genericMap.dart';
import 'mainDrawer.dart'; import 'mainDrawer.dart';
import 'models/appState.dart'; import 'models/appState.dart';
import 'redux/actions.dart'; import 'redux/actions.dart';
import 'firesSpinner.dart';
@immutable @immutable
class _ViewModel { class _ViewModel {
final bool isLoaded;
final List<FireNotification> fireNotifications; final List<FireNotification> fireNotifications;
final int fireNotificationsUnread; final int fireNotificationsUnread;
final List<YourLocation> yourLocations; final List<YourLocation> yourLocations;
@ -24,7 +26,8 @@ class _ViewModel {
final DeleteAllFireNotificationFunction onDeleteAll; final DeleteAllFireNotificationFunction onDeleteAll;
_ViewModel( _ViewModel(
{@required this.onTap, {@required this.isLoaded,
@required this.onTap,
@required this.onDelete, @required this.onDelete,
@required this.onDeleteAll, @required this.onDeleteAll,
@required this.fireNotifications, @required this.fireNotifications,
@ -36,12 +39,14 @@ class _ViewModel {
identical(this, other) || identical(this, other) ||
other is _ViewModel && other is _ViewModel &&
runtimeType == other.runtimeType && runtimeType == other.runtimeType &&
isLoaded == other.isLoaded &&
fireNotifications == other.fireNotifications && fireNotifications == other.fireNotifications &&
fireNotificationsUnread == other.fireNotificationsUnread && fireNotificationsUnread == other.fireNotificationsUnread &&
yourLocations == other.yourLocations; yourLocations == other.yourLocations;
@override @override
int get hashCode => int get hashCode =>
isLoaded.hashCode ^
fireNotifications.hashCode ^ fireNotifications.hashCode ^
fireNotificationsUnread.hashCode ^ fireNotificationsUnread.hashCode ^
yourLocations.hashCode; yourLocations.hashCode;
@ -144,8 +149,10 @@ class _FireNotificationListState extends State<FireNotificationList> {
return new StoreConnector<AppState, _ViewModel>( return new StoreConnector<AppState, _ViewModel>(
distinct: true, distinct: true,
converter: (store) { 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( return new _ViewModel(
isLoaded: store.state.isLoaded,
onDeleteAll: () { onDeleteAll: () {
store.dispatch(new DeleteAllFireNotificationAction()); store.dispatch(new DeleteAllFireNotificationAction());
}, },
@ -179,8 +186,7 @@ class _FireNotificationListState extends State<FireNotificationList> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: new MainDrawer(context, FireNotificationList.routeName), drawer: new MainDrawer(context, FireNotificationList.routeName),
appBar: new AppBar( appBar: new AppBar(
title: Text(title), title: Text(title),
leading: IconButton( leading: IconButton(
@ -196,7 +202,7 @@ class _FireNotificationListState extends State<FireNotificationList> {
onPressed: () => _showConfirmDialog(view)) onPressed: () => _showConfirmDialog(view))
: null : null
])), ])),
body: !hasFireNotifications body: !view.isLoaded ? new FiresSpinner() : !hasFireNotifications
? Padding( ? Padding(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
child: new Card( child: new Card(

10
lib/firesSpinner.dart Normal file
View file

@ -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);
}
}

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:latlong/latlong.dart'; import 'package:latlong/latlong.dart';
import 'colors.dart'; import 'colors.dart';
@ -9,6 +8,7 @@ import 'customBottomAppBar.dart';
import 'generated/i18n.dart'; import 'generated/i18n.dart';
import 'mainDrawer.dart'; import 'mainDrawer.dart';
import 'models/appState.dart'; import 'models/appState.dart';
import 'firesSpinner.dart';
class _ViewModel { class _ViewModel {
List<Polyline> monitoredAreas; List<Polyline> monitoredAreas;
@ -61,7 +61,7 @@ class MonitoredAreasPage extends StatelessWidget {
]))) ])))
]), ]),
body: !(view.monitoredAreas is List) body: !(view.monitoredAreas is List)
? new SpinKitPulse(color: fires600) ? new FiresSpinner()
: new Padding( : new Padding(
padding: new EdgeInsets.all(10.0), padding: new EdgeInsets.all(10.0),
child: new Column( child: new Column(