Implemented Loading Indicator in MainMenu

This commit is contained in:
Felix Kirchner
2025-05-03 02:26:24 +02:00
parent 663adb717e
commit e9ad9c445e
2 changed files with 76 additions and 68 deletions

View File

@@ -16,17 +16,23 @@ class MainMenuView extends StatefulWidget {
} }
class _MainMenuViewState extends State<MainMenuView> { class _MainMenuViewState extends State<MainMenuView> {
bool _isLoading = true;
@override @override
initState() { initState() {
super.initState(); super.initState();
LocalStorageService.loadGameSessions().then((_) { LocalStorageService.loadGameSessions().then((_) {
setState(() {}); setState(() {
_isLoading = false;
});
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('MainMenuView build');
LocalStorageService.loadGameSessions(); LocalStorageService.loadGameSessions();
return CupertinoPageScaffold( return CupertinoPageScaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
@@ -57,74 +63,76 @@ class _MainMenuViewState extends State<MainMenuView> {
), ),
child: CupertinoPageScaffold( child: CupertinoPageScaffold(
child: SafeArea( child: SafeArea(
child: Globals.gameList.isEmpty child: _isLoading
? Column( ? const Center(child: CupertinoActivityIndicator())
mainAxisAlignment: : Globals.gameList.isEmpty
MainAxisAlignment.center, // Oben ausrichten ? Column(
children: [ mainAxisAlignment:
const SizedBox(height: 30), // Abstand von oben MainAxisAlignment.center, // Oben ausrichten
Center( children: [
child: GestureDetector( const SizedBox(height: 30), // Abstand von oben
onTap: () => setState(() {}), Center(
child: Icon( child: GestureDetector(
CupertinoIcons.plus, onTap: () => setState(() {}),
size: 60, child: Icon(
color: CustomTheme.primaryColor, CupertinoIcons.plus,
), size: 60,
)), color: CustomTheme.primaryColor,
const SizedBox(height: 10), // Abstand von oben
const Padding(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Text(
'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
],
)
: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
), ),
onTap: () async { )),
//ignore: unused_local_variable const SizedBox(height: 10), // Abstand von oben
final val = await Navigator.push( const Padding(
context, padding: EdgeInsets.symmetric(horizontal: 70),
CupertinoPageRoute( child: Text(
builder: (context) => ActiveGameView( 'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
gameSession: Globals.gameList[index]), textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
],
)
: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
), ),
); onTap: () async {
setState(() {}); //ignore: unused_local_variable
}, final val = await Navigator.push(
)); context,
}), CupertinoPageRoute(
builder: (context) => ActiveGameView(
gameSession: Globals.gameList[index]),
),
);
setState(() {});
},
));
}),
), ),
), ),
); );

View File

@@ -2,7 +2,7 @@ name: cabo_counter
description: "Mobile app for the card game Cabo" description: "Mobile app for the card game Cabo"
publish_to: 'none' publish_to: 'none'
version: 0.1.5+113 version: 0.1.6+122
environment: environment:
sdk: ^3.5.4 sdk: ^3.5.4