import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'core/auth/auth_state.dart'; import 'core/router/app_router.dart'; import 'core/theme/app_theme.dart'; void main() { FlutterError.onError = (details) { FlutterError.presentError(details); debugPrint('═══ FlutterError ════════════════════════════'); debugPrint(details.exceptionAsString()); debugPrint(details.stack.toString()); }; runZonedGuarded( () => runApp(const ProviderScope(child: JiuApp())), (error, stack) { debugPrint('═══ Zone Error ═══════════════════════════════'); debugPrint(error.toString()); debugPrint(stack.toString()); }, ); } class JiuApp extends ConsumerWidget { const JiuApp({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { return MaterialApp( title: '酒库管理系统', theme: AppTheme.light(), debugShowCheckedModeBanner: false, home: const _AppBootstrap(), ); } } /// Restores persisted auth before handing off to the router. class _AppBootstrap extends ConsumerStatefulWidget { const _AppBootstrap(); @override ConsumerState<_AppBootstrap> createState() => _AppBootstrapState(); } class _AppBootstrapState extends ConsumerState<_AppBootstrap> { bool _ready = false; @override void initState() { super.initState(); _init(); } Future _init() async { await ref.read(authStateProvider.notifier).restore(); if (mounted) setState(() => _ready = true); } @override Widget build(BuildContext context) { if (!_ready) { return const Scaffold( body: Center(child: CircularProgressIndicator()), ); } return _RouterApp(); } } class _RouterApp extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final router = ref.watch(appRouterProvider); return MaterialApp.router( title: '酒库管理系统', theme: AppTheme.light(), routerConfig: router, debugShowCheckedModeBanner: false, builder: (context, child) => SelectionArea(child: child!), ); } }