213 lines
7.8 KiB
Dart
213 lines
7.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.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';
|
|
|
|
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) {
|
|
return Scaffold(
|
|
bottomNavigationBar: AppNavigationBar(startIndex: 0),
|
|
body: ListenableBuilder(
|
|
listenable: widget.viewModel,
|
|
builder: (context, child) {
|
|
return switch (widget.viewModel.isLoaded) {
|
|
false => Center(child: CircularProgressIndicator()),
|
|
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(
|
|
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()});
|
|
}
|