diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-20 23:42:34 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-20 23:42:34 +0300 |
| commit | ef0c310211d180d57f060aca3802bfed0958d312 (patch) | |
| tree | 7c3fedd84931dcc97aa7b27206c3797f38c32325 /player-android/lib/main.dart | |
| parent | 1a68b1aead492b50d824bde99fb1f30e1360ed26 (diff) | |
Add go_router + Riverpod wiring and extract SOLID-clean screen/nav layers (na)
Introduces flutter_riverpod and go_router dependencies. Wires up the app
with a Riverpod-managed GoRouter, auth-guarded redirect logic, and a shared
navigator key used by DioClient for 401 → /login redirects.
SOLID fixes applied:
- navigatorKey extracted to navigation_key.dart (DIP: breaks cross-layer
import from router.dart into api_client_provider.dart)
- AppRoutes extracted to app_routes.dart (SRP + avoids circular import
when screen files reference route constants)
- LoginScreen, HomeScreen, MediaDetailScreen, ShareScreen each moved to
their own file under lib/screens/ (SRP: router.dart is routing-only)
- router.dart re-exports AppRoutes for backward-compatible callers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'player-android/lib/main.dart')
| -rw-r--r-- | player-android/lib/main.dart | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/player-android/lib/main.dart b/player-android/lib/main.dart index eed6e99..156b8f8 100644 --- a/player-android/lib/main.dart +++ b/player-android/lib/main.dart @@ -1,50 +1,27 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; -void main() => runApp(const PlayerAndroidApp()); +import 'router.dart'; -class PlayerAndroidApp extends StatelessWidget { - const PlayerAndroidApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Player', - initialRoute: '/', - routes: { - '/': (context) => const HomeScreen(), - '/now-playing': (context) => const NowPlayingScreen(), - }, - ); - } -} +/// Entry point — wraps the whole widget tree in a [ProviderScope] so every +/// widget and provider has access to the Riverpod container. +void main() => runApp(const ProviderScope(child: PlayerAndroidApp())); -// HomeScreen shows the media library. Placeholder until the library API is wired. -class HomeScreen extends StatelessWidget { - const HomeScreen({super.key}); +/// Root application widget. +/// +/// Uses [ConsumerWidget] to read [routerProvider] from Riverpod so that the +/// same [GoRouter] instance (and its navigator key) is reused across rebuilds. +/// [MaterialApp.router] delegates all navigation decisions to go_router. +class PlayerAndroidApp extends ConsumerWidget { + const PlayerAndroidApp({super.key}); @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text('Library')), - body: Center( - child: ElevatedButton( - onPressed: () => Navigator.pushNamed(context, '/now-playing'), - child: const Text('Now Playing'), - ), - ), - ); - } -} + Widget build(BuildContext context, WidgetRef ref) { + final router = ref.watch(routerProvider); -// NowPlayingScreen shows the active media item. Placeholder until playback is wired. -class NowPlayingScreen extends StatelessWidget { - const NowPlayingScreen({super.key}); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text('Now Playing')), - body: const Center(child: Text('No media selected')), + return MaterialApp.router( + title: 'Player', + routerConfig: router, ); } } |
