@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
4
4
import 'package:flutter_riverpod/flutter_riverpod.dart' ;
5
5
import 'package:intl/intl.dart' ;
6
6
import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart' ;
7
+ import 'package:lichess_mobile/src/model/auth/auth_session.dart' ;
7
8
import 'package:lichess_mobile/src/model/common/id.dart' ;
8
9
import 'package:lichess_mobile/src/model/game/archived_game.dart' ;
9
10
import 'package:lichess_mobile/src/model/game/game.dart' ;
@@ -44,8 +45,15 @@ class ArchivedGameScreen extends ConsumerWidget {
44
45
45
46
@override
46
47
Widget build (BuildContext context, WidgetRef ref) {
48
+ final isLoggedIn = ref.watch (authSessionProvider) != null ;
49
+
47
50
if (gameData != null ) {
48
- return _Body (gameData: gameData, orientation: orientation, initialCursor: initialCursor);
51
+ return _Body (
52
+ gameData: gameData,
53
+ orientation: orientation,
54
+ isLoggedIn: isLoggedIn,
55
+ initialCursor: initialCursor,
56
+ );
49
57
} else {
50
58
return _LoadGame (gameId: gameId! , orientation: orientation, initialCursor: initialCursor);
51
59
}
@@ -62,25 +70,40 @@ class _LoadGame extends ConsumerWidget {
62
70
@override
63
71
Widget build (BuildContext context, WidgetRef ref) {
64
72
final game = ref.watch (archivedGameProvider (id: gameId));
73
+ final isLoggedIn = ref.watch (authSessionProvider) != null ;
74
+
65
75
return game.when (
66
76
data: (game) {
67
- return _Body (gameData: game.data, orientation: orientation, initialCursor: initialCursor);
77
+ return _Body (
78
+ gameData: game.data,
79
+ orientation: orientation,
80
+ isLoggedIn: isLoggedIn,
81
+ initialCursor: initialCursor,
82
+ );
68
83
},
69
- loading: () => _Body (gameData: null , orientation: orientation, initialCursor: initialCursor),
84
+ loading:
85
+ () => _Body (
86
+ gameData: null ,
87
+ orientation: orientation,
88
+ isLoggedIn: isLoggedIn,
89
+ initialCursor: initialCursor,
90
+ ),
70
91
error: (error, stackTrace) {
71
92
debugPrint ('SEVERE: [ArchivedGameScreen] could not load game; $error \n $stackTrace ' );
72
93
switch (error) {
73
94
case ServerException _ when error.statusCode == 404 :
74
95
return _Body (
75
96
gameData: null ,
76
97
orientation: orientation,
98
+ isLoggedIn: isLoggedIn,
77
99
initialCursor: initialCursor,
78
100
error: 'Game not found.' ,
79
101
);
80
102
default :
81
103
return _Body (
82
104
gameData: null ,
83
105
orientation: orientation,
106
+ isLoggedIn: isLoggedIn,
84
107
initialCursor: initialCursor,
85
108
error: error,
86
109
);
@@ -91,10 +114,17 @@ class _LoadGame extends ConsumerWidget {
91
114
}
92
115
93
116
class _Body extends StatelessWidget {
94
- const _Body ({required this .gameData, required this .orientation, this .initialCursor, this .error});
117
+ const _Body ({
118
+ required this .gameData,
119
+ required this .orientation,
120
+ required this .isLoggedIn,
121
+ this .initialCursor,
122
+ this .error,
123
+ });
95
124
96
125
final LightArchivedGame ? gameData;
97
126
final Object ? error;
127
+ final bool isLoggedIn;
98
128
final Side orientation;
99
129
final int ? initialCursor;
100
130
@@ -105,7 +135,7 @@ class _Body extends StatelessWidget {
105
135
title: gameData != null ? _GameTitle (gameData: gameData! ) : const SizedBox .shrink (),
106
136
actions: [
107
137
if (gameData == null && error == null ) const PlatformAppBarLoadingIndicator (),
108
- if (gameData != null ) BookmarkButton (id: gameData! .id),
138
+ if (gameData != null && isLoggedIn ) BookmarkButton (id: gameData! .id),
109
139
const ToggleSoundButton (),
110
140
],
111
141
),
0 commit comments