2026-02-25 18:37:17 +01:00
|
|
|
import 'package:auth/auth.dart';
|
2025-12-04 16:07:02 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2025-11-13 15:16:00 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2026-02-24 16:29:24 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2025-12-04 16:07:02 +01:00
|
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
2025-12-03 13:42:14 +01:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2025-11-13 15:16:00 +01:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
import 'package:design_system/design_system.dart';
|
2026-01-27 02:28:52 +03:00
|
|
|
import 'package:sca_treezor/sca_treezor_module.dart';
|
2025-12-04 16:07:02 +01:00
|
|
|
import 'package:sf_app_platform/config/env/questia_env_config.dart';
|
2025-11-17 00:15:31 +01:00
|
|
|
import 'package:sf_app_platform/navigation/app_router.dart';
|
2026-02-25 18:37:17 +01:00
|
|
|
import 'package:navigation/navigation.dart';
|
2026-01-20 07:37:29 +01:00
|
|
|
import 'package:sf_app_platform/providers/app_state_provider.dart';
|
|
|
|
|
import 'package:sf_app_platform/providers/permissions/permissions_provider.dart';
|
2026-02-12 09:02:43 +01:00
|
|
|
import 'package:sf_app_platform/providers/wallet_heartbeat_service.dart';
|
2025-12-04 16:07:02 +01:00
|
|
|
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
2026-02-25 18:37:17 +01:00
|
|
|
import 'package:sf_shared/sf_shared.dart';
|
2025-11-24 12:55:20 +01:00
|
|
|
import 'package:sf_localizations/sf_localizations.dart';
|
2025-12-12 13:42:06 +01:00
|
|
|
import 'package:utils/utils.dart';
|
2026-01-15 09:20:45 +01:00
|
|
|
import 'package:fonts/fonts.dart';
|
2025-11-13 15:16:00 +01:00
|
|
|
|
|
|
|
|
Future<void> main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2026-02-25 18:37:17 +01:00
|
|
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2025-11-13 15:16:00 +01:00
|
|
|
navigationModule();
|
2026-01-27 02:28:52 +03:00
|
|
|
scaTreezorModule();
|
2025-11-13 15:16:00 +01:00
|
|
|
configureAppRouter();
|
|
|
|
|
themePackages();
|
2025-12-04 16:07:02 +01:00
|
|
|
await dotenv.load(fileName: '.env');
|
2025-11-13 15:16:00 +01:00
|
|
|
|
2026-02-25 18:37:17 +01:00
|
|
|
await configureDependencies(
|
|
|
|
|
QuestiaEnvConfig(),
|
|
|
|
|
log: kDebugMode,
|
|
|
|
|
onTreezorTokenExpired: () => appRouter.go(AppRoutes.scaTreezor),
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-13 15:16:00 +01:00
|
|
|
runApp(const ProviderScope(child: PlatformApp()));
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 07:37:29 +01:00
|
|
|
class PlatformApp extends ConsumerStatefulWidget {
|
2025-11-13 15:16:00 +01:00
|
|
|
const PlatformApp({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
2026-01-20 07:37:29 +01:00
|
|
|
PlatformAppState createState() => PlatformAppState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PlatformAppState extends ConsumerState<PlatformApp>
|
|
|
|
|
with WidgetsBindingObserver {
|
2026-02-12 09:02:43 +01:00
|
|
|
late final WalletHeartbeatService walletHeartbeat;
|
|
|
|
|
|
2026-01-20 07:37:29 +01:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2026-02-25 18:37:17 +01:00
|
|
|
walletHeartbeat = WalletHeartbeatService(
|
|
|
|
|
repository: ref.read(treezorRepositoryProvider),
|
|
|
|
|
sessionLocal: SessionLocalDatasourceImpl(),
|
|
|
|
|
);
|
|
|
|
|
onBeforeSessionCleared = walletHeartbeat.stop;
|
2026-02-12 09:02:43 +01:00
|
|
|
walletHeartbeat.start();
|
2026-01-20 07:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
2026-02-12 09:02:43 +01:00
|
|
|
walletHeartbeat.stop();
|
2026-01-20 07:37:29 +01:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
|
debugPrint('State: $state');
|
|
|
|
|
ref.read(appLifecycleStateProvider.notifier).setState(state);
|
|
|
|
|
if (state == AppLifecycleState.resumed) {
|
2026-02-12 09:02:43 +01:00
|
|
|
walletHeartbeat.start();
|
2026-01-20 07:37:29 +01:00
|
|
|
ref.read(permissionsProvider.notifier).checkPermissions();
|
2026-02-12 09:02:43 +01:00
|
|
|
} else if (state == AppLifecycleState.paused) {
|
|
|
|
|
walletHeartbeat.stop();
|
2026-01-20 07:37:29 +01:00
|
|
|
}
|
|
|
|
|
super.didChangeAppLifecycleState(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-12-12 13:42:06 +01:00
|
|
|
SizeUtils.init(context: context);
|
|
|
|
|
|
2025-11-13 15:16:00 +01:00
|
|
|
return MaterialApp.router(
|
|
|
|
|
title: 'SaveFamily',
|
|
|
|
|
theme: ThemeData(
|
2026-01-15 09:20:45 +01:00
|
|
|
fontFamily: AppFonts.stolzl,
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF329E95)),
|
2025-11-13 15:16:00 +01:00
|
|
|
),
|
|
|
|
|
routerConfig: appRouter,
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
2026-01-05 10:03:18 +01:00
|
|
|
localizationsDelegates: [
|
2026-02-12 14:32:57 +01:00
|
|
|
// CountryLocalizations.delegate,
|
2025-11-24 12:55:20 +01:00
|
|
|
SFLocalizations.delegate,
|
2025-12-03 13:42:14 +01:00
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
2025-11-24 12:55:20 +01:00
|
|
|
],
|
2025-12-03 13:42:14 +01:00
|
|
|
|
2025-11-24 12:55:20 +01:00
|
|
|
supportedLocales: [for (final lang in supportedLanguages) Locale(lang)],
|
2025-12-03 13:42:14 +01:00
|
|
|
localeResolutionCallback: (locale, supportedLocales) {
|
|
|
|
|
if (locale == null) return supportedLocales.first;
|
|
|
|
|
for (var supportedLocale in supportedLocales) {
|
|
|
|
|
if (supportedLocale.languageCode == locale.languageCode) {
|
|
|
|
|
return supportedLocale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return supportedLocales.first;
|
|
|
|
|
},
|
2025-11-13 15:16:00 +01:00
|
|
|
);
|
|
|
|
|
}
|
2025-12-04 16:07:02 +01:00
|
|
|
}
|