Skip to content

Commit

Permalink
Merge pull request #974 from lichess-org/fix_ios_crash
Browse files Browse the repository at this point in the history
Fix ios crash
  • Loading branch information
veloce authored Sep 5, 2024
2 parents 3c34db0 + f4b9855 commit a49ac1d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 38 deletions.
45 changes: 15 additions & 30 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class AnalysisScreen extends StatelessWidget {
const AnalysisScreen({
required this.options,
required this.pgnOrId,
this.title,
});

/// The analysis options.
Expand All @@ -61,26 +60,22 @@ class AnalysisScreen extends StatelessWidget {
/// The PGN or game ID to load.
final String pgnOrId;

final String? title;

@override
Widget build(BuildContext context) {
return pgnOrId.length == 8 && GameId(pgnOrId).isValid
? _LoadGame(GameId(pgnOrId), options, title)
? _LoadGame(GameId(pgnOrId), options)
: _LoadedAnalysisScreen(
options: options,
pgn: pgnOrId,
title: title,
);
}
}

class _LoadGame extends ConsumerWidget {
const _LoadGame(this.gameId, this.options, this.title);
const _LoadGame(this.gameId, this.options);

final AnalysisOptions options;
final GameId gameId;
final String? title;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -100,7 +95,6 @@ class _LoadGame extends ConsumerWidget {
serverAnalysis: serverAnalysis,
),
pgn: game.makePgn(),
title: title,
);
},
loading: () => const Center(child: CircularProgressIndicator.adaptive()),
Expand All @@ -117,14 +111,11 @@ class _LoadedAnalysisScreen extends ConsumerWidget {
const _LoadedAnalysisScreen({
required this.options,
required this.pgn,
this.title,
});

final AnalysisOptions options;
final String pgn;

final String? title;

@override
Widget build(BuildContext context, WidgetRef ref) {
return ConsumerPlatformWidget(
Expand All @@ -140,7 +131,7 @@ class _LoadedAnalysisScreen extends ConsumerWidget {
return PlatformScaffold(
resizeToAvoidBottomInset: false,
appBar: PlatformAppBar(
title: _Title(options: options, title: title),
title: _Title(options: options),
actions: [
_EngineDepth(ctrlProvider),
AppBarIconButton(
Expand All @@ -167,7 +158,7 @@ class _LoadedAnalysisScreen extends ConsumerWidget {
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar(
padding: Styles.cupertinoAppBarTrailingWidgetPadding,
middle: _Title(options: options, title: title),
middle: _Title(options: options),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -192,27 +183,21 @@ class _LoadedAnalysisScreen extends ConsumerWidget {
}

class _Title extends StatelessWidget {
const _Title({
required this.options,
this.title,
});
const _Title({required this.options});
final AnalysisOptions options;
final String? title;

@override
Widget build(BuildContext context) {
return title != null
? Text(title!)
: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (options.variant != Variant.standard) ...[
Icon(options.variant.icon),
const SizedBox(width: 5.0),
],
Text(context.l10n.analysis),
],
);
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (options.variant != Variant.standard) ...[
Icon(options.variant.icon),
const SizedBox(width: 5.0),
],
Text(context.l10n.analysis),
],
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ class _BodyState extends ConsumerState<_Body> {
id: game.id,
division: game.meta.division,
),
title: context.l10n.analysis,
),
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/src/view/game/archived_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ class _BottomBar extends ConsumerWidget {
pushPlatformRoute(
context,
builder: (context) => AnalysisScreen(
title: context.l10n.gameAnalysis,
pgnOrId: game.makePgn(),
options: AnalysisOptions(
isLocalEvaluationAllowed: true,
Expand Down
2 changes: 0 additions & 2 deletions lib/src/view/game/game_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ class _GameBottomBar extends ConsumerWidget {
builder: (_) => AnalysisScreen(
pgnOrId: gameState.analysisPgn,
options: gameState.analysisOptions,
title: context.l10n.gameAnalysis,
),
);
},
Expand Down Expand Up @@ -688,7 +687,6 @@ class _GameBottomBar extends ConsumerWidget {
options: gameState.analysisOptions.copyWith(
isLocalEvaluationAllowed: false,
),
title: context.l10n.analysis,
),
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/src/view/game/game_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ class _ContextMenu extends ConsumerWidget {
pushPlatformRoute(
context,
builder: (context) => AnalysisScreen(
title: context.l10n.gameAnalysis,
pgnOrId: game.id.value,
options: AnalysisOptions(
isLocalEvaluationAllowed: true,
Expand Down
1 change: 0 additions & 1 deletion lib/src/view/game/game_result_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class _GameEndDialogState extends ConsumerState<GameResultDialog> {
builder: (_) => AnalysisScreen(
pgnOrId: gameState.analysisPgn,
options: gameState.analysisOptions,
title: context.l10n.gameAnalysis,
),
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/src/view/puzzle/puzzle_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ class _BottomBar extends ConsumerWidget {
pushPlatformRoute(
context,
builder: (context) => AnalysisScreen(
title: context.l10n.analysis,
pgnOrId: ref.read(ctrlProvider.notifier).makePgn(),
options: AnalysisOptions(
isLocalEvaluationAllowed: true,
Expand Down
1 change: 0 additions & 1 deletion lib/src/view/puzzle/streak_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ class _BottomBar extends ConsumerWidget {
pushPlatformRoute(
context,
builder: (context) => AnalysisScreen(
title: context.l10n.analysis,
pgnOrId: ref.read(ctrlProvider.notifier).makePgn(),
options: AnalysisOptions(
isLocalEvaluationAllowed: true,
Expand Down

0 comments on commit a49ac1d

Please sign in to comment.