fix: resolve 2 remaining strict analysis errors
- introPage.dart: Convert fireItems to proper static function closure - mainDrawer.dart: Convert unreadCount int to String for Text widget
This commit is contained in:
parent
1864e5b105
commit
7a4c9fb3bc
61 changed files with 1386 additions and 1202 deletions
|
|
@ -1,8 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
|
|
@ -13,19 +11,14 @@ import 'generated/i18n.dart';
|
|||
import 'genericMap.dart';
|
||||
import 'mainDrawer.dart';
|
||||
import 'models/appState.dart';
|
||||
import 'models/fireNotification.dart';
|
||||
import 'models/yourLocation.dart';
|
||||
import 'redux/actions.dart';
|
||||
|
||||
@immutable
|
||||
class _ViewModel {
|
||||
final bool isLoaded;
|
||||
final List<FireNotification> fireNotifications;
|
||||
final int fireNotificationsUnread;
|
||||
final List<YourLocation> yourLocations;
|
||||
final TapFireNotificationFunction onTap;
|
||||
final DeleteFireNotificationFunction onDelete;
|
||||
final DeleteAllFireNotificationFunction onDeleteAll;
|
||||
|
||||
_ViewModel(
|
||||
const _ViewModel(
|
||||
{required this.isLoaded,
|
||||
required this.onTap,
|
||||
required this.onDelete,
|
||||
|
|
@ -33,6 +26,13 @@ class _ViewModel {
|
|||
required this.fireNotifications,
|
||||
required this.yourLocations,
|
||||
required this.fireNotificationsUnread});
|
||||
final bool isLoaded;
|
||||
final List<FireNotification> fireNotifications;
|
||||
final int fireNotificationsUnread;
|
||||
final List<YourLocation> yourLocations;
|
||||
final TapFireNotificationFunction onTap;
|
||||
final DeleteFireNotificationFunction onDelete;
|
||||
final DeleteAllFireNotificationFunction onDeleteAll;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
|
|
@ -53,6 +53,8 @@ class _ViewModel {
|
|||
}
|
||||
|
||||
class FireNotificationList extends StatefulWidget {
|
||||
const FireNotificationList({super.key});
|
||||
|
||||
static const String routeName = '/fireNotifications';
|
||||
|
||||
@override
|
||||
|
|
@ -60,23 +62,23 @@ class FireNotificationList extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _FireNotificationListState extends State<FireNotificationList> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
Widget _buildRow(BuildContext context, List<YourLocation> yourLocations,
|
||||
FireNotification notif, onDeleted, onTap) {
|
||||
String prefix = "";
|
||||
String prefix = '';
|
||||
|
||||
// FIXME (this can fails if you don't have a location for this notif, for instance during tests)
|
||||
YourLocation yl = yourLocations.singleWhere((yl) => yl.id == notif.subsId);
|
||||
final YourLocation yl = yourLocations.singleWhere((YourLocation yl) => yl.id == notif.subsId);
|
||||
prefix = '${yl.description}. ';
|
||||
|
||||
return new ListTile(
|
||||
return ListTile(
|
||||
dense: true,
|
||||
leading: const Icon(Icons.whatshot),
|
||||
title: new Text('$prefix${notif.description}',
|
||||
style: new TextStyle(
|
||||
title: Text('$prefix${notif.description}',
|
||||
style: TextStyle(
|
||||
fontWeight: notif.read ? FontWeight.normal : FontWeight.bold)),
|
||||
subtitle: new Text(Moment.now().from(context, notif.when)),
|
||||
subtitle: Text(Moment.now().from(context, notif.when)),
|
||||
onLongPress: () {
|
||||
showSnackMsg(S.of(context).toDeleteThisNotification);
|
||||
},
|
||||
|
|
@ -86,8 +88,8 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
|||
}
|
||||
|
||||
void showSnackMsg(String msg) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
|
||||
content: new Text(msg),
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(msg),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -97,78 +99,77 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
|||
List<FireNotification> notifList,
|
||||
onDeleted,
|
||||
onTap) {
|
||||
return new RefreshIndicator(
|
||||
child: new ListView.builder(
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
// reverse: true,
|
||||
// shrinkWrap: true,
|
||||
itemCount: notifList.length,
|
||||
itemBuilder: (BuildContext _context, int i) {
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
return new Dismissible(
|
||||
key: new ObjectKey(notifList.elementAt(i)),
|
||||
direction: DismissDirection.horizontal,
|
||||
return Dismissible(
|
||||
key: ObjectKey(notifList.elementAt(i)),
|
||||
onDismissed: (DismissDirection direction) {
|
||||
onDeleted(notifList.elementAt(i));
|
||||
},
|
||||
background: new Container(
|
||||
background: Container(
|
||||
color: theme.primaryColor,
|
||||
child: const ListTile(
|
||||
leading: const Icon(Icons.delete,
|
||||
leading: Icon(Icons.delete,
|
||||
color: Colors.white, size: 36.0))),
|
||||
secondaryBackground: new Container(
|
||||
secondaryBackground: Container(
|
||||
color: theme.primaryColor,
|
||||
child: const ListTile(
|
||||
trailing: const Icon(Icons.delete,
|
||||
trailing: Icon(Icons.delete,
|
||||
color: Colors.white, size: 36.0))),
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.canvasColor,
|
||||
border: new Border(
|
||||
border: Border(
|
||||
bottom:
|
||||
new BorderSide(color: theme.dividerColor))),
|
||||
BorderSide(color: theme.dividerColor))),
|
||||
child: _buildRow(context, yourLocations,
|
||||
notifList.elementAt(i), onDeleted, onTap)));
|
||||
}),
|
||||
onRefresh: _handleRefresh);
|
||||
}));
|
||||
}
|
||||
|
||||
Future<Null> _handleRefresh() async {
|
||||
await new Future.delayed(new Duration(seconds: 1));
|
||||
Future<void> _handleRefresh() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
setState(() {});
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new StoreConnector<AppState, _ViewModel>(
|
||||
return StoreConnector<AppState, _ViewModel>(
|
||||
distinct: true,
|
||||
converter: (store) {
|
||||
converter: (Store<AppState> store) {
|
||||
print(
|
||||
'New ViewModel of Fires Notifications (unread: ${store.state.fireNotificationsUnread})');
|
||||
return new _ViewModel(
|
||||
return _ViewModel(
|
||||
isLoaded: store.state.isLoaded,
|
||||
onDeleteAll: () {
|
||||
store.dispatch(new DeleteAllFireNotificationAction());
|
||||
store.dispatch(DeleteAllFireNotificationAction());
|
||||
},
|
||||
onDelete: (notif) {
|
||||
store.dispatch(new DeleteFireNotificationAction(notif));
|
||||
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
|
||||
content: new Text(S.of(context).youDeletedThisNotification),
|
||||
action: new SnackBarAction(
|
||||
onDelete: (FireNotification notif) {
|
||||
store.dispatch(DeleteFireNotificationAction(notif));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(S.of(context).youDeletedThisNotification),
|
||||
action: SnackBarAction(
|
||||
label: S.of(context).UNDO,
|
||||
onPressed: () {
|
||||
store.dispatch(new AddFireNotificationAction(notif));
|
||||
store.dispatch(AddFireNotificationAction(notif));
|
||||
})));
|
||||
},
|
||||
onTap: (notif) {
|
||||
onTap: (FireNotification notif) {
|
||||
if (!notif.read) {
|
||||
store.dispatch(new ReadFireNotificationAction(
|
||||
store.dispatch(ReadFireNotificationAction(
|
||||
notif.copyWith(read: true)));
|
||||
}
|
||||
new Timer(new Duration(milliseconds: 500), () {
|
||||
Timer(const Duration(milliseconds: 500), () {
|
||||
gotoMap(store, notif, context);
|
||||
});
|
||||
},
|
||||
|
|
@ -176,48 +177,46 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
|||
fireNotifications: store.state.fireNotifications,
|
||||
fireNotificationsUnread: store.state.fireNotificationsUnread);
|
||||
},
|
||||
builder: (context, view) {
|
||||
var hasFireNotifications = view.fireNotifications.length > 0;
|
||||
final title = S.of(context).fireNotificationsTitle;
|
||||
builder: (BuildContext context, _ViewModel view) {
|
||||
final bool hasFireNotifications = view.fireNotifications.isNotEmpty;
|
||||
final String title = S.of(context).fireNotificationsTitle;
|
||||
print('Building Fire Notifications List');
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
drawer: new MainDrawer(context, FireNotificationList.routeName),
|
||||
appBar: new AppBar(
|
||||
drawer: MainDrawer(context, FireNotificationList.routeName),
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.menu),
|
||||
icon: const Icon(Icons.menu),
|
||||
onPressed: () {
|
||||
_scaffoldKey.currentState?.openDrawer();
|
||||
},
|
||||
),
|
||||
actions: (<Widget?>[
|
||||
hasFireNotifications
|
||||
? IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () => _showConfirmDialog(view))
|
||||
: null
|
||||
]).where((w) => w != null).cast<Widget>().toList()),
|
||||
actions: <Widget?>[
|
||||
if (hasFireNotifications) IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () => _showConfirmDialog(view)) else null
|
||||
].where((Widget? w) => w != null).cast<Widget>().toList()),
|
||||
body: !view.isLoaded
|
||||
? new FiresSpinner()
|
||||
? const FiresSpinner()
|
||||
: !hasFireNotifications
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: new Card(
|
||||
child: new Padding(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: new CenteredColumn(children: <Widget>[
|
||||
new Icon(Icons.notifications_none,
|
||||
child: CenteredColumn(children: <Widget>[
|
||||
const Icon(Icons.notifications_none,
|
||||
size: 150.0, color: Colors.black26),
|
||||
new SizedBox(height: 20.0),
|
||||
new Text(
|
||||
const SizedBox(height: 20.0),
|
||||
Text(
|
||||
S
|
||||
.of(context)
|
||||
.fireNotificationsDescription,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.1,
|
||||
style: new TextStyle(
|
||||
style: const TextStyle(
|
||||
height: 1.3, color: Colors.black45))
|
||||
]))))
|
||||
: _buildSavedFireNotifications(
|
||||
|
|
@ -231,29 +230,29 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
|||
|
||||
void gotoMap(
|
||||
Store<AppState> store, FireNotification notif, BuildContext context) {
|
||||
store.dispatch(new ShowFireNotificationMapAction(notif));
|
||||
store.dispatch(ShowFireNotificationMapAction(notif));
|
||||
Navigator.push(
|
||||
context, new MaterialPageRoute(builder: (context) => new genericMap()));
|
||||
context, MaterialPageRoute(builder: (BuildContext context) => const genericMap()));
|
||||
}
|
||||
|
||||
_showConfirmDialog(_ViewModel view) {
|
||||
return showDialog<Null>(
|
||||
Future<void> _showConfirmDialog(_ViewModel view) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return new AlertDialog(
|
||||
title: new Text(S.of(context).areYouSureTitle),
|
||||
content: new SingleChildScrollView(
|
||||
child: new ListBody(
|
||||
return AlertDialog(
|
||||
title: Text(S.of(context).areYouSureTitle),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
Text(
|
||||
S.of(context).deleteAllFireNotificationsAlertDescription)
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
new TextButton(
|
||||
child: new Text(S.of(context).DELETE),
|
||||
TextButton(
|
||||
child: Text(S.of(context).DELETE),
|
||||
onPressed: () {
|
||||
view.onDeleteAll();
|
||||
Navigator.of(context).pop();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue