Skip to content

Commit

Permalink
Don't open websocket in a tab navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Oct 10, 2023
1 parent 4a21c47 commit 4074099
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class _AppState extends ConsumerState<App> {
navigatorObservers: [
immersiveModeRouteObserver,
wakelockRouteObserver,
tvRouteObserver,
],
);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/src/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final puzzlesScrollController = ScrollController(debugLabel: 'PuzzlesScroll');
final watchScrollController = ScrollController(debugLabel: 'WatchScroll');
final profileScrollController = ScrollController(debugLabel: 'ProfileScroll');

final RouteObserver<PageRoute<void>> watchTabRouteObserver =
final RouteObserver<PageRoute<void>> tvRouteObserver =
RouteObserver<PageRoute<void>>();

final tabsProvider = Provider<List<_Tab>>((ref) {
Expand Down Expand Up @@ -201,7 +201,6 @@ class BottomNavScaffold extends ConsumerWidget {
case 2:
return _MaterialTabView(
navigatorKey: watchNavigatorKey,
navigatorObservers: [watchTabRouteObserver],
builder: (context) => const WatchTabScreen(),
);
case 3:
Expand Down Expand Up @@ -234,7 +233,6 @@ class BottomNavScaffold extends ConsumerWidget {
return CupertinoTabView(
defaultTitle: context.l10n.watch,
navigatorKey: watchNavigatorKey,
navigatorObservers: [watchTabRouteObserver],
builder: (context) => const WatchTabScreen(),
);
case 3:
Expand Down
10 changes: 4 additions & 6 deletions lib/src/view/watch/live_tv_channels_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class _TvChannelsScreenState extends ConsumerState<LiveTvChannelsScreen>
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (route != null && route is PageRoute) {
watchTabRouteObserver.subscribe(this, route);
tvRouteObserver.subscribe(this, route);
}
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
watchTabRouteObserver.unsubscribe(this);
tvRouteObserver.unsubscribe(this);
super.dispose();
}

Expand Down Expand Up @@ -109,10 +109,7 @@ class _Body extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final currentBottomTab = ref.watch(currentBottomTabProvider);
final gamesAsync = currentBottomTab == BottomTab.watch
? ref.watch(liveTvChannelsProvider)
: const AsyncLoading<LiveTvChannelsState>();
final gamesAsync = ref.watch(liveTvChannelsProvider);
return gamesAsync.when(
data: (games) {
final list = [
Expand All @@ -127,6 +124,7 @@ class _Body extends ConsumerWidget {
onTap: () {
pushPlatformRoute(
context,
rootNavigator: true,
builder: (_) => TvScreen(
channel: game.channel,
initialGame: (game.id, game.orientation),
Expand Down
9 changes: 3 additions & 6 deletions lib/src/view/watch/tv_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class _TvScreenState extends ConsumerState<TvScreen>
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (route != null && route is PageRoute) {
watchTabRouteObserver.subscribe(this, route);
tvRouteObserver.subscribe(this, route);
}
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
watchTabRouteObserver.unsubscribe(this);
tvRouteObserver.unsubscribe(this);
super.dispose();
}

Expand Down Expand Up @@ -143,10 +143,7 @@ class _Body extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final currentBottomTab = ref.watch(currentBottomTabProvider);
final asyncGame = currentBottomTab == BottomTab.watch
? ref.watch(tvControllerProvider(channel, initialGame))
: const AsyncLoading<TvState>();
final asyncGame = ref.watch(tvControllerProvider(channel, initialGame));

return SafeArea(
child: Center(
Expand Down
2 changes: 2 additions & 0 deletions lib/src/view/watch/watch_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class _WatchTvWidget extends ConsumerWidget {
headerTrailing: NoPaddingTextButton(
onPressed: () => pushPlatformRoute(
context,
rootNavigator: true,
builder: (context) => const LiveTvChannelsScreen(),
).then((_) => _refreshData(ref)),
child: Text(
Expand All @@ -208,6 +209,7 @@ class _WatchTvWidget extends ConsumerWidget {
),
onTap: () => pushPlatformRoute(
context,
rootNavigator: true,
builder: (context) => TvScreen(channel: snapshot.channel),
).then((_) => _refreshData(ref)),
);
Expand Down

0 comments on commit 4074099

Please sign in to comment.