Skip to content

Commit

Permalink
Fix create game section not shown when offline on tablets
Browse files Browse the repository at this point in the history
Closes #1248
  • Loading branch information
veloce committed Dec 10, 2024
1 parent 7978160 commit 262dc97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
9 changes: 4 additions & 5 deletions lib/src/view/home/home_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,9 @@ class _HomeScreenState extends ConsumerState<HomeTabScreen> with RouteAware {
if (isTablet)
Row(
children: [
if (status.isOnline)
const Flexible(
child: _TabletCreateAGameSection(),
),
const Flexible(
child: _TabletCreateAGameSection(),
),
Flexible(
child: Column(
children: welcomeWidgets,
Expand Down Expand Up @@ -361,7 +360,7 @@ class _HomeScreenState extends ConsumerState<HomeTabScreen> with RouteAware {
child: Column(
children: [
const SizedBox(height: 8.0),
if (status.isOnline) const _TabletCreateAGameSection(),
const _TabletCreateAGameSection(),
if (status.isOnline)
_OngoingGamesPreview(
ongoingGames,
Expand Down
68 changes: 39 additions & 29 deletions lib/src/view/play/quick_game_matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:lichess_mobile/src/model/auth/auth_session.dart';
import 'package:lichess_mobile/src/model/common/speed.dart';
import 'package:lichess_mobile/src/model/common/time_increment.dart';
import 'package:lichess_mobile/src/model/lobby/game_seek.dart';
import 'package:lichess_mobile/src/network/connectivity.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
Expand Down Expand Up @@ -85,6 +86,8 @@ class _SectionChoices extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final session = ref.watch(authSessionProvider);
final isOnline =
ref.watch(connectivityChangesProvider).valueOrNull?.isOnline ?? false;
final choiceWidgets = choices
.mapIndexed((index, choice) {
return [
Expand All @@ -99,15 +102,17 @@ class _SectionChoices extends ConsumerWidget {
),
),
speed: choice.speed,
onSelected: (bool selected) {
pushPlatformRoute(
context,
rootNavigator: true,
builder: (_) => GameScreen(
seek: GameSeek.fastPairing(choice, session),
),
);
},
onTap: isOnline
? () {
pushPlatformRoute(
context,
rootNavigator: true,
builder: (_) => GameScreen(
seek: GameSeek.fastPairing(choice, session),
),
);
}
: null,
),
),
if (index < choices.length - 1)
Expand All @@ -127,12 +132,14 @@ class _SectionChoices extends ConsumerWidget {
Expanded(
child: _ChoiceChip(
label: Text(context.l10n.custom),
onSelected: (bool selected) {
pushPlatformRoute(
context,
builder: (_) => const CreateCustomGameScreen(),
);
},
onTap: isOnline
? () {
pushPlatformRoute(
context,
builder: (_) => const CreateCustomGameScreen(),
);
}
: null,
),
),
],
Expand All @@ -146,13 +153,13 @@ class _ChoiceChip extends StatefulWidget {
const _ChoiceChip({
required this.label,
this.speed,
required this.onSelected,
required this.onTap,
super.key,
});

final Widget label;
final Speed? speed;
final void Function(bool selected) onSelected;
final void Function()? onTap;

@override
State<_ChoiceChip> createState() => _ChoiceChipState();
Expand All @@ -165,18 +172,21 @@ class _ChoiceChipState extends State<_ChoiceChip> {
? Styles.cupertinoCardColor.resolveFrom(context).withValues(alpha: 0.7)
: Theme.of(context).colorScheme.surfaceContainer.withValues(alpha: 0.7);

return Container(
decoration: BoxDecoration(
color: cardColor,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
),
child: AdaptiveInkWell(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
onTap: () => widget.onSelected(true),
splashColor: Theme.of(context).primaryColor.withValues(alpha: 0.2),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Center(child: widget.label),
return Opacity(
opacity: widget.onTap != null ? 1.0 : 0.5,
child: Container(
decoration: BoxDecoration(
color: cardColor,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
),
child: AdaptiveInkWell(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
onTap: widget.onTap,
splashColor: Theme.of(context).primaryColor.withValues(alpha: 0.2),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Center(child: widget.label),
),
),
),
);
Expand Down

0 comments on commit 262dc97

Please sign in to comment.