revanced-manager/lib/main.dart

66 lines
2.3 KiB
Dart
Raw Normal View History

import 'dart:developer';
2022-07-30 21:09:59 +02:00
import 'package:flutter/material.dart';
2022-08-07 01:37:12 +02:00
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
2022-08-06 23:35:35 +02:00
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/github_api.dart';
2022-08-25 01:51:47 +02:00
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/revanced_api.dart';
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
2022-09-05 10:07:38 +02:00
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked_themes/stacked_themes.dart';
2022-09-20 01:03:37 +02:00
import 'package:timezone/data/latest.dart' as tz;
2022-07-30 21:09:59 +02:00
late SharedPreferences prefs;
2022-08-11 21:05:03 +02:00
Future main() async {
await ThemeManager.initialise();
await setupLocator();
WidgetsFlutterBinding.ensureInitialized();
await locator<ManagerAPI>().initialize();
final String apiUrl = locator<ManagerAPI>().getApiUrl();
await locator<RevancedAPI>().initialize(apiUrl);
final String repoUrl = locator<ManagerAPI>().getRepoUrl();
2022-12-09 13:10:43 +01:00
locator<GithubAPI>().initialize(repoUrl);
2022-09-20 01:03:37 +02:00
tz.initializeTimeZones();
prefs = await SharedPreferences.getInstance();
runApp(const MyApp());
2022-07-30 21:09:59 +02:00
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// String rawLocale = prefs.getString('language') ?? 'en_US';
// String replaceLocale = rawLocale.replaceAll('_', '-');
// List<String> localeList = replaceLocale.split('-');
// Locale locale = Locale(localeList[0], localeList[1]);
const Locale locale = Locale('en', 'US');
2022-11-10 18:33:07 +01:00
return DynamicThemeBuilder(
title: 'ReVanced Manager',
home: const NavigationView(),
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(
fallbackFile: 'en_US',
2022-11-10 18:33:07 +01:00
forcedLocale: locale,
basePath: 'assets/i18n',
2022-11-10 18:33:07 +01:00
useCountryCode: true,
),
2022-11-10 18:33:07 +01:00
missingTranslationHandler: (key, locale) {
log(
'--> Missing translation: key: $key, languageCode: ${locale?.languageCode}',
);
2022-11-10 18:33:07 +01:00
},
),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
2022-07-31 10:00:11 +02:00
);
}
}