73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import '../features/sharing/presentation/share_receiver.dart';
|
|
import 'package:cupertino_ui/cupertino_ui.dart';
|
|
import 'package:flutter/gestures.dart' show PointerDeviceKind;
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:material_ui/material_ui.dart' as material;
|
|
|
|
import '../l10n/app_localizations.dart';
|
|
import '../core/storage/token_storage.dart';
|
|
import 'theme/app_theme.dart';
|
|
import 'theme/dark_mode.dart';
|
|
|
|
/// 应用根组件。
|
|
///
|
|
/// 使用 CupertinoApp.router 接入 GoRouter,并在 [ProviderScope] 内运行。
|
|
class App extends StatelessWidget {
|
|
const App({super.key, required this.router});
|
|
|
|
final GoRouter router;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoApp.router(
|
|
title: '同同家庭关怀',
|
|
theme: AppTheme.cupertinoTheme,
|
|
routerConfig: router,
|
|
scrollBehavior: const CupertinoScrollBehavior().copyWith(
|
|
dragDevices: {
|
|
...const CupertinoScrollBehavior().dragDevices,
|
|
PointerDeviceKind.mouse,
|
|
},
|
|
),
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
...material.GlobalMaterialLocalizations.delegates,
|
|
],
|
|
builder: (context, child) {
|
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
|
value: DarkMode.systemBars(context),
|
|
child: material.Theme(
|
|
data: material.ThemeData(
|
|
colorScheme: material.ColorScheme.fromSeed(
|
|
seedColor: AppTheme.primary,
|
|
brightness: CupertinoTheme.brightnessOf(context),
|
|
),
|
|
),
|
|
// easy_image_viewer 仍使用 SDK Material 的主题和本地化。
|
|
// ignore: deprecated_member_use
|
|
child: material.MaterialUiCompatibilityBridge(child: child!),
|
|
),
|
|
);
|
|
},
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
debugShowCheckedModeBanner: false,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 便于在 main 中统一构建 ProviderScope + App。
|
|
Widget buildApp(GoRouter router) {
|
|
return ShareReceiver(
|
|
router: router,
|
|
child: ValueListenableBuilder<int>(
|
|
valueListenable: TokenStorage.sessionChanges,
|
|
builder: (context, version, _) => ProviderScope(
|
|
key: ValueKey(version),
|
|
child: App(router: router),
|
|
),
|
|
),
|
|
);
|
|
}
|