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,10 +25,102 @@ class _HomePageState extends State<HomePage> {
builder: (context, child) { builder: (context, child) {
return switch (widget.viewModel.isLoaded) { return switch (widget.viewModel.isLoaded) {
false => AwaitLoading(), false => AwaitLoading(),
true => switch (widget.viewModel.currentBal == null) { true => Column(
true => HomePageOnNoCurrent(widget: widget), children: [
false => HomePageOnCurrent(widget: widget), 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<HomePage> {
} }
} }
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) { void _moveToBal(BuildContext context, int id) {
context.goNamed("bal", pathParameters: {"id": id.toString()}); context.goNamed("bal", pathParameters: {"id": id.toString()});
} }