fix: fix usage of wrong context for multiplayer battle
This commit is contained in:
parent
c290c268e8
commit
58e79147c7
5 changed files with 29 additions and 19 deletions
|
|
@ -42,6 +42,7 @@ class ErrorHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void showErrorSnackBar(BuildContext context, Object error) {
|
static void showErrorSnackBar(BuildContext context, Object error) {
|
||||||
|
if (!context.mounted) return;
|
||||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
scaffoldMessenger.hideCurrentSnackBar();
|
scaffoldMessenger.hideCurrentSnackBar();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,19 +286,19 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (dialogContext) => AlertDialog(
|
||||||
title: Text(title, style: const TextStyle(color: AppTheme.errorColor)),
|
title: Text(title, style: const TextStyle(color: AppTheme.errorColor)),
|
||||||
content: Text(content),
|
content: Text(content),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(dialogContext),
|
||||||
child: Text(l10n.commonCancel),
|
child: Text(l10n.commonCancel),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style:
|
style:
|
||||||
ElevatedButton.styleFrom(backgroundColor: AppTheme.errorColor),
|
ElevatedButton.styleFrom(backgroundColor: AppTheme.errorColor),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(dialogContext);
|
||||||
onConfirm();
|
onConfirm();
|
||||||
},
|
},
|
||||||
child: Text(l10n.commonConfirm),
|
child: Text(l10n.commonConfirm),
|
||||||
|
|
|
||||||
|
|
@ -253,13 +253,13 @@ class _HubScreenState extends ConsumerState<HubScreen> {
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (dialogContext) => AlertDialog(
|
||||||
title: Text(l10n.multiplayerTitle),
|
title: Text(l10n.multiplayerTitle),
|
||||||
content: Text(l10n.multiplayerDescription),
|
content: Text(l10n.multiplayerDescription),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(dialogContext);
|
||||||
_showJoinCodeDialog();
|
_showJoinCodeDialog();
|
||||||
},
|
},
|
||||||
child: Text(l10n.multiplayerJoinButton),
|
child: Text(l10n.multiplayerJoinButton),
|
||||||
|
|
@ -268,14 +268,14 @@ class _HubScreenState extends ConsumerState<HubScreen> {
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: AppTheme.primaryColor),
|
backgroundColor: AppTheme.primaryColor),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.pop(context);
|
Navigator.pop(dialogContext);
|
||||||
try {
|
try {
|
||||||
final party =
|
final party =
|
||||||
await ref.read(partyRepositoryProvider).createParty();
|
await ref.read(partyRepositoryProvider).createParty();
|
||||||
if (mounted) context.go('/lobby/${party.id}');
|
if (mounted) context.go('/lobby/${party.id}');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
if (mounted) ErrorHandler.showErrorSnackBar(context, e);
|
ErrorHandler.showErrorSnackBar(context, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -293,7 +293,7 @@ class _HubScreenState extends ConsumerState<HubScreen> {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (dialogContext) => AlertDialog(
|
||||||
title: Text(l10n.multiplayerEnterCodeTitle),
|
title: Text(l10n.multiplayerEnterCodeTitle),
|
||||||
content: TextField(
|
content: TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
|
@ -305,21 +305,21 @@ class _HubScreenState extends ConsumerState<HubScreen> {
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(dialogContext),
|
||||||
child: Text(l10n.multiplayerCancelAction),
|
child: Text(l10n.multiplayerCancelAction),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final code = controller.text.trim().toUpperCase();
|
final code = controller.text.trim().toUpperCase();
|
||||||
if (code.isNotEmpty) {
|
if (code.isNotEmpty) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(dialogContext);
|
||||||
try {
|
try {
|
||||||
final party =
|
final party =
|
||||||
await ref.read(partyRepositoryProvider).joinParty(code);
|
await ref.read(partyRepositoryProvider).joinParty(code);
|
||||||
if (mounted) context.go('/lobby/${party.id}');
|
if (mounted) context.go('/lobby/${party.id}');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
if (mounted) ErrorHandler.showErrorSnackBar(context, e);
|
ErrorHandler.showErrorSnackBar(context, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,11 @@ class PartyRepository {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onCancel: () async {
|
onCancel: () async {
|
||||||
await unsubscribe?.call();
|
try {
|
||||||
|
await unsubscribe?.call();
|
||||||
|
} catch (e) {
|
||||||
|
log('Safe ignore: Unsubscribe error (likely already disconnected): $e');
|
||||||
|
}
|
||||||
log('🔌 Unsubscribed from party $partyId');
|
log('🔌 Unsubscribed from party $partyId');
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -120,7 +124,11 @@ class PartyRepository {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onCancel: () async {
|
onCancel: () async {
|
||||||
await unsubscribe?.call();
|
try {
|
||||||
|
await unsubscribe?.call();
|
||||||
|
} catch (e) {
|
||||||
|
log('Safe ignore: Unsubscribe error (likely already disconnected): $e');
|
||||||
|
}
|
||||||
log('🔌 Unsubscribed from party members $partyId');
|
log('🔌 Unsubscribed from party members $partyId');
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -141,11 +141,11 @@ class _BattleScreenState extends ConsumerState<BattleScreen> {
|
||||||
|
|
||||||
final controller = ref.read(battleControllerProvider.notifier);
|
final controller = ref.read(battleControllerProvider.notifier);
|
||||||
final battleState = ref.read(battleControllerProvider);
|
final battleState = ref.read(battleControllerProvider);
|
||||||
|
|
||||||
if (battleState.isResting) {
|
if (battleState.isResting) {
|
||||||
controller.tickRest();
|
controller.tickRest();
|
||||||
final newState = ref.read(battleControllerProvider);
|
final newState = ref.read(battleControllerProvider);
|
||||||
|
|
||||||
if (newState.isResting) {
|
if (newState.isResting) {
|
||||||
_runRestTimer();
|
_runRestTimer();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -254,7 +254,7 @@ class _BattleScreenState extends ConsumerState<BattleScreen> {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (context) => AlertDialog(
|
builder: (dialogContext) => AlertDialog(
|
||||||
title: Text(l10n.battleRaidComplete),
|
title: Text(l10n.battleRaidComplete),
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
|
@ -267,7 +267,7 @@ class _BattleScreenState extends ConsumerState<BattleScreen> {
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
'+$xpEarned XP',
|
'+$xpEarned XP',
|
||||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
style: Theme.of(dialogContext).textTheme.headlineMedium?.copyWith(
|
||||||
color: AppTheme.primaryColor,
|
color: AppTheme.primaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -276,7 +276,7 @@ class _BattleScreenState extends ConsumerState<BattleScreen> {
|
||||||
actions: [
|
actions: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
context.go('/hub');
|
context.go('/hub');
|
||||||
},
|
},
|
||||||
child: Text(l10n.battleBackToHub),
|
child: Text(l10n.battleBackToHub),
|
||||||
|
|
@ -1079,7 +1079,8 @@ class _BattleScreenState extends ConsumerState<BattleScreen> {
|
||||||
children: [
|
children: [
|
||||||
_InfoBox(
|
_InfoBox(
|
||||||
label: l10n.battleWeight,
|
label: l10n.battleWeight,
|
||||||
value: '${currentSet.targetWeightTotal} kg',
|
value:
|
||||||
|
'${currentSet.targetWeightTotal} ${l10n.unitKg}',
|
||||||
),
|
),
|
||||||
_InfoBox(
|
_InfoBox(
|
||||||
label: l10n.battleReps,
|
label: l10n.battleReps,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue