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,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
|
|
@ -15,20 +14,14 @@ import 'globalFiresBottomStats.dart';
|
|||
import 'locationUtils.dart';
|
||||
import 'mainDrawer.dart';
|
||||
import 'models/appState.dart';
|
||||
import 'models/yourLocation.dart';
|
||||
import 'placesAutocompleteUtils.dart';
|
||||
import 'redux/actions.dart';
|
||||
|
||||
@immutable
|
||||
class _ViewModel {
|
||||
final List<YourLocation> yourLocations;
|
||||
final AddYourLocationFunction onAdd;
|
||||
final DeleteYourLocationFunction onDelete;
|
||||
final ToggleSubscriptionFunction onToggleSubs;
|
||||
final OnLocationTapFunction onTap;
|
||||
final OnRefreshYourLocationsFunction onRefresh;
|
||||
final bool isLoading;
|
||||
|
||||
_ViewModel(
|
||||
const _ViewModel(
|
||||
{required this.onAdd,
|
||||
required this.onDelete,
|
||||
required this.onToggleSubs,
|
||||
|
|
@ -36,6 +29,13 @@ class _ViewModel {
|
|||
required this.onRefresh,
|
||||
required this.yourLocations,
|
||||
required this.isLoading});
|
||||
final List<YourLocation> yourLocations;
|
||||
final AddYourLocationFunction onAdd;
|
||||
final DeleteYourLocationFunction onDelete;
|
||||
final ToggleSubscriptionFunction onToggleSubs;
|
||||
final OnLocationTapFunction onTap;
|
||||
final OnRefreshYourLocationsFunction onRefresh;
|
||||
final bool isLoading;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
|
|
@ -50,6 +50,8 @@ class _ViewModel {
|
|||
}
|
||||
|
||||
class ActiveFiresPage extends StatefulWidget {
|
||||
const ActiveFiresPage({super.key});
|
||||
|
||||
static const String routeName = '/fires';
|
||||
|
||||
@override
|
||||
|
|
@ -57,11 +59,11 @@ class ActiveFiresPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
List<SpeedDialChild> _fabMiniMenuItemList(
|
||||
BuildContext context, AddYourLocationFunction onAdd) {
|
||||
return [
|
||||
return <SpeedDialChild>[
|
||||
SpeedDialChild(
|
||||
child: const Icon(Icons.location_searching),
|
||||
backgroundColor: fires600,
|
||||
|
|
@ -92,13 +94,13 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
}
|
||||
|
||||
Widget _buildRow(BuildContext context, YourLocation loc, onToggle, onTap) {
|
||||
final fireStatsStyle = new TextStyle(color: fires600);
|
||||
return new ListTile(
|
||||
const TextStyle fireStatsStyle = TextStyle(color: fires600);
|
||||
return ListTile(
|
||||
dense: true,
|
||||
isThreeLine: false,
|
||||
// leading: const Icon(Icons.location_on),
|
||||
trailing: new IconButton(
|
||||
icon: new Icon(loc.subscribed
|
||||
trailing: IconButton(
|
||||
icon: Icon(loc.subscribed
|
||||
? Icons.notifications_active
|
||||
: Icons.notifications_off),
|
||||
color: loc.subscribed ? fires600 : null,
|
||||
|
|
@ -110,18 +112,18 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
? S.of(context).subscribedToFires
|
||||
: S.of(context).unsubscribedToFires);
|
||||
}),
|
||||
title: new Text(loc.description, style: new TextStyle(fontSize: 16.0)),
|
||||
title: Text(loc.description, style: const TextStyle(fontSize: 16.0)),
|
||||
subtitle: loc.currentNumFires == YourLocation.withoutStats
|
||||
? null
|
||||
: loc.currentNumFires == 0
|
||||
? new Text(S.of(context).noFiresAround)
|
||||
? Text(S.of(context).noFiresAround)
|
||||
: loc.currentNumFires == 1
|
||||
? new Text(
|
||||
? Text(
|
||||
S
|
||||
.of(context)
|
||||
.fireAroundThisArea(loc.distance.toString()),
|
||||
style: fireStatsStyle)
|
||||
: new Text(
|
||||
: Text(
|
||||
S.of(context).firesAroundThisArea(
|
||||
loc.currentNumFires.toString(),
|
||||
loc.distance.toString()),
|
||||
|
|
@ -136,86 +138,85 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
|
||||
void showSnackMsg(String msg) {
|
||||
// _scaffoldKey.currentState.showSnackBar(new SnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
|
||||
content: new Text(msg),
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(msg),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildSavedLocations(
|
||||
BuildContext context, List<YourLocation> yl, onDeleted, onToggle, onTap) {
|
||||
return new ListView.builder(
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
itemCount: yl.length,
|
||||
itemBuilder: (BuildContext _context, int i) {
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
return new Dismissible(
|
||||
key: new ObjectKey(yl.elementAt(i)),
|
||||
direction: DismissDirection.horizontal,
|
||||
return Dismissible(
|
||||
key: ObjectKey(yl.elementAt(i)),
|
||||
onDismissed: (DismissDirection direction) {
|
||||
onDeleted(yl.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(
|
||||
bottom: new BorderSide(color: theme.dividerColor))),
|
||||
border: Border(
|
||||
bottom: BorderSide(color: theme.dividerColor))),
|
||||
child: _buildRow(context, yl.elementAt(i), onToggle, onTap)));
|
||||
});
|
||||
}
|
||||
|
||||
@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 Active Fires');
|
||||
return new _ViewModel(
|
||||
onAdd: (loc) {
|
||||
return _ViewModel(
|
||||
onAdd: (YourLocation loc) {
|
||||
if (store.state.yourLocations
|
||||
.any((l) => loc.lat == l.lat && loc.lon == l.lon)) {
|
||||
.any((YourLocation l) => loc.lat == l.lat && loc.lon == l.lon)) {
|
||||
// Already added
|
||||
showSnackMsg(S.of(context).addedThisLocation);
|
||||
} else {
|
||||
store.dispatch(new AddYourLocationAction(loc));
|
||||
new Timer(new Duration(milliseconds: 1000), () {
|
||||
store.dispatch(AddYourLocationAction(loc));
|
||||
Timer(const Duration(milliseconds: 1000), () {
|
||||
gotoLocationMap(store, loc, context);
|
||||
});
|
||||
}
|
||||
},
|
||||
onDelete: (loc) {
|
||||
store.dispatch(new DeleteYourLocationAction(loc));
|
||||
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
|
||||
content: new Text(S.of(context).youDeletedThisPlace),
|
||||
action: new SnackBarAction(
|
||||
onDelete: (YourLocation loc) {
|
||||
store.dispatch(DeleteYourLocationAction(loc));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(S.of(context).youDeletedThisPlace),
|
||||
action: SnackBarAction(
|
||||
label: S.of(context).UNDO,
|
||||
onPressed: () {
|
||||
store.dispatch(new AddYourLocationAction(loc));
|
||||
store.dispatch(AddYourLocationAction(loc));
|
||||
})));
|
||||
},
|
||||
onToggleSubs: (loc) {
|
||||
store.dispatch(new ToggleSubscriptionAction(loc));
|
||||
onToggleSubs: (YourLocation loc) {
|
||||
store.dispatch(ToggleSubscriptionAction(loc));
|
||||
},
|
||||
onTap: (loc) {
|
||||
onTap: (YourLocation loc) {
|
||||
gotoLocationMap(store, loc, context);
|
||||
},
|
||||
onRefresh: (refreshCallback) =>
|
||||
store.dispatch(new FetchYourLocationsAction(refreshCallback)),
|
||||
onRefresh: (Completer<void> refreshCallback) =>
|
||||
store.dispatch(FetchYourLocationsAction(refreshCallback)),
|
||||
yourLocations: store.state.yourLocations,
|
||||
isLoading: !store.state.isLoaded);
|
||||
},
|
||||
builder: (context, view) {
|
||||
var hasLocations = view.yourLocations.length > 0;
|
||||
final title = hasLocations
|
||||
builder: (BuildContext context, _ViewModel view) {
|
||||
final bool hasLocations = view.yourLocations.isNotEmpty;
|
||||
final String title = hasLocations
|
||||
? S.of(context).firesInYourPlaces
|
||||
: S.of(context).firesInTheWorld;
|
||||
print('Building Active Fires');
|
||||
|
|
@ -223,11 +224,11 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
// FIXME new?
|
||||
drawer: new MainDrawer(context, ActiveFiresPage.routeName),
|
||||
appBar: new AppBar(
|
||||
drawer: MainDrawer(context, ActiveFiresPage.routeName),
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.menu),
|
||||
icon: const Icon(Icons.menu),
|
||||
onPressed: () {
|
||||
_scaffoldKey.currentState?.openDrawer();
|
||||
},
|
||||
|
|
@ -235,12 +236,12 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
),
|
||||
floatingActionButtonLocation:
|
||||
FloatingActionButtonLocation.centerFloat,
|
||||
bottomNavigationBar: new GlobalFiresBottomStats(),
|
||||
bottomNavigationBar: const GlobalFiresBottomStats(),
|
||||
body: view.isLoading
|
||||
? new FiresSpinner()
|
||||
? const FiresSpinner()
|
||||
: hasLocations
|
||||
? new Stack(children: <Widget>[
|
||||
new RefreshIndicator(
|
||||
? Stack(children: <Widget>[
|
||||
RefreshIndicator(
|
||||
child: _buildSavedLocations(
|
||||
context,
|
||||
view.yourLocations,
|
||||
|
|
@ -248,8 +249,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
view.onToggleSubs,
|
||||
view.onTap),
|
||||
onRefresh: () async {
|
||||
final Completer<Null> completer =
|
||||
new Completer<Null>();
|
||||
final Completer<void> completer =
|
||||
Completer<void>();
|
||||
view.onRefresh(completer);
|
||||
return completer.future;
|
||||
}),
|
||||
|
|
@ -260,15 +261,15 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
children: _fabMiniMenuItemList(context, view.onAdd),
|
||||
)
|
||||
])
|
||||
: new Center(
|
||||
child: new CenteredColumn(children: <Widget>[
|
||||
new RoundedBtn(
|
||||
: Center(
|
||||
child: CenteredColumn(children: <Widget>[
|
||||
RoundedBtn(
|
||||
icon: Icons.location_searching,
|
||||
text: S.of(context).addYourCurrentPosition,
|
||||
onPressed: () => onAddYourLocation(view.onAdd),
|
||||
backColor: fires600),
|
||||
const SizedBox(height: 26.0),
|
||||
new RoundedBtn(
|
||||
RoundedBtn(
|
||||
icon: Icons.edit_location,
|
||||
text: S.of(context).addSomePlace,
|
||||
onPressed: () => onAddOtherLocation(view.onAdd),
|
||||
|
|
@ -280,23 +281,23 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
|
||||
void gotoLocationMap(
|
||||
Store<AppState> store, YourLocation loc, BuildContext context) {
|
||||
store.dispatch(new ShowYourLocationMapAction(loc));
|
||||
store.dispatch(ShowYourLocationMapAction(loc));
|
||||
Navigator.push(
|
||||
context, new MaterialPageRoute(builder: (context) => new genericMap()));
|
||||
context, MaterialPageRoute(builder: (BuildContext context) => const genericMap()));
|
||||
}
|
||||
|
||||
void onAddYourLocation(AddYourLocationFunction onAdd) {
|
||||
Future<YourLocation> location = getUserLocation(_scaffoldKey);
|
||||
final Future<YourLocation> location = getUserLocation(_scaffoldKey);
|
||||
_saveLocation(location, onAdd);
|
||||
}
|
||||
|
||||
void onAddOtherLocation(AddYourLocationFunction onAdd) {
|
||||
Future<YourLocation> location = openPlacesDialog(_scaffoldKey);
|
||||
final Future<YourLocation> location = openPlacesDialog(_scaffoldKey);
|
||||
_saveLocation(location, onAdd);
|
||||
}
|
||||
|
||||
void _saveLocation(Future<YourLocation> location, onAdd) {
|
||||
location.then((newLocation) {
|
||||
location.then((YourLocation newLocation) {
|
||||
if (newLocation != YourLocation.noLocation) {
|
||||
onAdd(newLocation);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue