Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp puzzle tab #1071

Merged
merged 5 commits into from
Oct 7, 2024
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
2 changes: 2 additions & 0 deletions lib/src/model/puzzle/puzzle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class PuzzleData with _$PuzzleData {
required ISet<String> themes,
}) = _PuzzleData;

Side get sideToMove => initialPly.isEven ? Side.black : Side.white;

factory PuzzleData.fromJson(Map<String, dynamic> json) =>
_$PuzzleDataFromJson(json);
}
Expand Down
58 changes: 58 additions & 0 deletions lib/src/utils/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,61 @@ Future<bool> isOnline(Client client) {
}
return completer.future;
}

extension AsyncValueConnectivity on AsyncValue<ConnectivityStatus> {
/// Switches between device's connectivity status.
///
/// Using this method assumes the the device is offline when the status is
/// not yet available (i.e. [AsyncValue.isLoading].
/// If you want to handle the loading state separately, use
/// [whenIsLoading] instead.
///
/// This method is similar to [AsyncValueX.maybeWhen], but it takes two
/// functions, one for when the device is online and another for when it is
/// offline.
///
/// Example:
/// ```dart
/// final status = ref.watch(connectivityChangesProvider);
/// final result = status.whenIs(
/// online: () => 'Online',
/// offline: () => 'Offline',
/// );
/// ```
R whenIs<R>({
required R Function() online,
required R Function() offline,
}) {
return maybeWhen(
data: (status) => status.isOnline ? online() : offline(),
orElse: offline,
);
}

/// Switches between device's connectivity status, but handling the loading state.
///
/// This method is similar to [AsyncValueX.when], but it takes three
/// functions, one for when the device is online, another for when it is
/// offline, and the last for when the status is still loading.
///
/// Example:
/// ```dart
/// final status = ref.watch(connectivityChangesProvider);
/// final result = status.whenIsLoading(
/// online: () => 'Online',
/// offline: () => 'Offline',
/// loading: () => 'Loading',
/// );
/// ```
R whenIsLoading<R>({
required R Function() online,
required R Function() offline,
required R Function() loading,
}) {
return when(
data: (status) => status.isOnline ? online() : offline(),
loading: loading,
error: (error, stack) => offline(),
);
}
}
2 changes: 2 additions & 0 deletions lib/src/view/puzzle/puzzle_history_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'package:timeago/timeago.dart' as timeago;
final _dateFormatter = DateFormat.yMMMd();

class PuzzleHistoryScreen extends StatelessWidget {
const PuzzleHistoryScreen();

@override
Widget build(BuildContext context) {
return PlatformScaffold(
Expand Down
Loading