77 lines
2.6 KiB
Dart
77 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:encrypt_shared_preferences/provider.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:f0ckapp/controller/authcontroller.dart';
|
|
import 'package:f0ckapp/controller/localizationcontroller.dart';
|
|
import 'package:f0ckapp/controller/themecontroller.dart';
|
|
import 'package:f0ckapp/screens/mediadetail.dart';
|
|
import 'package:f0ckapp/utils/appversion.dart';
|
|
import 'package:f0ckapp/controller/mediacontroller.dart';
|
|
import 'package:f0ckapp/screens/mediagrid.dart';
|
|
import 'package:f0ckapp/screens/login.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await EncryptedSharedPreferencesAsync.initialize('VokTnbAbemBUa2j9');
|
|
await MyTranslations.loadTranslations();
|
|
await AppVersion.init();
|
|
Get.put(AuthController());
|
|
final MediaController mediaController = Get.put(MediaController());
|
|
final ThemeController themeController = Get.put(ThemeController());
|
|
final LocalizationController localizationController = Get.put(
|
|
LocalizationController(),
|
|
);
|
|
|
|
Get.addTranslations(MyTranslations.instance.keys);
|
|
Get.locale = localizationController.currentLocale.value;
|
|
|
|
//Locale systemLocale = WidgetsBinding.instance.platformDispatcher.locale;
|
|
|
|
runApp(
|
|
Obx(
|
|
() => MaterialApp(
|
|
locale: Get.locale,
|
|
navigatorKey: Get.key,
|
|
theme: themeController.currentTheme.value,
|
|
debugShowCheckedModeBanner: false,
|
|
initialRoute: '/',
|
|
onGenerateRoute: (RouteSettings settings) {
|
|
final Uri uri = Uri.parse(settings.name ?? '/');
|
|
|
|
if (uri.path == '/' || uri.pathSegments.isEmpty) {
|
|
return MaterialPageRoute(builder: (_) => MediaGrid());
|
|
}
|
|
|
|
if (uri.path == '/login') {
|
|
return MaterialPageRoute(builder: (_) => LoginScreen());
|
|
}
|
|
|
|
if (uri.pathSegments.length == 1) {
|
|
final int id = int.parse(uri.pathSegments.first);
|
|
|
|
return MaterialPageRoute(
|
|
builder: (_) => FutureBuilder(
|
|
future: mediaController.items.isEmpty
|
|
? mediaController.fetchInitial(id: id)
|
|
: Future.value(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
return MediaDetailScreen(initialId: id);
|
|
}
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
return MaterialPageRoute(builder: (_) => MediaGrid());
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|