132 lines
4.5 KiB
Dart
132 lines
4.5 KiB
Dart
import 'package:manager_app/l10n/app_localizations.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:manager_app/Components/map_canvas.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
|
|
/// L'éditeur de géométrie en dialogue.
|
|
///
|
|
/// Le dessin a déménagé dans `MapCanvas`, qui sait vivre dans un écran. Ce
|
|
/// dialogue n'est plus qu'une coquille autour de lui, pour les appelants qui
|
|
/// ouvrent encore une modale — `etape_fields` et `showNewOrUpdateEventAgenda`.
|
|
/// Il disparaîtra avec eux.
|
|
class MapGeometryPicker extends StatefulWidget {
|
|
final GeometryDTO? initialGeometry;
|
|
final String? initialColor;
|
|
final Function(GeometryDTO, String) onSave;
|
|
final bool showColorButton;
|
|
|
|
MapGeometryPicker({
|
|
Key? key,
|
|
this.initialGeometry,
|
|
this.initialColor,
|
|
required this.onSave,
|
|
this.showColorButton = true,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<MapGeometryPicker> createState() => _MapGeometryPickerState();
|
|
}
|
|
|
|
class _MapGeometryPickerState extends State<MapGeometryPicker> {
|
|
GeometryDTO? geometry;
|
|
String? color;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
geometry = widget.initialGeometry;
|
|
color = widget.initialColor;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l = AppLocalizations.of(context)!;
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
return Dialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(kRadiusShell),
|
|
side: const BorderSide(color: kLine),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
insetPadding:
|
|
const EdgeInsets.symmetric(horizontal: kSpace7, vertical: kSpace7),
|
|
child: SizedBox(
|
|
width: size.width * 0.9,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.fromLTRB(kSpace6, kSpace5, kSpace4, kSpace5),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(l.geometryEditorTitle, style: kTitleCard)),
|
|
IconButton(
|
|
icon: const Icon(Icons.close, size: 20, color: kInk3),
|
|
tooltip: l.cancel,
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Divider(height: 1, thickness: 1, color: kLineSoft),
|
|
Padding(
|
|
padding: const EdgeInsets.all(kSpace5),
|
|
child: MapCanvas(
|
|
geometry: geometry,
|
|
color: color,
|
|
showColorButton: widget.showColorButton,
|
|
height: size.height * 0.62,
|
|
onChanged: (newGeometry, newColor) {
|
|
geometry = newGeometry;
|
|
color = newColor;
|
|
},
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.all(kSpace4),
|
|
decoration: const BoxDecoration(
|
|
color: kSurface2,
|
|
border: Border(top: BorderSide(color: kLineSoft)),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(l.cancel,
|
|
style: const TextStyle(fontSize: 13, color: kInk2)),
|
|
),
|
|
const SizedBox(width: kSpace2),
|
|
FilledButton(
|
|
onPressed: () {
|
|
if (geometry != null) {
|
|
widget.onSave(geometry!, color ?? '#264863');
|
|
}
|
|
Navigator.pop(context);
|
|
},
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: kPrimaryColor,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: kSpace5, vertical: kSpace3),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(kRadiusPill)),
|
|
),
|
|
child: Text(l.save,
|
|
style: const TextStyle(
|
|
fontSize: 13, fontWeight: FontWeight.w600)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|