fix: reorganize main and navigation

This commit is contained in:
Alberto Ponces 2022-09-05 09:07:38 +01:00
parent 9b91e4aaa3
commit db02dc623f
10 changed files with 96 additions and 93 deletions

View File

@ -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/patcher_api.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/home/home_viewmodel.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_viewmodel.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(
routes: [
MaterialRoute(page: Navigation),
MaterialRoute(page: NavigationView),
MaterialRoute(page: PatcherView),
MaterialRoute(page: AppSelectorView),
MaterialRoute(page: PatchesSelectorView),
@ -26,7 +26,7 @@ import 'package:stacked_services/stacked_services.dart';
MaterialRoute(page: RootCheckerView),
],
dependencies: [
LazySingleton(classType: MainViewModel),
LazySingleton(classType: NavigationViewModel),
LazySingleton(classType: HomeViewModel),
LazySingleton(classType: PatcherViewModel),
LazySingleton(classType: NavigationService),

View File

@ -1,18 +1,13 @@
import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_localizations/flutter_localizations.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/patcher_api.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/patcher/patcher_view.dart';
import 'package:revanced_manager/ui/views/navigation/navigation_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';
Future main() async {
@ -62,79 +57,8 @@ class MyApp extends StatelessWidget {
await locator<PatcherAPI>().initialize();
bool? isRooted = locator<ManagerAPI>().isRooted();
if (isRooted != null) {
return const Navigation();
return const NavigationView();
}
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();
}
}
}

View File

@ -1,5 +0,0 @@
import 'package:injectable/injectable.dart';
import 'package:stacked/stacked.dart';
@lazySingleton
class MainViewModel extends IndexTrackingViewModel {}

View File

@ -8,10 +8,10 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:injectable/injectable.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/services/manager_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:stacked/stacked.dart';
@ -46,7 +46,7 @@ class HomeViewModel extends BaseViewModel {
locator<PatcherViewModel>().selectedPatches =
await _patcherAPI.getAppliedPatches(app.appliedPatches);
locator<PatcherViewModel>().notifyListeners();
locator<MainViewModel>().setIndex(1);
locator<NavigationViewModel>().setIndex(1);
}
void _getPatchedApps() {

View 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',
),
),
],
),
),
);
}
}

View 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();
}
}
}

View File

@ -62,7 +62,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
onSelectAll: (value) => model.selectAllPatches(value),
),
const SizedBox(height: 12),
//TODO:IMPROVE THIS BAD CODE!!
// TODO: IMPROVE THIS BAD CODE
Expanded(
child: ListView(
padding: const EdgeInsets.only(bottom: 80),

View File

@ -27,6 +27,6 @@ class RootCheckerViewModel extends BaseViewModel {
Future<void> navigateToHome() async {
_managerAPI.setIsRooted(isRooted);
_navigationService.navigateTo(Routes.navigation);
_navigationService.navigateTo(Routes.navigationView);
}
}

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.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/shared/custom_card.dart';

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/models/patch.dart';
class OptionsTextField extends StatelessWidget {
final String hint;