134 lines
5.5 KiB
Dart
134 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.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/core/ui/navigation_bar.dart';
|
|
import 'package:seshat/ui/home_page/view_model/home_view_model.dart';
|
|
import 'package:seshat/ui/home_page/widgets/create_confirmation_popup.dart';
|
|
import 'package:seshat/ui/core/ui/await_loading.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key, required this.viewModel});
|
|
|
|
final HomeViewModel viewModel;
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
initializeDateFormatting();
|
|
var format = DateFormat("dd MMM yyyy", "fr");
|
|
return Scaffold(
|
|
bottomNavigationBar: AppNavigationBar(startIndex: 0),
|
|
appBar: AppBar(title: Text("Gestion des BALs")),
|
|
body: ListenableBuilder(
|
|
listenable: widget.viewModel,
|
|
builder: (context, child) {
|
|
return switch (widget.viewModel.isLoaded) {
|
|
false => AwaitLoading(),
|
|
true => Column(
|
|
children: [
|
|
Expanded(
|
|
child: (widget.viewModel.bals.isEmpty)
|
|
? Center(child: Text("Aucune BAL existante"))
|
|
: ListView(
|
|
children: [
|
|
for (Bal bal in widget.viewModel.bals.where(
|
|
(el) => el.id != widget.viewModel.currentBal?.id,
|
|
))
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 10.0,
|
|
),
|
|
child: Card(
|
|
child: ListTile(
|
|
leading: switch (bal.state) {
|
|
BalState.pending => Icon(Icons.event),
|
|
BalState.ongoing => Icon(
|
|
Icons.event_available,
|
|
),
|
|
BalState.ended => Icon(Icons.lock),
|
|
},
|
|
title: Text(bal.name),
|
|
subtitle: switch (bal.state) {
|
|
BalState.pending => Text(
|
|
"À venir · Débute le ${format.format(bal.startTime)}",
|
|
),
|
|
BalState.ongoing => Text("En cours"),
|
|
BalState.ended => Text("Terminée"),
|
|
},
|
|
trailing: switch (bal.state) {
|
|
BalState.ended => IconButton(
|
|
onPressed: () {
|
|
_moveToBal(context, bal.id);
|
|
},
|
|
icon: Icon(Icons.analytics),
|
|
),
|
|
_ => IconButton(
|
|
onPressed: () {
|
|
_moveToBal(context, bal.id);
|
|
},
|
|
icon: Icon(Icons.arrow_forward),
|
|
),
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
switch (widget.viewModel.currentBal == null) {
|
|
true => SizedBox(),
|
|
false => Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
|
child: Card(
|
|
child: ListTile(
|
|
leading: Icon(Icons.event_available),
|
|
title: Text(widget.viewModel.currentBal!.name),
|
|
subtitle: Text("BAL en cours"),
|
|
trailing: IconButton(
|
|
onPressed: () {
|
|
_moveToBal(
|
|
context,
|
|
widget.viewModel.currentBal!.id,
|
|
);
|
|
},
|
|
icon: Icon(Icons.arrow_forward),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
SizedBox(height: 10),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (context) {
|
|
return CreateConfirmationPopup(
|
|
viewModel: widget.viewModel,
|
|
);
|
|
},
|
|
);
|
|
},
|
|
child: Text("Créer une BAL"),
|
|
),
|
|
SizedBox(height: 5),
|
|
],
|
|
),
|
|
};
|
|
},
|
|
),
|
|
);
|
|
// return Center(child: Text("Home page;"));
|
|
}
|
|
}
|
|
|
|
void _moveToBal(BuildContext context, int id) {
|
|
context.goNamed("bal", pathParameters: {"id": id.toString()});
|
|
}
|