todos-contra-el-fuego-mobile/lib/fireAlert.dart
vjrj ea588a9753 refactor: clean up 55 lint warnings and issues
- Remove all 31 avoid_print debug statements across codebase
- Fix 8 critical warnings (unused variables, unreachable defaults, etc)
- Update deprecated APIs: launch() → launchUrl(), textScaleFactor → textScaler
- Replace deprecated surfaceVariant → surfaceContainerHighest in Material 3 themes
- Refactor switch statements to use modern pattern matching
- Remove unused code: _showDialog, _initNoLocation, _getAnchorOffset
- Fix use_build_context_synchronously by adding mounted checks
- Add ignore_for_file annotations to generated JSON serialization files
- Fix type annotations in appState.dart and models

Warnings reduced from 301 to 246 issues (8 → 0 critical warnings).
Build verified: app-production-debug.apk (160MB) compiles successfully.
Zero type errors, Dart analysis clean for critical issues.
2026-03-06 22:47:27 +01:00

124 lines
4 KiB
Dart

import 'package:community_material_icon/community_material_icon.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import 'customStepper.dart';
import 'generated/i18n.dart';
import 'mainDrawer.dart';
import 'models/yourLocation.dart';
import 'placesAutocompleteUtils.dart';
class FireAlert extends StatefulWidget {
const FireAlert({super.key});
static const String routeName = '/fireAlert';
@override
_FireAlertState createState() => _FireAlertState();
}
class _FireAlertState extends State<FireAlert> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
int _currentStep = 0;
Widget buildCallButton() {
return Align(
alignment: const Alignment(0.0, -0.2),
child: FloatingActionButton(
heroTag: 'callAction',
child: const Icon(Icons.call),
onPressed: () async {
final Uri url = Uri(scheme: 'tel', path: '112');
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
},
),
);
}
Widget buildNotifyNeighboursButton() {
return Align(
alignment: const Alignment(0.0, -0.2),
child: FloatingActionButton(
heroTag: 'neighAction',
child: const Icon(CommunityMaterialIcons.bullhorn),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(S.of(context).inDevelopment),
));
},
),
);
}
Widget buildTweetButton() {
return Align(
alignment: const Alignment(0.0, -0.2),
child: FloatingActionButton(
heroTag: 'tweetAction',
child: const Icon(CommunityMaterialIcons.twitter),
onPressed: () {
openPlacesDialog(_scaffoldKey).then((YourLocation yourLocation) {
final String where =
yourLocation.description.replaceAll(' ', '').split(',')[0];
Share.shareWithResult(S
.of(context)
.tweetAboutSelf(yourLocation.description, '#IF$where'));
}).catchError((Object onError) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(S.of(context).errorFirePlaceDialog)));
}
});
},
),
);
}
List<CustomStep> listWithoutNulls(List<CustomStep> children) =>
children.where(notNull).toList();
@override
Widget build(BuildContext context) {
final List<CustomStep> fireSteps = listWithoutNulls(<CustomStep>[
CustomStep(
title: Text(S.of(context).callEmergencyServicesTitle),
content: Column(children: <Widget>[
Text(S.of(context).callEmergencyServicesDescription),
const SizedBox(height: 20.0),
buildCallButton()
])),
CustomStep(
title: Text(S.of(context).notifyNeighbours),
// state: CustomStepState.disabled,
content: Column(children: <Widget>[
Text(S.of(context).notifyNeighboursDescription),
const SizedBox(height: 20.0),
buildNotifyNeighboursButton()
])),
// TODOconditional: this only in Spain
CustomStep(
title: Text(S.of(context).tweetAboutAFireTitle),
// subtitle: new Text(S.of(context).tweetAboutAFireDescription),
content: Column(children: <Widget>[
Text(S.of(context).tweetAboutAFireDescription),
const SizedBox(height: 20.0),
buildTweetButton()
])),
]);
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(title: Text(S.of(context).notifyAFire)),
drawer: MainDrawer(context, FireAlert.routeName),
body: CustomStepper(
currentCustomStep: _currentStep,
// type: StepperType.horizontal,
onCustomStepTapped: (int num) => setState(() {
_currentStep = num;
}),
steps: fireSteps));
}
}