revanced-manager/lib/main.dart

91 lines
2.7 KiB
Dart
Raw Normal View History

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';
2022-08-07 02:13:27 +02:00
// ignore: depend_on_referenced_packages
2022-08-07 01:37:12 +02:00
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/app/app.router.dart';
import 'package:revanced_manager/main_viewmodel.dart';
import 'package:revanced_manager/theme.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
2022-07-30 21:09:59 +02:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
setupLocator();
2022-07-30 21:09:59 +02:00
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
2022-07-31 10:00:11 +02:00
debugShowCheckedModeBanner: false,
2022-07-30 21:20:36 +02:00
title: 'ReVanced Manager',
2022-08-01 13:30:06 +02:00
theme: lightTheme,
darkTheme: darkTheme,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
2022-07-31 10:00:11 +02:00
home: const Navigation(),
2022-08-07 01:37:12 +02:00
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(
fallbackFile: 'en',
basePath: 'assets/i18n',
),
),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
2022-07-31 10:00:11 +02:00
);
}
}
class Navigation extends StatelessWidget {
2022-07-31 10:00:11 +02:00
const Navigation({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<MainViewModel>.reactive(
viewModelBuilder: () => MainViewModel(),
2022-08-06 23:35:35 +02:00
builder: (context, MainViewModel model, child) => Scaffold(
body: getViewForIndex(model.currentIndex),
bottomNavigationBar: NavigationBar(
onDestinationSelected: model.setIndex,
selectedIndex: model.currentIndex,
2022-08-07 01:37:12 +02:00
destinations: <Widget>[
NavigationDestination(
2022-08-07 01:37:12 +02:00
icon: const Icon(Icons.dashboard),
label: FlutterI18n.translate(
context,
'main.dashboardTab',
),
),
NavigationDestination(
2022-08-07 01:37:12 +02:00
icon: const Icon(Icons.build),
label: FlutterI18n.translate(
context,
'main.patcherTab',
),
),
],
),
2022-07-30 21:09:59 +02:00
),
);
}
2022-08-06 23:35:35 +02:00
Widget getViewForIndex(int index) {
switch (index) {
case 0:
return const HomeView();
case 1:
return const PatcherView();
default:
return const HomeView();
}
}
2022-07-30 21:09:59 +02:00
}