mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-27 21:11:01 +00:00
refactor: migrate to stacked architecture.
* feat: mostly done stacked architecture. * refactor: migration to stacked architecture.
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:revanced_manager_flutter/app/app.locator.dart';
|
||||
import 'package:revanced_manager_flutter/app/app.router.dart';
|
||||
import 'package:revanced_manager_flutter/main_viewmodel.dart';
|
||||
import 'package:revanced_manager_flutter/theme.dart';
|
||||
import 'package:revanced_manager_flutter/ui/screens/home_screen.dart';
|
||||
import 'package:revanced_manager_flutter/ui/screens/patcher_screen.dart';
|
||||
import 'package:revanced_manager_flutter/ui/views/home/home_view.dart';
|
||||
import 'package:revanced_manager_flutter/ui/views/patcher/patcher_view.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
void main() {
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
setupLocator();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -17,47 +24,47 @@ class MyApp extends StatelessWidget {
|
||||
title: 'ReVanced Manager',
|
||||
theme: lightTheme,
|
||||
darkTheme: darkTheme,
|
||||
navigatorKey: StackedService.navigatorKey,
|
||||
onGenerateRoute: StackedRouter().onGenerateRoute,
|
||||
home: const Navigation(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Navigation extends StatefulWidget {
|
||||
class Navigation extends StatelessWidget {
|
||||
const Navigation({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Navigation> createState() => _NavigationState();
|
||||
}
|
||||
|
||||
class _NavigationState extends State<Navigation> {
|
||||
int currentPageIndex = 0;
|
||||
final List<Widget> screens = [
|
||||
const HomeScreen(),
|
||||
const PatcherScreen(),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: screens[currentPageIndex],
|
||||
bottomNavigationBar: NavigationBar(
|
||||
onDestinationSelected: (int index) {
|
||||
setState(() {
|
||||
currentPageIndex = index;
|
||||
});
|
||||
},
|
||||
selectedIndex: currentPageIndex,
|
||||
destinations: const <Widget>[
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.dashboard),
|
||||
label: "Dashboard",
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.build),
|
||||
label: "Patcher",
|
||||
),
|
||||
],
|
||||
return ViewModelBuilder<MainViewModel>.reactive(
|
||||
viewModelBuilder: () => MainViewModel(),
|
||||
builder: (context,MainViewModel model, child) => Scaffold(
|
||||
body: getViewForIndex(model.currentIndex),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
onDestinationSelected: model.setIndex,
|
||||
selectedIndex: model.currentIndex,
|
||||
destinations: const <Widget>[
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.dashboard),
|
||||
label: "Dashboard",
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.build),
|
||||
label: "Patcher",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget getViewForIndex(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return const HomeView();
|
||||
case 1:
|
||||
return const PatcherView();
|
||||
default:
|
||||
return const HomeView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user