fix: make the switch have more sense

This commit is contained in:
alzalia1 2025-08-13 14:24:12 +02:00
parent 8e379241ee
commit 6c6f0da1ae

View file

@ -25,26 +25,7 @@ class _HomePageState extends State<HomePage> {
builder: (context, child) {
return switch (widget.viewModel.isLoaded) {
false => AwaitLoading(),
true => switch (widget.viewModel.currentBal == null) {
true => HomePageOnNoCurrent(widget: widget),
false => HomePageOnCurrent(widget: widget),
},
};
},
),
);
// return Center(child: Text("Home page;"));
}
}
class HomePageOnNoCurrent extends StatelessWidget {
const HomePageOnNoCurrent({super.key, required this.widget});
final HomePage widget;
@override
Widget build(BuildContext context) {
return Column(
true => Column(
children: [
Expanded(
child: (widget.viewModel.bals.isEmpty)
@ -55,12 +36,16 @@ class HomePageOnNoCurrent extends StatelessWidget {
(el) => el.id != widget.viewModel.currentBal?.id,
))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
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.ongoing => Icon(
Icons.event_available,
),
BalState.ended => Icon(Icons.lock),
},
title: Text(bal.name),
@ -97,85 +82,9 @@ class HomePageOnNoCurrent extends StatelessWidget {
],
),
),
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(
switch (widget.viewModel.currentBal == null) {
true => SizedBox(),
false => Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Card(
child: ListTile(
@ -184,20 +93,26 @@ class HomePageOnCurrent extends StatelessWidget {
subtitle: Text("BAL en cours"),
trailing: IconButton(
onPressed: () {
_moveToBal(context, widget.viewModel.currentBal!.id);
_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);
return CreateConfirmationPopup(
viewModel: widget.viewModel,
);
},
);
},
@ -205,7 +120,12 @@ class HomePageOnCurrent extends StatelessWidget {
),
SizedBox(height: 5),
],
),
};
},
),
);
// return Center(child: Text("Home page;"));
}
}