todos-contra-el-fuego-mobile/lib/fireAlert.dart
vjrj 7a4c9fb3bc 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
2026-03-06 11:21:06 +01:00

125 lines
4.2 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: () {
launch('tel://112');
},
),
);
}
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: () {
// In Android you can choose with app to use with setPackage but seems it's not implemented here
// https://stackoverflow.com/questions/6814268/android-share-on-facebook-twitter-mail-ecc
openPlacesDialog(_scaffoldKey).then((YourLocation yourLocation) {
final String where =
yourLocation.description.replaceAll(' ', '').split(',')[0];
print(where);
Share.shareWithResult(S
.of(context)
.tweetAboutSelf(yourLocation.description, '#IF$where'));
}).catchError((onError) {
final BuildContext? ctx = _scaffoldKey.currentContext;
if (ctx != null) {
ScaffoldMessenger.of(ctx).showSnackBar(SnackBar(
content: Text(S.of(ctx).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));
}
}