relatica/lib/main.dart

124 wiersze
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:logging/logging.dart';
import 'package:multi_trigger_autocomplete/multi_trigger_autocomplete.dart';
import 'package:provider/provider.dart';
import 'package:result_monad/result_monad.dart';
import 'globals.dart';
import 'models/TimelineIdentifiers.dart';
import 'routes.dart';
import 'services/auth_service.dart';
import 'services/connections_manager.dart';
import 'services/entry_manager_service.dart';
import 'services/gallery_service.dart';
import 'services/hashtag_service.dart';
import 'services/media_upload_attachment_helper.dart';
import 'services/notifications_manager.dart';
import 'services/secrets_service.dart';
import 'services/timeline_manager.dart';
import 'utils/app_scrolling_behavior.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await dotenv.load(fileName: '.env');
Logger.root.level = Level.FINER;
// Logger.root.onRecord.listen((event) {
// final logName = event.loggerName.isEmpty ? 'ROOT' : event.loggerName;
// final msg =
// '${event.level.name} - $logName @ ${event.time}: ${event.message}';
// print(msg);
// });
final authService = AuthService();
final secretsService = SecretsService();
final entryManagerService = EntryManagerService();
final timelineManager = TimelineManager();
final galleryService = GalleryService();
getIt.registerLazySingleton<ConnectionsManager>(() => ConnectionsManager());
getIt.registerLazySingleton<HashtagService>(() => HashtagService());
getIt.registerSingleton(galleryService);
getIt.registerSingleton<EntryManagerService>(entryManagerService);
getIt.registerSingleton<SecretsService>(secretsService);
getIt.registerSingleton<AuthService>(authService);
getIt.registerSingleton<TimelineManager>(timelineManager);
getIt.registerLazySingleton<MediaUploadAttachmentHelper>(
() => MediaUploadAttachmentHelper());
getIt.registerLazySingleton<NotificationsManager>(
() => NotificationsManager());
galleryService.getGalleries();
await secretsService.initialize().andThenSuccessAsync((credentials) async {
if (credentials.isEmpty) {
return;
}
final wasLoggedIn = await authService.getStoredLoginState();
if (wasLoggedIn) {
final result = await authService.signIn(credentials);
print('Startup login result: $result');
if (result.isSuccess) {
print('Getting timeline for ${result.value.credentials.handle}');
timelineManager.updateTimeline(
TimelineIdentifiers.home(), TimelineRefreshType.loadOlder);
}
} else {
print('Was not logged in');
}
});
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return Portal(
child: MultiProvider(
providers: [
ChangeNotifierProvider<AuthService>(
create: (_) => getIt<AuthService>(),
lazy: true,
),
ChangeNotifierProvider<ConnectionsManager>(
create: (_) => getIt<ConnectionsManager>(),
lazy: true,
),
ChangeNotifierProvider<EntryManagerService>(
create: (_) => getIt<EntryManagerService>(),
lazy: true,
),
ChangeNotifierProvider<GalleryService>(
create: (_) => getIt<GalleryService>(),
lazy: true,
),
ChangeNotifierProvider<HashtagService>(
create: (_) => getIt<HashtagService>(),
lazy: true,
),
ChangeNotifierProvider<TimelineManager>(
create: (_) => getIt<TimelineManager>(),
),
ChangeNotifierProvider<NotificationsManager>(
create: (_) => getIt<NotificationsManager>(),
),
],
child: MaterialApp.router(
theme: ThemeData(
primarySwatch: Colors.indigo,
),
debugShowCheckedModeBanner: false,
scrollBehavior: AppScrollingBehavior(),
routerDelegate: appRouter.routerDelegate,
routeInformationProvider: appRouter.routeInformationProvider,
routeInformationParser: appRouter.routeInformationParser,
),
),
);
}
}