Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/src/view/analysis/analysis_layout.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:dartchess/dartchess.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/l10n/l10n.dart';
import 'package:lichess_mobile/src/constants.dart';
Expand Down Expand Up @@ -121,6 +122,7 @@ class AnalysisLayout extends StatelessWidget {
this.tabController,
required this.boardBuilder,
required this.children,
required this.pov,
this.boardHeader,
this.boardFooter,
this.engineGaugeBuilder,
Expand All @@ -135,6 +137,9 @@ class AnalysisLayout extends StatelessWidget {
/// The builder for the board widget.
final BoardBuilder boardBuilder;

/// The side the board is displayed from.
final Side pov;

/// A widget to show above the board.
///
/// The widget will included in a parent container with a height of
Expand Down Expand Up @@ -201,6 +206,8 @@ class AnalysisLayout extends StatelessWidget {
children: [
if (boardHeader != null)
Container(
// This key is used to preserve the state of the board header when the pov changes
key: ValueKey(pov.opposite),
decoration: BoxDecoration(
borderRadius:
isTablet
Expand All @@ -226,6 +233,8 @@ class AnalysisLayout extends StatelessWidget {
),
if (boardFooter != null)
Container(
// This key is used to preserve the state of the board footer when the pov changes
key: ValueKey(pov),
decoration: BoxDecoration(
borderRadius:
isTablet
Expand Down Expand Up @@ -291,7 +300,9 @@ class AnalysisLayout extends StatelessWidget {
child: Column(
children: [
if (boardHeader != null)
// This key is used to preserve the state of the board header when the pov changes
Container(
key: ValueKey(pov.opposite),
decoration: BoxDecoration(
borderRadius:
isTablet
Expand All @@ -314,6 +325,8 @@ class AnalysisLayout extends StatelessWidget {
),
if (boardFooter != null)
Container(
// This key is used to preserve the state of the board footer when the pov changes
key: ValueKey(pov),
decoration: BoxDecoration(
borderRadius:
isTablet
Expand Down
2 changes: 2 additions & 0 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ class _Body extends ConsumerWidget {
final isEngineAvailable = analysisState.isEngineAvailable;
final hasEval = analysisState.hasAvailableEval;
final currentNode = analysisState.currentNode;
final pov = analysisState.pov;

return AnalysisLayout(
tabController: controller,
pov: pov,
boardBuilder:
(context, boardSize, borderRadius) => AnalysisBoard(
options,
Expand Down
7 changes: 2 additions & 5 deletions lib/src/view/broadcast/broadcast_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,21 @@ class _Body extends ConsumerWidget {
final engineGaugeParams = state.engineGaugeParams;
final isLocalEvaluationEnabled = state.isLocalEvaluationEnabled;
final currentNode = state.currentNode;
final pov = state.pov;

return AnalysisLayout(
pov: pov,
tabController: tabController,
boardBuilder:
(context, boardSize, borderRadius) =>
_BroadcastBoard(roundId, gameId, boardSize, borderRadius),
boardHeader: _PlayerWidget(
// We need to use a key to preserve the state of the clock when board is flipped
key: const ValueKey('top'),
tournamentId: tournamentId,
roundId: roundId,
gameId: gameId,
widgetPosition: _PlayerWidgetPosition.top,
),
boardFooter: _PlayerWidget(
// We need to use a key to preserve the state of the clock when board is flipped
key: const ValueKey('bottom'),
tournamentId: tournamentId,
roundId: roundId,
gameId: gameId,
Expand Down Expand Up @@ -383,7 +381,6 @@ enum _PlayerWidgetPosition { bottom, top }

class _PlayerWidget extends ConsumerWidget {
const _PlayerWidget({
required super.key,
required this.tournamentId,
required this.roundId,
required this.gameId,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/view/study/study_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class _StudyScreenLoader extends ConsumerWidget {
body: DefaultTabController(
length: 1,
child: AnalysisLayout(
pov: Side.white,
boardBuilder:
(context, boardSize, borderRadius) => Chessboard.fixed(
size: boardSize,
Expand Down Expand Up @@ -108,6 +109,7 @@ class _StudyScreenLoader extends ConsumerWidget {
body: DefaultTabController(
length: 1,
child: AnalysisLayout(
pov: Side.white,
boardBuilder:
(context, boardSize, borderRadius) => Chessboard.fixed(
size: boardSize,
Expand Down Expand Up @@ -369,6 +371,7 @@ class _Body extends ConsumerWidget {
return DefaultTabController(
length: 1,
child: AnalysisLayout(
pov: Side.white,
boardBuilder:
(context, boardSize, borderRadius) => SizedBox.square(
dimension: boardSize,
Expand All @@ -388,11 +391,13 @@ class _Body extends ConsumerWidget {
final isComputerAnalysisAllowed = studyState.isComputerAnalysisAllowed;
final isLocalEvaluationEnabled = studyState.isLocalEvaluationEnabled;
final currentNode = studyState.currentNode;
final pov = studyState.pov;

final bottomChild = gamebookActive ? StudyGamebook(id) : StudyTreeView(id);

return AnalysisLayout(
tabController: tabController,
pov: pov,
boardBuilder:
(context, boardSize, borderRadius) =>
_StudyBoard(id: id, boardSize: boardSize, borderRadius: borderRadius),
Expand Down
2 changes: 2 additions & 0 deletions test/view/analysis/analysis_layout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() {
home: DefaultTabController(
length: 1,
child: AnalysisLayout(
pov: Side.white,
boardBuilder: (context, boardSize, boardRadius) {
return Chessboard.fixed(
size: boardSize,
Expand Down Expand Up @@ -69,6 +70,7 @@ void main() {
home: DefaultTabController(
length: 1,
child: AnalysisLayout(
pov: Side.white,
boardBuilder: (context, boardSize, boardRadius) {
return Chessboard.fixed(
size: boardSize,
Expand Down