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

disable android refresh when no connectivity #226

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
disable android refresh when no connectivity
rool78 committed Jul 4, 2023
commit 716f176fb8b755a5dfe0f3b4fb2f678e3811f521
2 changes: 1 addition & 1 deletion lib/src/ui/watch/tv_screen.dart
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ class _Body extends ConsumerWidget {
interactableSide: cg.InteractableSide.none,
orientation: cg.Side.white,
),
errorMessage: 'Could not load TV stream.',
errorMessage: 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error?
);
},
),
14 changes: 12 additions & 2 deletions lib/src/ui/watch/watch_screen.dart
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ import 'package:lichess_mobile/src/widgets/shimmer.dart';
import 'package:lichess_mobile/src/ui/watch/streamer_screen.dart';
import 'package:lichess_mobile/src/ui/watch/tv_screen.dart';

import '../../utils/connectivity.dart';

final _featuredGameNoSoundProvider = featuredGameProvider(withSound: false);

class WatchScreen extends ConsumerStatefulWidget {
@@ -32,8 +34,15 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
with RouteAware, WidgetsBindingObserver {
final _androidRefreshKey = GlobalKey<RefreshIndicatorState>();

bool isNowOnline = true;

@override
Widget build(BuildContext context) {
ref.listen(connectivityChangesProvider, (_, connectivity) {
if (!connectivity.isRefreshing && connectivity.hasValue) {
isNowOnline = connectivity.value!.isOnline;
}
});
return ConsumerPlatformWidget(
ref: ref,
androidBuilder: _buildAndroid,
@@ -49,6 +58,7 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
body: RefreshIndicator(
key: _androidRefreshKey,
onRefresh: () => ref.refresh(liveStreamersProvider.future),
notificationPredicate: (_) => isNowOnline,
child: SafeArea(
child: OrientationBuilder(
builder: (context, orientation) {
@@ -84,7 +94,7 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
controller: watchScrollController,
slivers: [
const CupertinoSliverNavigationBar(),
CupertinoSliverRefreshControl(
CupertinoSliverRefreshControl( //TODO: Explore workaround to handle refresh on iOS.
onRefresh: () => ref.refresh(liveStreamersProvider.future),
),
SliverSafeArea(
@@ -193,7 +203,7 @@ class _WatchTvWidget extends ConsumerWidget {
header: Text('Lichess TV', style: Styles.sectionTitle),
orientation: Side.white,
fen: kEmptyFen,
errorMessage: 'Could not load Tv Stream',
errorMessage: 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error?
);
},
loading: () => BoardPreview(