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-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-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-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,
|
|
|
|
|
sessionBootstrapper: AuthSessionBootstrapper(
|
|
|
|
|
calendarService: sl<CalendarService>(),
|
|
|
|
|
notificationService: sl<LocalNotificationService>(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
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-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,
|
|
|
|
|
required this.sessionBootstrapper,
|
|
|
|
|
});
|
2026-02-25 10:57:43 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-02-25 15:25:31 +08:00
|
|
|
return BlocProvider<AuthBloc>.value(
|
|
|
|
|
value: authBloc,
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|