-
-
Notifications
You must be signed in to change notification settings - Fork 336
Expand file tree
/
Copy pathmain_dev.dart
More file actions
60 lines (55 loc) 路 2.42 KB
/
Copy pathmain_dev.dart
File metadata and controls
60 lines (55 loc) 路 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:opennutritracker/core/data/repository/config_repository.dart';
import 'package:opennutritracker/core/utils/app_locale_service.dart';
import 'package:opennutritracker/core/utils/app_locale_sync.dart';
import 'package:opennutritracker/core/utils/demo/demo_seeder.dart';
import 'package:opennutritracker/core/utils/locator.dart';
import 'package:opennutritracker/core/utils/logger_config.dart';
import 'package:opennutritracker/generated/l10n.dart';
import 'package:opennutritracker/main.dart';
/// Dev-only entry point: wipes the active profile and reseeds it with
/// realistic demo data (user, a year of meals and activities, weight/water
/// history, a recipe, fasting sessions), then boots straight past
/// onboarding.
///
/// Run with `flutter run -t lib/dev/main_dev.dart` (or `just dev_seed`)
/// instead of the normal `flutter run` when you want a populated app to
/// test against rather than walking onboarding by hand on every run.
Future<void> main() async {
if (kReleaseMode) {
throw UnsupportedError(
'lib/dev/main_dev.dart seeds demo data and must never be built in release mode',
);
}
WidgetsFlutterBinding.ensureInitialized();
LoggerConfig.intiLogger();
await initLocator();
await seedDemoData(DemoSeedOptions.dev);
final configRepo = locator<ConfigRepository>();
final config = await configRepo.getConfig();
// Mirrors the reconciliation in main.dart so a dev build behaves the same
// way when the OS holds a per-app language.
final systemLocale = await AppLocaleService.getApplicationLocale();
final localeCode = await reconcileAppLocale(
savedLocaleCode: await configRepo.getSelectedLocale(),
systemLocaleTag: systemLocale.tag,
systemTagReadFailed: systemLocale.readFailed,
localeSyncSeeded: await configRepo.getLocaleSyncSeeded(),
supportedLocales: S.supportedLocales,
persistSelectedLocale: configRepo.setSelectedLocale,
pushToSystem: AppLocaleService.setApplicationLocale,
readSystemTag: AppLocaleService.getApplicationLocale,
markLocaleSyncSeeded: configRepo.setLocaleSyncSeeded,
);
final savedLocale = localeCode != null ? Locale(localeCode) : null;
final savedAppTheme = await configRepo.getConfigAppTheme();
runAppWithChangeNotifiers(
true,
savedAppTheme,
savedLocale,
config.usesKilojoules,
config.useMaterialYou,
config.accentColor,
);
}