50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '/l10n/generated/l10n.dart';
|
|
import '/locator.dart';
|
|
|
|
abstract class AppSetup {
|
|
// TODO: When locator is properly refactored we should not have to use these stub methods for testing
|
|
static Future<void> initialise() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.portraitUp,
|
|
DeviceOrientation.portraitDown,
|
|
]);
|
|
|
|
await Locator.setup();
|
|
}
|
|
|
|
static final List<Locale> supportedLocales = kReleaseMode
|
|
? <Locale>[
|
|
const Locale.fromSubtags(languageCode: 'en'),
|
|
]
|
|
: Strings.delegate.supportedLocales;
|
|
|
|
static Locale resolveLocale(List<Locale>? preferredLocales, Iterable<Locale> supportedLocales) {
|
|
for (final locale in preferredLocales ?? const <Locale>[]) {
|
|
// Check if the current device locale is supported
|
|
for (final supportedLocale in supportedLocales) {
|
|
if (supportedLocale.languageCode == locale.languageCode) {
|
|
return supportedLocale;
|
|
}
|
|
}
|
|
}
|
|
return supportedLocales.first;
|
|
}
|
|
|
|
static Future<void> setupStrings() async {
|
|
await Strings.load(resolveLocale(WidgetsBinding.instance.window.locales, supportedLocales));
|
|
}
|
|
|
|
static void Function(Object error, StackTrace stackTrace) get onUncaughtException => (
|
|
error,
|
|
stackTrace,
|
|
) {};
|
|
}
|