78 lines
2.5 KiB
Dart
78 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:timezone/data/latest.dart' as tzdata;
|
|
|
|
import 'app/app_controller.dart';
|
|
import 'app/app_version.dart';
|
|
import 'services/diagnostic_log.dart';
|
|
import 'services/app_update_service.dart';
|
|
import 'app/hepan_app.dart';
|
|
import 'app/tp_startup.dart';
|
|
import 'data/file_snapshot_store.dart';
|
|
import 'services/local_notification_service.dart';
|
|
import 'services/android_calendar_service.dart';
|
|
import 'features/school/school_session.dart';
|
|
import 'features/school/school_auth_page.dart';
|
|
import 'features/school/undergraduate/session.dart';
|
|
import 'features/school/undergraduate/auth_page.dart';
|
|
|
|
Widget buildApplication(
|
|
AppController controller, {
|
|
ValueNotifier<String?>? notificationSelection,
|
|
SchoolSession? school,
|
|
UndergraduateSession? undergraduate,
|
|
AppUpdateService? updateService,
|
|
}) => HepanApp(
|
|
controller: controller,
|
|
notificationSelection: notificationSelection,
|
|
school: school,
|
|
undergraduate: undergraduate,
|
|
updateService: updateService,
|
|
undergraduateBuilder: undergraduate == null
|
|
? null
|
|
: () => UndergraduateAuthPage(
|
|
session: undergraduate,
|
|
controller: controller,
|
|
),
|
|
schoolBuilder: school == null
|
|
? null
|
|
: () => SchoolAuthPage(session: school, controller: controller),
|
|
);
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
DiagnosticLog.instance.add('app_started', fields: {'version': appVersion});
|
|
AppController? controller;
|
|
await launchApplication(
|
|
bootstrap: () async {
|
|
tzdata.initializeTimeZones();
|
|
final selection = ValueNotifier<String?>(null);
|
|
final gateway = PluginReminderGateway(
|
|
onTap: (key) => selection.value = key,
|
|
);
|
|
final directory = await getApplicationSupportDirectory();
|
|
unawaited(DiagnosticLog.instance.attach(directory));
|
|
final value = AppController(
|
|
FileSnapshotStore(directory),
|
|
LocalNotificationService(gateway),
|
|
AndroidCalendarService(MethodCalendarGateway()),
|
|
DateTime.now,
|
|
);
|
|
await value.initialize(reconcileServices: false);
|
|
controller = value;
|
|
return buildApplication(
|
|
value,
|
|
notificationSelection: selection,
|
|
school: SchoolSession(),
|
|
undergraduate: UndergraduateSession(),
|
|
updateService: AppUpdateService(),
|
|
);
|
|
},
|
|
onHomeReady: () {
|
|
final value = controller;
|
|
if (value != null) unawaited(value.refreshServices());
|
|
},
|
|
);
|
|
}
|