Fixed state update bug
This commit is contained in:
@@ -81,7 +81,7 @@ class _CreateGameState extends State<CreateGame> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ModeSelectionMenu(
|
||||
pointLimit: Globals.pointLimit,
|
||||
pointLimit: globals.pointLimit,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -285,13 +285,11 @@ class _CreateGameState extends State<CreateGame> {
|
||||
createdAt: DateTime.now(),
|
||||
gameTitle: _gameTitleTextController.text,
|
||||
players: players,
|
||||
pointLimit: Globals.pointLimit,
|
||||
caboPenalty: Globals.caboPenalty,
|
||||
pointLimit: globals.pointLimit,
|
||||
caboPenalty: globals.caboPenalty,
|
||||
isPointsLimitEnabled: selectedMode!,
|
||||
);
|
||||
setState(() {
|
||||
Globals.addGameSession(gameSession);
|
||||
});
|
||||
globals.addGameSession(gameSession);
|
||||
LocalStorageService.saveGameSessions();
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacement(
|
||||
|
||||
@@ -26,6 +26,11 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
_isLoading = false;
|
||||
});
|
||||
});
|
||||
globals.addListener(_updateView);
|
||||
}
|
||||
|
||||
void _updateView() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -33,132 +38,143 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
print('MainMenuView build');
|
||||
LocalStorageService.loadGameSessions();
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const SettingsView(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(CupertinoIcons.settings, size: 30)),
|
||||
middle: const Text('Cabo Counter'),
|
||||
trailing: IconButton(
|
||||
onPressed: () => {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const CreateGame(),
|
||||
),
|
||||
)
|
||||
},
|
||||
icon: const Icon(CupertinoIcons.add)),
|
||||
),
|
||||
child: CupertinoPageScaffold(
|
||||
child: SafeArea(
|
||||
child: _isLoading
|
||||
? const Center(child: CupertinoActivityIndicator())
|
||||
: Globals.gameList.isEmpty
|
||||
? Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center, // Oben ausrichten
|
||||
children: [
|
||||
const SizedBox(height: 30), // Abstand von oben
|
||||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() {}),
|
||||
child: Icon(
|
||||
CupertinoIcons.plus,
|
||||
size: 60,
|
||||
color: CustomTheme.primaryColor,
|
||||
return ListenableBuilder(
|
||||
listenable: globals,
|
||||
builder: (context, _) {
|
||||
return CupertinoPageScaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const SettingsView(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(CupertinoIcons.settings, size: 30)),
|
||||
middle: const Text('Cabo Counter'),
|
||||
trailing: IconButton(
|
||||
onPressed: () => {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const CreateGame(),
|
||||
),
|
||||
)),
|
||||
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 Dismissible(
|
||||
key: Key(session.gameTitle),
|
||||
background: Container(
|
||||
color: CupertinoColors.destructiveRed,
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.only(left: 20.0),
|
||||
child: const Icon(
|
||||
CupertinoIcons.delete,
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
),
|
||||
direction: DismissDirection.startToEnd,
|
||||
confirmDismiss: (direction) async {
|
||||
final String gameTitle =
|
||||
Globals.gameList[index].gameTitle;
|
||||
return await _showDeleteGamePopup(gameTitle);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
_deleteSpecificGame(index);
|
||||
},
|
||||
dismissThresholds: const {
|
||||
DismissDirection.startToEnd: 0.6
|
||||
},
|
||||
child: 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
|
||||
final val = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ActiveGameView(
|
||||
gameSession: Globals.gameList[index]),
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
)
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
icon: const Icon(CupertinoIcons.add)),
|
||||
),
|
||||
child: CupertinoPageScaffold(
|
||||
child: SafeArea(
|
||||
child: _isLoading
|
||||
? const Center(child: CupertinoActivityIndicator())
|
||||
: globals.gameList.isEmpty
|
||||
? Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center, // Oben ausrichten
|
||||
children: [
|
||||
const SizedBox(height: 30), // Abstand von oben
|
||||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() {}),
|
||||
child: Icon(
|
||||
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 Dismissible(
|
||||
key: Key(session.gameTitle),
|
||||
background: Container(
|
||||
color: CupertinoColors.destructiveRed,
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.only(left: 20.0),
|
||||
child: const Icon(
|
||||
CupertinoIcons.delete,
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
),
|
||||
direction: DismissDirection.startToEnd,
|
||||
confirmDismiss: (direction) async {
|
||||
final String gameTitle =
|
||||
globals.gameList[index].gameTitle;
|
||||
return await _showDeleteGamePopup(gameTitle);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
_deleteSpecificGame(index);
|
||||
},
|
||||
dismissThresholds: const {
|
||||
DismissDirection.startToEnd: 0.6
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10.0),
|
||||
child: CupertinoListTile(
|
||||
backgroundColorActivated:
|
||||
CustomTheme.backgroundColor,
|
||||
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
|
||||
final val = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ActiveGameView(
|
||||
gameSession:
|
||||
globals.gameList[index]),
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Translates the game mode boolean into the corresponding String.
|
||||
@@ -204,7 +220,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
/// This function takes an [index] as parameter and removes the game session at
|
||||
/// that index from the global game list,
|
||||
void _deleteSpecificGame(int index) {
|
||||
Globals.gameList.removeAt(index);
|
||||
globals.gameList.removeAt(index);
|
||||
LocalStorageService.saveGameSessions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
subtitle: const Text('... für falsches Cabo sagen'),
|
||||
trailing: Stepper(
|
||||
key: _stepperKey1,
|
||||
initialValue: Globals.caboPenalty,
|
||||
initialValue: globals.caboPenalty,
|
||||
minValue: 0,
|
||||
maxValue: 50,
|
||||
step: 1,
|
||||
onChanged: (newCaboPenalty) {
|
||||
setState(() {
|
||||
ConfigService.setCaboPenalty(newCaboPenalty);
|
||||
Globals.caboPenalty = newCaboPenalty;
|
||||
globals.caboPenalty = newCaboPenalty;
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -70,14 +70,14 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
subtitle: const Text('... hier ist Schluss'),
|
||||
trailing: Stepper(
|
||||
key: _stepperKey2,
|
||||
initialValue: Globals.pointLimit,
|
||||
initialValue: globals.pointLimit,
|
||||
minValue: 30,
|
||||
maxValue: 1000,
|
||||
step: 10,
|
||||
onChanged: (newPointLimit) {
|
||||
setState(() {
|
||||
ConfigService.setPointLimit(newPointLimit);
|
||||
Globals.pointLimit = newPointLimit;
|
||||
globals.pointLimit = newPointLimit;
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -201,7 +201,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text(
|
||||
'${Globals.appDevPhase} ${snapshot.data!.version} '
|
||||
'${globals.appDevPhase} ${snapshot.data!.version} '
|
||||
'(Build ${snapshot.data!.buildNumber})',
|
||||
textAlign: TextAlign.center,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user