diff --git a/lib/ui/home_page/widgets/home_page.dart b/lib/ui/home_page/widgets/home_page.dart index 588347b..d20fd69 100644 --- a/lib/ui/home_page/widgets/home_page.dart +++ b/lib/ui/home_page/widgets/home_page.dart @@ -25,10 +25,102 @@ class _HomePageState extends State { builder: (context, child) { return switch (widget.viewModel.isLoaded) { false => AwaitLoading(), - true => switch (widget.viewModel.currentBal == null) { - true => HomePageOnNoCurrent(widget: widget), - false => HomePageOnCurrent(widget: widget), - }, + 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 ${bal.startTime.toString()}", + ), + BalState.ongoing => Text("En cours"), + BalState.ended => Text("Terminée"), + }, + trailing: switch (bal.state) { + BalState.pending => IconButton( + onPressed: () { + _moveToBal(context, bal.id); + }, + icon: Icon(Icons.edit), + ), + BalState.ongoing => IconButton( + onPressed: () { + _moveToBal(context, bal.id); + }, + icon: Icon(Icons.arrow_forward), + ), + BalState.ended => IconButton( + onPressed: () { + _moveToBal(context, bal.id); + }, + icon: Icon(Icons.analytics), + ), + }, + ), + ), + ), + ], + ), + ), + 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, + builder: (context) { + return CreateConfirmationPopup( + viewModel: widget.viewModel, + ); + }, + ); + }, + child: Text("Créer une BAL"), + ), + SizedBox(height: 5), + ], + ), }; }, ), @@ -37,178 +129,6 @@ class _HomePageState extends State { } } -class HomePageOnNoCurrent extends StatelessWidget { - const HomePageOnNoCurrent({super.key, required this.widget}); - - final HomePage widget; - - @override - Widget build(BuildContext context) { - return 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 ${bal.startTime.toString()}", - ), - BalState.ongoing => Text("En cours"), - BalState.ended => Text("Terminée"), - }, - trailing: switch (bal.state) { - BalState.pending => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.edit), - ), - BalState.ongoing => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.arrow_forward), - ), - BalState.ended => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.analytics), - ), - }, - ), - ), - ), - ], - ), - ), - SizedBox(height: 10), - ElevatedButton( - onPressed: () { - showDialog( - context: context, - builder: (context) { - return CreateConfirmationPopup(viewModel: widget.viewModel); - }, - ); - }, - child: Text("Débuter une BAL"), - ), - SizedBox(height: 5), - ], - ); - } -} - -class HomePageOnCurrent extends StatelessWidget { - const HomePageOnCurrent({super.key, required this.widget}); - - final HomePage widget; - - @override - Widget build(BuildContext context) { - return 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 ${bal.startTime.toString()}", - ), - BalState.ongoing => Text("En cours"), - BalState.ended => Text("Terminée"), - }, - trailing: switch (bal.state) { - BalState.pending => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.edit), - ), - BalState.ongoing => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.arrow_forward), - ), - BalState.ended => IconButton( - onPressed: () { - _moveToBal(context, bal.id); - }, - icon: Icon(Icons.analytics), - ), - }, - ), - ), - ), - ], - ), - ), - 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, - builder: (context) { - return CreateConfirmationPopup(viewModel: widget.viewModel); - }, - ); - }, - child: Text("Créer une BAL"), - ), - SizedBox(height: 5), - ], - ); - } -} - void _moveToBal(BuildContext context, int id) { context.goNamed("bal", pathParameters: {"id": id.toString()}); }