2026-03-13 14:10:13 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2026-02-25 10:57:43 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2026-02-25 15:25:31 +08:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-03-13 14:10:13 +08:00
|
|
|
|
2026-03-16 16:09:07 +08:00
|
|
|
import 'core/constants/app_constants.dart';
|
2026-02-25 15:25:31 +08:00
|
|
|
import 'core/di/injection.dart';
|
2026-03-13 14:10:13 +08:00
|
|
|
import 'core/notifications/local_notification_service.dart';
|
2026-03-20 01:30:34 +08:00
|
|
|
import 'core/notifications/reminder_notification_callbacks.dart';
|
2026-02-25 10:57:43 +08:00
|
|
|
import 'core/router/app_router.dart';
|
2026-03-13 14:10:13 +08:00
|
|
|
import 'core/startup/auth_session_bootstrapper.dart';
|
2026-02-25 15:25:31 +08:00
|
|
|
import 'core/theme/app_theme.dart';
|
|
|
|
|
import 'features/auth/presentation/bloc/auth_bloc.dart';
|
|
|
|
|
import 'features/auth/presentation/bloc/auth_event.dart';
|
2026-03-13 14:10:13 +08:00
|
|
|
import 'features/auth/presentation/bloc/auth_state.dart';
|
2026-03-12 16:41:45 +08:00
|
|
|
import 'features/calendar/data/services/calendar_service.dart';
|
2026-03-18 19:12:47 +08:00
|
|
|
import 'features/calendar/reminders/reminder_action_executor.dart';
|
2026-03-20 01:30:34 +08:00
|
|
|
import 'features/calendar/reminders/ui/reminder_foreground_presenter.dart';
|
2026-03-18 17:03:22 +08:00
|
|
|
import 'features/chat/presentation/bloc/chat_bloc.dart';
|
2026-02-25 15:25:31 +08:00
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
await configureDependencies();
|
2026-03-16 16:09:07 +08:00
|
|
|
await AppConstants.init();
|
2026-03-20 01:30:34 +08:00
|
|
|
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
|
final reminderForegroundPresenter = ReminderForegroundPresenter(
|
|
|
|
|
navigatorKey: rootNavigatorKey,
|
|
|
|
|
executor: sl<ReminderActionExecutor>(),
|
|
|
|
|
);
|
2026-03-18 19:12:47 +08:00
|
|
|
sl<LocalNotificationService>().bindActionHandler(({
|
|
|
|
|
required action,
|
|
|
|
|
required payload,
|
|
|
|
|
}) {
|
|
|
|
|
return sl<ReminderActionExecutor>().handleAction(
|
|
|
|
|
action: action,
|
|
|
|
|
payload: payload,
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-20 01:30:34 +08:00
|
|
|
sl<LocalNotificationService>().bindInAppReminderHandler(
|
|
|
|
|
reminderForegroundPresenter.present,
|
|
|
|
|
);
|
2026-03-18 19:12:47 +08:00
|
|
|
await sl<LocalNotificationService>().initialize();
|
2026-02-25 10:57:43 +08:00
|
|
|
|
2026-02-25 15:25:31 +08:00
|
|
|
final authBloc = sl<AuthBloc>();
|
2026-03-12 16:41:45 +08:00
|
|
|
authBloc.add(AuthStarted());
|
2026-02-25 15:25:31 +08:00
|
|
|
|
2026-03-13 14:10:13 +08:00
|
|
|
runApp(
|
|
|
|
|
LinksyApp(
|
|
|
|
|
authBloc: authBloc,
|
2026-03-20 01:30:34 +08:00
|
|
|
rootNavigatorKey: rootNavigatorKey,
|
2026-03-13 14:10:13 +08:00
|
|
|
sessionBootstrapper: AuthSessionBootstrapper(
|
|
|
|
|
calendarService: sl<CalendarService>(),
|
|
|
|
|
notificationService: sl<LocalNotificationService>(),
|
2026-03-18 19:12:47 +08:00
|
|
|
reminderActionExecutor: sl<ReminderActionExecutor>(),
|
2026-03-13 14:10:13 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-03-20 01:30:34 +08:00
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
unawaited(
|
|
|
|
|
ReminderNotificationCallbacks.bindResponseHandler(
|
|
|
|
|
sl<LocalNotificationService>().handleNotificationResponse,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-02-25 10:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LinksyApp extends StatelessWidget {
|
2026-02-25 15:25:31 +08:00
|
|
|
final AuthBloc authBloc;
|
2026-03-20 01:30:34 +08:00
|
|
|
final GlobalKey<NavigatorState> rootNavigatorKey;
|
2026-03-13 14:10:13 +08:00
|
|
|
final AuthSessionBootstrapper sessionBootstrapper;
|
2026-02-25 15:25:31 +08:00
|
|
|
|
2026-03-13 14:10:13 +08:00
|
|
|
const LinksyApp({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.authBloc,
|
2026-03-20 01:30:34 +08:00
|
|
|
required this.rootNavigatorKey,
|
2026-03-13 14:10:13 +08:00
|
|
|
required this.sessionBootstrapper,
|
|
|
|
|
});
|
2026-02-25 10:57:43 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-03-18 17:03:22 +08:00
|
|
|
return MultiBlocProvider(
|
|
|
|
|
providers: [
|
|
|
|
|
BlocProvider<AuthBloc>.value(value: authBloc),
|
|
|
|
|
BlocProvider<ChatBloc>(create: (_) => ChatBloc(apiClient: sl())),
|
|
|
|
|
],
|
2026-03-13 14:10:13 +08:00
|
|
|
child: BlocListener<AuthBloc, AuthState>(
|
|
|
|
|
listenWhen: (previous, current) => previous != current,
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
unawaited(sessionBootstrapper.syncForAuthState(state));
|
|
|
|
|
},
|
|
|
|
|
child: MaterialApp.router(
|
|
|
|
|
title: 'Linksy',
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
theme: AppTheme.light,
|
|
|
|
|
routerConfig: createAppRouter(authBloc),
|
|
|
|
|
),
|
2026-02-25 15:25:31 +08:00
|
|
|
),
|
2026-02-25 10:57:43 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|