Remove the external comunes-flutter library dependency and replace all its components with local implementations: - Utility functions: Created lib/utils/widget_utils.dart with compactWidgets() and ellipse() functions, replacing the comunes-flutter helpers with modern Dart null-safety patterns (whereType instead of where(notNull)) - Secret loader: Inlined as lib/utils/secret_loader.dart for loading JSON config - Layout widgets: Replaced CenteredRow/CenteredColumn with standard Row/Column with MainAxisAlignment.center - Intro screens: Copied AppIntroPage and MaterialAppWithIntro locally in lib/widgets/ with cleaned-up deprecated code patterns - Button widget: Created lib/widgets/rounded_btn.dart for the RoundedBtn used in activeFires.dart Changes span 20 files: - 5 new utility/widget files created - Updated imports in 15 files - Removed path dependency from pubspec.yaml - All functionality preserved, build verified with flutter pub get Impact: - Removes external dependency, simplifying project structure - Modern Dart patterns (proper null-safety) - Better code clarity with explicit widget properties - Easier onboarding (no 'what is comunes-flutter?' questions)
142 lines
5.8 KiB
Dart
142 lines
5.8 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'colors.dart';
|
|
import 'customBottomAppBar.dart';
|
|
import 'customMoment.dart';
|
|
import 'generated/i18n.dart';
|
|
import 'models/appState.dart';
|
|
import 'models/falsePositiveTypes.dart';
|
|
import 'models/fireMapState.dart';
|
|
import 'models/fireNotification.dart';
|
|
import 'models/yourLocation.dart';
|
|
import 'utils/widget_utils.dart';
|
|
|
|
typedef OnSave = void Function();
|
|
typedef OnCancel = void Function();
|
|
typedef OnFalsePositive = void Function(
|
|
FireNotification notif, FalsePositiveType type);
|
|
|
|
class GenericMapBottom extends StatelessWidget {
|
|
const GenericMapBottom(
|
|
{super.key,
|
|
required this.onSave,
|
|
required this.onCancel,
|
|
required this.onFalsePositive,
|
|
required this.state,
|
|
required this.scaffoldKey});
|
|
final OnSave onSave;
|
|
final OnCancel onCancel;
|
|
final OnFalsePositive onFalsePositive;
|
|
final FireMapState state;
|
|
final GlobalKey<ScaffoldState> scaffoldKey;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final YourLocation? locOrNull = state.yourLocation;
|
|
if (locOrNull == null) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
final YourLocation loc = locOrNull;
|
|
final int kmAround = loc.distance;
|
|
return CustomBottomAppBar(
|
|
fabLocation: FloatingActionButtonLocation.centerFloat,
|
|
color: fires100,
|
|
actions: buildActionList(loc, context, kmAround, scaffoldKey));
|
|
}
|
|
|
|
List<Widget> buildActionList(YourLocation loc, BuildContext context,
|
|
int kmAround, GlobalKey<ScaffoldState> scaffoldState) {
|
|
final List<Widget> actionList = <Widget>[];
|
|
switch (state.status) {
|
|
case FireMapStatus.edit:
|
|
actionList.add(TextButton(
|
|
onPressed: onSave,
|
|
child: Text(S.of(context).SAVE,
|
|
style: Theme.of(context).textTheme.labelLarge)));
|
|
actionList.add(TextButton(
|
|
onPressed: onCancel,
|
|
child: Text(S.of(context).CANCEL,
|
|
style: Theme.of(context).textTheme.labelLarge)));
|
|
break;
|
|
case FireMapStatus.subscriptionConfirm:
|
|
break;
|
|
case FireMapStatus.viewFireNotification:
|
|
final FireNotification? notif = state.fireNotification;
|
|
if (notif != null) {
|
|
actionList.add(Flexible(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: compactWidgets(<Widget?>[
|
|
Text(notif.description),
|
|
// TODOfire type (neighbout, NASA, etc)
|
|
const SizedBox(height: 5.0),
|
|
Row(
|
|
children: <Widget>[
|
|
const Icon(Icons.access_time),
|
|
const SizedBox(width: 5.0),
|
|
Text(Moment.now().from(context, notif.when)),
|
|
],
|
|
),
|
|
if (state.industries.isNotEmpty ||
|
|
state.falsePos.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 10.0),
|
|
child: Text(S.of(context).itSeemsNotAtForesFire,
|
|
style: const TextStyle(color: fires600)))
|
|
else
|
|
null,
|
|
DropdownButton<FalsePositiveType>(
|
|
style: const TextStyle(
|
|
color: Colors.black,
|
|
// fontSize: 18.0,
|
|
),
|
|
hint: Text(S.of(context).notAWildfire),
|
|
items: FalsePositiveType.values
|
|
.map((FalsePositiveType value) {
|
|
String menuText;
|
|
switch (value) {
|
|
case FalsePositiveType.industry:
|
|
menuText = S.of(context).itSeemsAIndustry;
|
|
break;
|
|
case FalsePositiveType.controled:
|
|
menuText =
|
|
S.of(context).itSeemsAControlledBurning;
|
|
break;
|
|
case FalsePositiveType.falsealarm:
|
|
menuText = S.of(context).itSeemsAFalseAlarm;
|
|
}
|
|
return DropdownMenuItem<FalsePositiveType>(
|
|
value: value, child: Text(menuText));
|
|
}).toList(),
|
|
onChanged: (FalsePositiveType? value) async {
|
|
if (value != null) {
|
|
onFalsePositive(notif, value);
|
|
}
|
|
await Future<void>.delayed(
|
|
const Duration(milliseconds: 500));
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(
|
|
content:
|
|
Text(S.of(context).thanksForParticipating),
|
|
));
|
|
}),
|
|
] as List<Widget>)))));
|
|
}
|
|
break;
|
|
case FireMapStatus.unsubscribe:
|
|
case FireMapStatus.view:
|
|
actionList.add(Text(state.numFires > 0
|
|
? loc.currentNumFires == 1
|
|
? S.of(context).fireAroundThisArea(loc.distance.toString())
|
|
: S.of(context).firesAroundThisArea(
|
|
state.numFires.toString(), kmAround.toString())
|
|
: S.of(context).noFiresAroundThisArea(kmAround.toString())));
|
|
// SizedBox(width: 10.0)
|
|
}
|
|
return actionList;
|
|
}
|
|
}
|