Surface/lib/main.dart

130 lines
4.6 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-20 16:18:11 +00:00
import 'package:firebase_core/firebase_core.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';
2024-11-23 16:22:08 +00:00
import 'package:go_router/go_router.dart';
2024-11-16 05:54:36 +00:00
import 'package:hive_flutter/hive_flutter.dart';
2024-11-08 16:09:46 +00:00
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';
import 'package:sentry_flutter/sentry_flutter.dart';
2024-11-20 16:18:11 +00:00
import 'package:surface/firebase_options.dart';
2024-11-16 13:15:55 +00:00
import 'package:surface/providers/channel.dart';
2024-11-24 12:23:06 +00:00
import 'package:surface/providers/chat_call.dart';
2024-11-13 16:08:09 +00:00
import 'package:surface/providers/navigation.dart';
import 'package:surface/providers/notification.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/user_directory.dart';
2024-11-08 16:09:46 +00:00
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';
2024-11-16 13:15:55 +00:00
import 'package:surface/types/chat.dart';
import 'package:surface/types/realm.dart';
2024-11-23 16:22:08 +00:00
import 'package:flutter_web_plugins/url_strategy.dart' show usePathUrlStrategy;
2024-11-08 16:09:46 +00:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
2024-11-16 05:54:36 +00:00
await Hive.initFlutter();
2024-11-16 13:15:55 +00:00
Hive.registerAdapter(SnChannelImplAdapter());
Hive.registerAdapter(SnRealmImplAdapter());
Hive.registerAdapter(SnChannelMemberImplAdapter());
Hive.registerAdapter(SnChatMessageImplAdapter());
2024-11-16 05:54:36 +00:00
2024-11-20 16:18:11 +00:00
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
2024-11-10 14:56:18 +00:00
if (!kReleaseMode) {
debugInvertOversizedImages = true;
}
2024-11-23 16:22:08 +00:00
GoRouter.optionURLReflectsImperativeAPIs = true;
usePathUrlStrategy();
await SentryFlutter.init(
(options) {
options.dsn =
'https://c218d44126d59d69301e730498494def@o4506965897117696.ingest.us.sentry.io/4508346768228352';
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
2024-11-23 10:10:50 +00:00
options.experimental.replay.sessionSampleRate = 1.0;
options.experimental.replay.onErrorSampleRate = 1.0;
},
appRunner: () => runApp(const SolianApp()),
);
2024-11-08 16:09:46 +00:00
}
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)),
Provider(create: (ctx) => UserDirectoryProvider(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-21 14:55:00 +00:00
ChangeNotifierProvider(create: (ctx) => NotificationProvider(ctx)),
2024-11-16 13:15:55 +00:00
ChangeNotifierProvider(create: (ctx) => ChatChannelProvider(ctx)),
2024-11-24 12:23:06 +00:00
ChangeNotifierProvider(create: (ctx) => ChatCallProvider(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>();
2024-11-16 13:15:55 +00:00
context.read<ChatChannelProvider>();
2024-11-21 14:55:00 +00:00
context.read<NotificationProvider>();
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,
);
}
}