mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: reorganize main and navigation
This commit is contained in:
parent
9b91e4aaa3
commit
db02dc623f
@ -1,11 +1,11 @@
|
|||||||
import 'package:revanced_manager/main.dart';
|
|
||||||
import 'package:revanced_manager/main_viewmodel.dart';
|
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/services/patcher_api.dart';
|
import 'package:revanced_manager/services/patcher_api.dart';
|
||||||
import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart';
|
import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/contributors/contributors_view.dart';
|
import 'package:revanced_manager/ui/views/contributors/contributors_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||||
import 'package:revanced_manager/ui/views/installer/installer_view.dart';
|
import 'package:revanced_manager/ui/views/installer/installer_view.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||||
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart';
|
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart';
|
||||||
@ -16,7 +16,7 @@ import 'package:stacked_services/stacked_services.dart';
|
|||||||
|
|
||||||
@StackedApp(
|
@StackedApp(
|
||||||
routes: [
|
routes: [
|
||||||
MaterialRoute(page: Navigation),
|
MaterialRoute(page: NavigationView),
|
||||||
MaterialRoute(page: PatcherView),
|
MaterialRoute(page: PatcherView),
|
||||||
MaterialRoute(page: AppSelectorView),
|
MaterialRoute(page: AppSelectorView),
|
||||||
MaterialRoute(page: PatchesSelectorView),
|
MaterialRoute(page: PatchesSelectorView),
|
||||||
@ -26,7 +26,7 @@ import 'package:stacked_services/stacked_services.dart';
|
|||||||
MaterialRoute(page: RootCheckerView),
|
MaterialRoute(page: RootCheckerView),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
LazySingleton(classType: MainViewModel),
|
LazySingleton(classType: NavigationViewModel),
|
||||||
LazySingleton(classType: HomeViewModel),
|
LazySingleton(classType: HomeViewModel),
|
||||||
LazySingleton(classType: PatcherViewModel),
|
LazySingleton(classType: PatcherViewModel),
|
||||||
LazySingleton(classType: NavigationService),
|
LazySingleton(classType: NavigationService),
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import 'package:animations/animations.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
// ignore: depend_on_referenced_packages
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:revanced_manager/app/app.locator.dart';
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/main_viewmodel.dart';
|
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/services/patcher_api.dart';
|
import 'package:revanced_manager/services/patcher_api.dart';
|
||||||
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
||||||
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
|
||||||
import 'package:revanced_manager/ui/views/root_checker/root_checker_view.dart';
|
import 'package:revanced_manager/ui/views/root_checker/root_checker_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
|
|
||||||
import 'package:stacked/stacked.dart';
|
|
||||||
import 'package:stacked_themes/stacked_themes.dart';
|
import 'package:stacked_themes/stacked_themes.dart';
|
||||||
|
|
||||||
Future main() async {
|
Future main() async {
|
||||||
@ -62,79 +57,8 @@ class MyApp extends StatelessWidget {
|
|||||||
await locator<PatcherAPI>().initialize();
|
await locator<PatcherAPI>().initialize();
|
||||||
bool? isRooted = locator<ManagerAPI>().isRooted();
|
bool? isRooted = locator<ManagerAPI>().isRooted();
|
||||||
if (isRooted != null) {
|
if (isRooted != null) {
|
||||||
return const Navigation();
|
return const NavigationView();
|
||||||
}
|
}
|
||||||
return const RootCheckerView();
|
return const RootCheckerView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Navigation extends StatelessWidget {
|
|
||||||
const Navigation({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ViewModelBuilder<MainViewModel>.reactive(
|
|
||||||
viewModelBuilder: () => locator<MainViewModel>(),
|
|
||||||
builder: (context, model, child) => Scaffold(
|
|
||||||
body: PageTransitionSwitcher(
|
|
||||||
duration: const Duration(milliseconds: 400),
|
|
||||||
transitionBuilder: (
|
|
||||||
Widget child,
|
|
||||||
Animation<double> animation,
|
|
||||||
Animation<double> secondaryAnimation,
|
|
||||||
) {
|
|
||||||
return FadeThroughTransition(
|
|
||||||
animation: animation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
fillColor: Theme.of(context).colorScheme.surface,
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: getViewForIndex(model.currentIndex),
|
|
||||||
),
|
|
||||||
bottomNavigationBar: NavigationBar(
|
|
||||||
onDestinationSelected: model.setIndex,
|
|
||||||
selectedIndex: model.currentIndex,
|
|
||||||
destinations: <Widget>[
|
|
||||||
NavigationDestination(
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.dashboard,
|
|
||||||
),
|
|
||||||
label: FlutterI18n.translate(
|
|
||||||
context,
|
|
||||||
'main.dashboardTab',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
NavigationDestination(
|
|
||||||
icon: const Icon(Icons.build),
|
|
||||||
label: FlutterI18n.translate(
|
|
||||||
context,
|
|
||||||
'main.patcherTab',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
NavigationDestination(
|
|
||||||
icon: const Icon(Icons.settings),
|
|
||||||
label: FlutterI18n.translate(
|
|
||||||
context,
|
|
||||||
'main.settingsTab',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget getViewForIndex(int index) {
|
|
||||||
switch (index) {
|
|
||||||
case 0:
|
|
||||||
return const HomeView();
|
|
||||||
case 1:
|
|
||||||
return const PatcherView();
|
|
||||||
case 2:
|
|
||||||
return SettingsView();
|
|
||||||
default:
|
|
||||||
return const HomeView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import 'package:injectable/injectable.dart';
|
|
||||||
import 'package:stacked/stacked.dart';
|
|
||||||
|
|
||||||
@lazySingleton
|
|
||||||
class MainViewModel extends IndexTrackingViewModel {}
|
|
@ -8,10 +8,10 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:injectable/injectable.dart';
|
import 'package:injectable/injectable.dart';
|
||||||
import 'package:revanced_manager/app/app.locator.dart';
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/main_viewmodel.dart';
|
|
||||||
import 'package:revanced_manager/models/patched_application.dart';
|
import 'package:revanced_manager/models/patched_application.dart';
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/services/patcher_api.dart';
|
import 'package:revanced_manager/services/patcher_api.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||||
import 'package:stacked/stacked.dart';
|
import 'package:stacked/stacked.dart';
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
locator<PatcherViewModel>().selectedPatches =
|
locator<PatcherViewModel>().selectedPatches =
|
||||||
await _patcherAPI.getAppliedPatches(app.appliedPatches);
|
await _patcherAPI.getAppliedPatches(app.appliedPatches);
|
||||||
locator<PatcherViewModel>().notifyListeners();
|
locator<PatcherViewModel>().notifyListeners();
|
||||||
locator<MainViewModel>().setIndex(1);
|
locator<NavigationViewModel>().setIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getPatchedApps() {
|
void _getPatchedApps() {
|
||||||
|
64
lib/ui/views/navigation/navigation_view.dart
Normal file
64
lib/ui/views/navigation/navigation_view.dart
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import 'package:animations/animations.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
||||||
|
import 'package:stacked/stacked.dart';
|
||||||
|
|
||||||
|
class NavigationView extends StatelessWidget {
|
||||||
|
const NavigationView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ViewModelBuilder<NavigationViewModel>.reactive(
|
||||||
|
viewModelBuilder: () => locator<NavigationViewModel>(),
|
||||||
|
builder: (context, model, child) => Scaffold(
|
||||||
|
body: PageTransitionSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 400),
|
||||||
|
transitionBuilder: (
|
||||||
|
Widget child,
|
||||||
|
Animation<double> animation,
|
||||||
|
Animation<double> secondaryAnimation,
|
||||||
|
) {
|
||||||
|
return FadeThroughTransition(
|
||||||
|
animation: animation,
|
||||||
|
secondaryAnimation: secondaryAnimation,
|
||||||
|
fillColor: Theme.of(context).colorScheme.surface,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: model.getViewForIndex(model.currentIndex),
|
||||||
|
),
|
||||||
|
bottomNavigationBar: NavigationBar(
|
||||||
|
onDestinationSelected: model.setIndex,
|
||||||
|
selectedIndex: model.currentIndex,
|
||||||
|
destinations: <Widget>[
|
||||||
|
NavigationDestination(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.dashboard,
|
||||||
|
),
|
||||||
|
label: FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'main.dashboardTab',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: const Icon(Icons.build),
|
||||||
|
label: FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'main.patcherTab',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: const Icon(Icons.settings),
|
||||||
|
label: FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'main.settingsTab',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
22
lib/ui/views/navigation/navigation_viewmodel.dart
Normal file
22
lib/ui/views/navigation/navigation_viewmodel.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:injectable/injectable.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
||||||
|
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
|
||||||
|
import 'package:stacked/stacked.dart';
|
||||||
|
|
||||||
|
@lazySingleton
|
||||||
|
class NavigationViewModel extends IndexTrackingViewModel {
|
||||||
|
Widget getViewForIndex(int index) {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
return const HomeView();
|
||||||
|
case 1:
|
||||||
|
return const PatcherView();
|
||||||
|
case 2:
|
||||||
|
return SettingsView();
|
||||||
|
default:
|
||||||
|
return const HomeView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -62,7 +62,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
|||||||
onSelectAll: (value) => model.selectAllPatches(value),
|
onSelectAll: (value) => model.selectAllPatches(value),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
//TODO:IMPROVE THIS BAD CODE!!
|
// TODO: IMPROVE THIS BAD CODE
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.only(bottom: 80),
|
padding: const EdgeInsets.only(bottom: 80),
|
||||||
|
@ -27,6 +27,6 @@ class RootCheckerViewModel extends BaseViewModel {
|
|||||||
|
|
||||||
Future<void> navigateToHome() async {
|
Future<void> navigateToHome() async {
|
||||||
_managerAPI.setIsRooted(isRooted);
|
_managerAPI.setIsRooted(isRooted);
|
||||||
_navigationService.navigateTo(Routes.navigation);
|
_navigationService.navigateTo(Routes.navigationView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_options_fields.dart';
|
|
||||||
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
|
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
|
||||||
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:revanced_manager/models/patch.dart';
|
|
||||||
|
|
||||||
class OptionsTextField extends StatelessWidget {
|
class OptionsTextField extends StatelessWidget {
|
||||||
final String hint;
|
final String hint;
|
||||||
|
Loading…
Reference in New Issue
Block a user