203 lines
6.3 KiB
Dart
203 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/date_symbol_data_local.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:seshat/domain/models/bal.dart';
|
|
import 'package:seshat/ui/bal_page/view_model/bal_view_model.dart';
|
|
import 'package:seshat/ui/core/ui/navigation_bar.dart';
|
|
|
|
class BalPendingScreen extends StatelessWidget {
|
|
const BalPendingScreen({super.key, required this.viewModel});
|
|
|
|
final BalViewModel viewModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
bottomNavigationBar: AppNavigationBar(startIndex: 0),
|
|
appBar: AppBar(
|
|
title: Text(viewModel.bal!.name),
|
|
actions: [
|
|
IconButton(
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (context) => EditPopup(viewModel: viewModel),
|
|
);
|
|
},
|
|
icon: Icon(Icons.edit),
|
|
),
|
|
],
|
|
),
|
|
body: Center(
|
|
child: ElevatedButton(
|
|
onPressed: viewModel.isABalOngoing
|
|
? () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text("Une BAL est déjà en cours.")),
|
|
);
|
|
}
|
|
: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text(
|
|
"Êtes-vous sûr·e de vouloir débuter cette BAL ?",
|
|
),
|
|
content: Text(
|
|
"Cette action est irréversible. Vous pourrez ensuite intéragir avec la BAL, mais pas la remettre en mode \"À venir\"",
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text("Annuler"),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
await viewModel.startBal(viewModel.bal!.id);
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
child: Text("Valider"),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
child: Text("Démarrer cette BAL"),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class EditPopup extends StatefulWidget {
|
|
const EditPopup({super.key, required this.viewModel});
|
|
|
|
final BalViewModel viewModel;
|
|
|
|
@override
|
|
State<EditPopup> createState() => _EditPopup();
|
|
}
|
|
|
|
class _EditPopup extends State<EditPopup> {
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
String? name;
|
|
DateTime? start;
|
|
DateTime? end;
|
|
Future<void> _selectRange() async {
|
|
final DateTimeRange? pickedDate = await showDateRangePicker(
|
|
context: context,
|
|
firstDate: DateTime(DateTime.now().year - 1),
|
|
lastDate: DateTime(DateTime.now().year + 2),
|
|
initialDateRange: DateTimeRange(
|
|
start: start ?? widget.viewModel.bal!.startTime,
|
|
end: end ?? widget.viewModel.bal!.endTime,
|
|
),
|
|
);
|
|
|
|
setState(() {
|
|
start = pickedDate?.start;
|
|
end = pickedDate?.end;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
initializeDateFormatting();
|
|
var format = DateFormat("dd MMM yyyy", "fr");
|
|
return AlertDialog(
|
|
title: Text("Créer une BAL"),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
labelText: "Nom de la BAL",
|
|
border: OutlineInputBorder(),
|
|
),
|
|
initialValue: widget.viewModel.bal!.name,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return "Veuillez entrer un nom";
|
|
}
|
|
return null;
|
|
},
|
|
onSaved: (newValue) {
|
|
name = newValue;
|
|
},
|
|
),
|
|
Row(
|
|
children: [
|
|
Text("Date de début : "),
|
|
TextButton(
|
|
onPressed: () {
|
|
_selectRange();
|
|
},
|
|
child: Text(
|
|
"Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}",
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Text("Note: Les dates sont à titre purement indicatif."),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text("Annuler"),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
if (_formKey.currentState!.validate()) {
|
|
_formKey.currentState!.save();
|
|
|
|
final Bal bal = widget.viewModel.bal!;
|
|
|
|
final result = await widget.viewModel.editBal(
|
|
bal.id,
|
|
name ?? bal.name,
|
|
start ?? bal.startTime,
|
|
end ?? bal.endTime,
|
|
);
|
|
if (result is Error && context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text("Une erreur est survenue")),
|
|
);
|
|
}
|
|
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
"Veuillez indiquer une date de début et de fin.",
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
child: Text("Valider"),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|