Surface/lib/main.dart

89 lines
2.8 KiB
Dart
Raw Normal View History

2024-11-09 17:04:39 +00:00
import 'package:croppy/croppy.dart';
2024-11-08 16:09:46 +00:00
import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization_loader/easy_localization_loader.dart';
2024-11-10 14:56:18 +00:00
import 'package:flutter/foundation.dart';
2024-11-08 16:09:46 +00:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
2024-11-09 03:16:14 +00:00
import 'package:relative_time/relative_time.dart';
2024-11-08 16:09:46 +00:00
import 'package:responsive_framework/responsive_framework.dart';
2024-11-13 16:08:09 +00:00
import 'package:surface/providers/navigation.dart';
2024-11-09 04:04:03 +00:00
import 'package:surface/providers/sn_attachment.dart';
2024-11-08 16:09:46 +00:00
import 'package:surface/providers/sn_network.dart';
import 'package:surface/providers/theme.dart';
import 'package:surface/providers/userinfo.dart';
2024-11-14 16:24:46 +00:00
import 'package:surface/providers/websocket.dart';
2024-11-08 16:09:46 +00:00
import 'package:surface/router.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
2024-11-10 14:56:18 +00:00
if (!kReleaseMode) {
debugInvertOversizedImages = true;
}
2024-11-08 16:09:46 +00:00
runApp(const SolianApp());
}
class SolianApp extends StatelessWidget {
const SolianApp({super.key});
@override
Widget build(BuildContext context) {
return ResponsiveBreakpoints.builder(
child: EasyLocalization(
path: 'assets/translations',
supportedLocales: [Locale('en', 'US'), Locale('zh', 'CN')],
fallbackLocale: Locale('en', 'US'),
useFallbackTranslations: true,
useOnlyLangCode: true,
2024-11-08 16:09:46 +00:00
assetLoader: JsonAssetLoader(),
child: MultiProvider(
providers: [
2024-11-14 16:24:46 +00:00
// Display layer
ChangeNotifierProvider(create: (_) => ThemeProvider()),
ChangeNotifierProvider(create: (ctx) => NavigationProvider()),
// Data layer
2024-11-08 16:09:46 +00:00
Provider(create: (_) => SnNetworkProvider()),
2024-11-09 04:04:03 +00:00
Provider(create: (ctx) => SnAttachmentProvider(ctx)),
2024-11-09 10:28:45 +00:00
ChangeNotifierProvider(create: (ctx) => UserProvider(ctx)),
2024-11-14 16:24:46 +00:00
ChangeNotifierProvider(create: (ctx) => WebSocketProvider(ctx)),
2024-11-08 16:09:46 +00:00
],
child: AppMainContent(),
2024-11-08 16:09:46 +00:00
),
),
breakpoints: [
const Breakpoint(start: 0, end: 450, name: MOBILE),
const Breakpoint(start: 451, end: 800, name: TABLET),
const Breakpoint(start: 801, end: 1920, name: DESKTOP),
],
);
}
}
class AppMainContent extends StatelessWidget {
const AppMainContent({super.key});
@override
Widget build(BuildContext context) {
2024-11-13 16:08:09 +00:00
context.read<NavigationProvider>();
2024-11-14 16:24:46 +00:00
context.read<WebSocketProvider>();
final th = context.watch<ThemeProvider>();
return MaterialApp.router(
theme: th.theme?.light,
darkTheme: th.theme?.dark,
locale: context.locale,
supportedLocales: context.supportedLocales,
localizationsDelegates: [
CroppyLocalizations.delegate,
RelativeTimeLocalizations.delegate,
...context.localizationDelegates,
],
routerConfig: appRouter,
);
}
}