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:
vjrj 2026-03-06 11:21:06 +01:00
parent 1864e5b105
commit 7a4c9fb3bc
61 changed files with 1386 additions and 1202 deletions

View file

@ -2,8 +2,6 @@ import 'dart:async';
import 'package:comunes_flutter/comunes_flutter.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_redux/flutter_redux.dart';
import 'package:get_it/get_it.dart';
@ -17,12 +15,14 @@ import 'firesSpinner.dart';
import 'generated/i18n.dart';
import 'mainDrawer.dart';
import 'models/appState.dart';
import 'models/fireNotification.dart';
import 'objectIdUtils.dart';
import 'redux/actions.dart';
class _ViewModel {
final bool isLoaded;
_ViewModel({required this.isLoaded});
final bool isLoaded;
@override
bool operator ==(Object other) =>
@ -36,21 +36,21 @@ class _ViewModel {
}
class HomePage extends StatefulWidget {
static const String routeName = '/home';
HomePage();
const HomePage({super.key});
static const String routeName = '/home';
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final Store<AppState> store = GetIt.instance<Store<AppState>>();
final List<FireNotification> newNotifications = [];
final List<FireNotification> newNotifications = <FireNotification>[];
// Platform messages are asynchronous, so we initialize in an async method.
Future<Null> initConnectivity() async {
Future<void> initConnectivity() async {
// Connectivity checking removed - no longer needed
}
@ -70,9 +70,9 @@ class _HomePageState extends State<HomePage> {
// Listen for messages when app is in foreground
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
debugPrint(
"onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message");
'onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message');
if (message.data.isNotEmpty) {
final notif = _notifForMessage(message.data, store.state.isLoaded);
final FireNotification? notif = _notifForMessage(message.data, store.state.isLoaded);
if (notif != null) {
_showItemDialog(message.data, notif);
}
@ -82,7 +82,7 @@ class _HomePageState extends State<HomePage> {
// Listen for messages when app is opened from background
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
debugPrint(
"onMessageOpenedApp (isLoaded: ${store.state.isLoaded}): $message");
'onMessageOpenedApp (isLoaded: ${store.state.isLoaded}): $message');
if (message.data.isNotEmpty) {
_notifForMessage(message.data, store.state.isLoaded);
_navigateToItemDetail(message.data);
@ -92,7 +92,7 @@ class _HomePageState extends State<HomePage> {
// Check if app was terminated and opened by notification tap
_firebaseMessaging.getInitialMessage().then((RemoteMessage? message) {
if (message != null) {
debugPrint("App opened by notification: $message");
debugPrint('App opened by notification: $message');
if (message.data.isNotEmpty) {
_navigateToItemDetail(message.data);
}
@ -103,39 +103,39 @@ class _HomePageState extends State<HomePage> {
void _getFirebaseToken() {
_firebaseMessaging.getToken().then((String? token) {
if (token != null) {
store.dispatch(new OnUserTokenAction(token));
store.dispatch(OnUserTokenAction(token));
setState(() {});
}
});
}
final _homeFont = const TextStyle(
final TextStyle _homeFont = const TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.w600,
);
final _btnFont = const TextStyle(
final TextStyle _btnFont = const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w600,
);
@override
Widget build(BuildContext context) {
return new StoreConnector<AppState, _ViewModel>(
return StoreConnector<AppState, _ViewModel>(
distinct: true,
converter: (store) {
bool isLoaded = store.state.isLoaded;
converter: (Store<AppState> store) {
final bool isLoaded = store.state.isLoaded;
if (isLoaded && newNotifications.isNotEmpty) {
newNotifications.forEach((notif) {
store.dispatch(new AddFireNotificationAction(notif));
});
for (final FireNotification notif in newNotifications) {
store.dispatch(AddFireNotificationAction(notif));
}
newNotifications.clear();
}
return new _ViewModel(isLoaded: store.state.isLoaded);
return _ViewModel(isLoaded: store.state.isLoaded);
},
builder: (context, view) {
return new Scaffold(
builder: (BuildContext context, _ViewModel view) {
return Scaffold(
key: _scaffoldKey,
drawer: new MainDrawer(context, HomePage.routeName),
drawer: MainDrawer(context, HomePage.routeName),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: Column(
@ -160,7 +160,7 @@ class _HomePageState extends State<HomePage> {
},
heroTag: 'notifyFire',
backgroundColor: fires600,
label: new Text(S.of(context).notifyAFire,
label: Text(S.of(context).notifyAFire,
style: _btnFont),
icon:
const Icon(Icons.notifications_active, size: 32.0),
@ -168,41 +168,40 @@ class _HomePageState extends State<HomePage> {
),
]),
body: !view.isLoaded
? new FiresSpinner()
: new SafeArea(
? const FiresSpinner()
: SafeArea(
child: Center(
child: new CenteredColumn(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.start,
child: CenteredColumn(children: <Widget>[
Row(
children: <Widget>[
new IconButton(
IconButton(
onPressed: () {
_scaffoldKey.currentState?.openDrawer();
},
icon: new Icon(Icons.menu,
icon: const Icon(Icons.menu,
size: 30.0, color: Colors.black38)),
]),
new Expanded(
child: new FractionallySizedBox(
Expanded(
child: FractionallySizedBox(
alignment: FractionalOffset.center,
heightFactor: 0.7,
child: new Image.asset('images/logo-200.png',
child: Image.asset('images/logo-200.png',
fit: BoxFit.fitHeight))),
new Expanded(
child: new FractionallySizedBox(
Expanded(
child: FractionallySizedBox(
alignment: FractionalOffset.topCenter,
heightFactor: 1.0,
child: new Column(
child: Column(
children: <Widget>[
new Padding(
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 20.0),
child: FittedBox(
child: new Text(S.of(context).appName,
fit: BoxFit.scaleDown,
child: Text(S.of(context).appName,
maxLines: 2,
textAlign: TextAlign.center,
style: _homeFont),
fit: BoxFit.scaleDown,
)),
],
)))
@ -212,14 +211,14 @@ class _HomePageState extends State<HomePage> {
}
void _showDialog(String message) {
final context = _scaffoldKey.currentContext;
final BuildContext? context = _scaffoldKey.currentContext;
if (context == null) return;
showDialog<bool>(
context: context,
builder: (_) => new AlertDialog(
content: new Text(message),
builder: (_) => AlertDialog(
content: Text(message),
actions: <Widget>[
new TextButton(
TextButton(
child: Text(S.of(context).CLOSE),
onPressed: () {
Navigator.pop(context);
@ -230,29 +229,29 @@ class _HomePageState extends State<HomePage> {
}
void _showItemDialog(Map<String, dynamic> message, FireNotification notif) {
final context = _scaffoldKey.currentContext;
final BuildContext? context = _scaffoldKey.currentContext;
if (context == null) return;
showDialog<bool>(
context: context,
builder: (_) => _buildDialog(context, notif),
).then((bool? shouldNavigate) {
if (shouldNavigate == true) {
if (shouldNavigate ?? false) {
_navigateToItemDetail(message);
}
}).catchError((e) => print("$e"));
}).catchError((e) => print('$e'));
}
Widget _buildDialog(BuildContext context, FireNotification item) {
return new AlertDialog(
content: new Text(item.description),
return AlertDialog(
content: Text(item.description),
actions: <Widget>[
new TextButton(
TextButton(
child: Text(S.of(context).CLOSE),
onPressed: () {
Navigator.pop(context, false);
},
),
new TextButton(
TextButton(
child: Text(S.of(context).SHOW),
onPressed: () {
Navigator.pop(context, true);
@ -263,7 +262,7 @@ class _HomePageState extends State<HomePage> {
}
void _navigateToItemDetail(Map<String, dynamic> message) {
final context = _scaffoldKey.currentContext;
final BuildContext? context = _scaffoldKey.currentContext;
if (context == null) return;
// Clear away dialogs
Navigator.popUntil(context, (Route<dynamic> route) => route is PageRoute);
@ -280,7 +279,7 @@ class _HomePageState extends State<HomePage> {
Map<String, dynamic> message, bool isLoaded) {
FireNotification? notif;
try {
notif = new FireNotification(
notif = FireNotification(
id: objectIdFromJson(message['id'] as String),
subsId: objectIdFromJson(message['subsId'] as String),
lat: double.parse(message['lat'] as String),
@ -296,7 +295,7 @@ class _HomePageState extends State<HomePage> {
// if our store is loaded, we just dispatch the notification, if not, we wait til is loaded
if (notif != null) {
if (isLoaded) {
store.dispatch(new AddFireNotificationAction(notif));
store.dispatch(AddFireNotificationAction(notif));
} else {
newNotifications.add(notif);
}