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';
|
|
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.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-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';
|
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-13 16:08:09 +00:00
|
|
|
import 'package:surface/providers/navigation.dart';
|
2024-11-21 14:10:12 +00:00
|
|
|
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';
|
2024-11-16 17:16:54 +00:00
|
|
|
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';
|
2024-11-16 17:16:54 +00:00
|
|
|
import 'package:surface/types/realm.dart';
|
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());
|
2024-11-16 17:16:54 +00:00
|
|
|
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-20 16:18:11 +00:00
|
|
|
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
|
|
|
|
PlatformDispatcher.instance.onError = (error, stack) {
|
|
|
|
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
|
|
|
return 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,
|
2024-11-13 16:40:58 +00:00
|
|
|
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-16 17:16:54 +00:00
|
|
|
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-08 16:09:46 +00:00
|
|
|
],
|
2024-11-10 13:48:42 +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),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-11-10 13:48:42 +00:00
|
|
|
|
|
|
|
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>();
|
2024-11-10 13:48:42 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|