Last changes not published

This commit is contained in:
vjrj 2026-03-05 01:18:27 +01:00
parent ac65ccf990
commit 21ec08303a
43 changed files with 607 additions and 613 deletions

View file

@ -1,21 +1,21 @@
import 'dart:async';
import 'package:bson_objectid/bson_objectid.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:connectivity/connectivity.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:fires_flutter/objectIdUtils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:redux/redux.dart';
import 'firesSpinner.dart';
import 'activeFires.dart';
import 'colors.dart';
import 'fireAlert.dart';
import 'fireNotificationList.dart';
import 'firesSpinner.dart';
import 'generated/i18n.dart';
import 'mainDrawer.dart';
import 'models/appState.dart';
@ -28,14 +28,13 @@ class _ViewModel {
@override
bool operator ==(Object other) =>
identical(this, other) ||
identical(this, other) ||
other is _ViewModel &&
runtimeType == other.runtimeType &&
isLoaded == other.isLoaded;
runtimeType == other.runtimeType &&
isLoaded == other.isLoaded;
@override
int get hashCode => isLoaded.hashCode;
}
class HomePage extends StatefulWidget {
@ -83,16 +82,20 @@ class _HomePageState extends State<HomePage> {
void initState() {
super.initState();
_firebaseMessaging.configure(onMessage: (Map<String, dynamic> message) {
debugPrint("onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message");
debugPrint(
"onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message");
_showItemDialog(message, _notifForMessage(message, store.state.isLoaded));
return;
}, onLaunch: (Map<String, dynamic> message) {
debugPrint("onLaunch (isLoaded: ${store.state.isLoaded}): $message");
_notifForMessage(message, store.state.isLoaded);
_navigateToItemDetail(message);
return;
}, onResume: (Map<String, dynamic> message) {
debugPrint("onResume (isLoaded: ${store.state.isLoaded}): $message");
_notifForMessage(message, store.state.isLoaded);
_navigateToItemDetail(message);
return;
});
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
@ -140,9 +143,7 @@ class _HomePageState extends State<HomePage> {
});
newNotifications.clear();
}
return new _ViewModel(
isLoaded: store.state.isLoaded
);
return new _ViewModel(isLoaded: store.state.isLoaded);
},
builder: (context, view) {
return new Scaffold(
@ -179,45 +180,47 @@ class _HomePageState extends State<HomePage> {
),
),
]),
body: !view.isLoaded? new FiresSpinner(): new SafeArea(
child: Center(
child: new CenteredColumn(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new IconButton(
onPressed: () {
_scaffoldKey.currentState.openDrawer();
},
icon: new Icon(Icons.menu,
size: 30.0, color: Colors.black38)),
]),
new Expanded(
child: new FractionallySizedBox(
alignment: FractionalOffset.center,
heightFactor: 0.7,
child: new Image.asset('images/logo-200.png',
fit: BoxFit.fitHeight))),
new Expanded(
child: new FractionallySizedBox(
alignment: FractionalOffset.topCenter,
heightFactor: 1.0,
child: new Column(
body: !view.isLoaded
? new FiresSpinner()
: new SafeArea(
child: Center(
child: new CenteredColumn(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
child: FittedBox(
child: new Text(S.of(context).appName,
maxLines: 2,
textAlign: TextAlign.center,
style: _homeFont),
fit: BoxFit.scaleDown,
)),
],
)))
])),
));
new IconButton(
onPressed: () {
_scaffoldKey.currentState.openDrawer();
},
icon: new Icon(Icons.menu,
size: 30.0, color: Colors.black38)),
]),
new Expanded(
child: new FractionallySizedBox(
alignment: FractionalOffset.center,
heightFactor: 0.7,
child: new Image.asset('images/logo-200.png',
fit: BoxFit.fitHeight))),
new Expanded(
child: new FractionallySizedBox(
alignment: FractionalOffset.topCenter,
heightFactor: 1.0,
child: new Column(
children: <Widget>[
new Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
child: FittedBox(
child: new Text(S.of(context).appName,
maxLines: 2,
textAlign: TextAlign.center,
style: _homeFont),
fit: BoxFit.scaleDown,
)),
],
)))
])),
));
});
}
@ -282,12 +285,13 @@ class _HomePageState extends State<HomePage> {
// https://pub.dartlang.org/packages/firebase_messaging#-example-tab-
final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
FireNotification _notifForMessage(Map<String, dynamic> message, bool isLoaded) {
FireNotification _notifForMessage(
Map<String, dynamic> message, bool isLoaded) {
FireNotification notif;
try {
notif = new FireNotification(
id: new ObjectId.fromHexString(message['id']),
subsId: new ObjectId.fromHexString(message['subsId']),
id: objectIdFromJson(message['id']),
subsId: objectIdFromJson(message['subsId']),
lat: double.parse(message['lat']),
lon: double.parse(message['lon']),
description: message['description'],
@ -299,12 +303,12 @@ class _HomePageState extends State<HomePage> {
debugPrint(e.toString());
}
if (notif != null)
// if our store is loaded, we just dispatch the notification, if not, we wait til is loaded
if (isLoaded) {
store.dispatch(new AddFireNotificationAction(notif));
} else {
newNotifications.add(notif);
}
// if our store is loaded, we just dispatch the notification, if not, we wait til is loaded
if (isLoaded) {
store.dispatch(new AddFireNotificationAction(notif));
} else {
newNotifications.add(notif);
}
return notif;
}
}