mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
initial commit
This commit is contained in:
116
lib/pages/main_page.dart
Normal file
116
lib/pages/main_page.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/pages/categories_page.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
import '../components/components.dart';
|
||||
import '../foundation/app.dart';
|
||||
import '../foundation/app_page_route.dart';
|
||||
import 'explore_page.dart';
|
||||
import 'favorites_page.dart';
|
||||
import 'home_page.dart';
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
late final NaviObserver _observer;
|
||||
|
||||
GlobalKey<NavigatorState>? _navigatorKey;
|
||||
|
||||
void to(Widget Function() widget, {bool preventDuplicate = false}) async {
|
||||
if (preventDuplicate) {
|
||||
var page = widget();
|
||||
if ("/${page.runtimeType}" == _observer.routes.last.toString()) return;
|
||||
}
|
||||
_navigatorKey!.currentContext!.to(widget);
|
||||
}
|
||||
|
||||
void back() {
|
||||
_navigatorKey!.currentContext!.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_observer = NaviObserver();
|
||||
_navigatorKey = GlobalKey();
|
||||
App.mainNavigatorKey = _navigatorKey;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
final _pages = [
|
||||
const HomePage(),
|
||||
const FavoritesPage(),
|
||||
const ExplorePage(),
|
||||
const CategoriesPage(),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return NaviPane(
|
||||
observer: _observer,
|
||||
paneItems: [
|
||||
PaneItemEntry(
|
||||
label: 'Home'.tl,
|
||||
icon: Icons.home_outlined,
|
||||
activeIcon: Icons.home,
|
||||
),
|
||||
PaneItemEntry(
|
||||
label: 'Favorites'.tl,
|
||||
icon: Icons.local_activity_outlined,
|
||||
activeIcon: Icons.local_activity,
|
||||
),
|
||||
PaneItemEntry(
|
||||
label: 'Explore'.tl,
|
||||
icon: Icons.explore_outlined,
|
||||
activeIcon: Icons.explore,
|
||||
),
|
||||
PaneItemEntry(
|
||||
label: 'Categories'.tl,
|
||||
icon: Icons.category_outlined,
|
||||
activeIcon: Icons.category,
|
||||
),
|
||||
],
|
||||
paneActions: [
|
||||
PaneActionEntry(
|
||||
icon: Icons.search,
|
||||
label: "Search".tl,
|
||||
onTap: () {},
|
||||
),
|
||||
PaneActionEntry(
|
||||
icon: Icons.settings,
|
||||
label: "Settings".tl,
|
||||
onTap: () {},
|
||||
)
|
||||
],
|
||||
pageBuilder: (index) {
|
||||
return Navigator(
|
||||
observers: [_observer],
|
||||
key: _navigatorKey,
|
||||
onGenerateRoute: (settings) => AppPageRoute(
|
||||
preventRebuild: false,
|
||||
isRootRoute: true,
|
||||
builder: (context) {
|
||||
return NaviPaddingWidget(child: _pages[index]);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
onPageChange: (index) {
|
||||
_navigatorKey!.currentState?.pushAndRemoveUntil(
|
||||
AppPageRoute(
|
||||
preventRebuild: false,
|
||||
isRootRoute: true,
|
||||
builder: (context) {
|
||||
return NaviPaddingWidget(child: _pages[index]);
|
||||
},
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user