Router changes
This commit is contained in:
23
lib/config/app_screens.dart
Normal file
23
lib/config/app_screens.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/models/app_route.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
|
||||
final appScreens = [
|
||||
AppRoute(
|
||||
icon: Icons.link_rounded,
|
||||
route: RoutesPaths.links,
|
||||
name: t.links.links,
|
||||
),
|
||||
AppRoute(
|
||||
icon: Icons.search_rounded,
|
||||
route: RoutesPaths.search,
|
||||
name: t.search.search,
|
||||
),
|
||||
AppRoute(
|
||||
icon: Icons.settings_rounded,
|
||||
route: RoutesPaths.settings,
|
||||
name: t.settings.settings,
|
||||
),
|
||||
];
|
||||
13
lib/models/app_route.dart
Normal file
13
lib/models/app_route.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppRoute {
|
||||
final IconData icon;
|
||||
final String route;
|
||||
final String name;
|
||||
|
||||
const AppRoute({
|
||||
required this.icon,
|
||||
required this.route,
|
||||
required this.name,
|
||||
});
|
||||
}
|
||||
@@ -27,49 +27,32 @@ final List<RouteBase> appRoutes = [
|
||||
path: RoutesPaths.webview,
|
||||
builder: (context, state) => WebView(bookmark: state.extra as Bookmark),
|
||||
),
|
||||
StatefulShellRoute.indexedStack(
|
||||
builder: (context, state, navigationShell) => Layout(
|
||||
navigationShell: navigationShell,
|
||||
ShellRoute(
|
||||
builder: (context, state, child) => Layout(
|
||||
state: state,
|
||||
child: child,
|
||||
),
|
||||
branches: [
|
||||
StatefulShellBranch(
|
||||
navigatorKey: linksNavigatorKey,
|
||||
initialLocation: RoutesPaths.links,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: RoutesPaths.links,
|
||||
builder: (context, state) => const Links(),
|
||||
),
|
||||
],
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: RoutesPaths.links,
|
||||
builder: (context, state) => const Links(),
|
||||
),
|
||||
StatefulShellBranch(
|
||||
navigatorKey: searchNavigatorKey,
|
||||
initialLocation: RoutesPaths.search,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: RoutesPaths.search,
|
||||
builder: (context, state) => const Search(),
|
||||
),
|
||||
],
|
||||
GoRoute(
|
||||
path: RoutesPaths.search,
|
||||
builder: (context, state) => const Search(),
|
||||
),
|
||||
StatefulShellBranch(
|
||||
navigatorKey: settingsNavigatorKey,
|
||||
initialLocation: RoutesPaths.settings,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: RoutesPaths.settings,
|
||||
builder: (context, state) => const Settings(),
|
||||
),
|
||||
GoRoute(
|
||||
path: RoutesPaths.customization,
|
||||
builder: (context, state) => const Customization(),
|
||||
),
|
||||
GoRoute(
|
||||
path: RoutesPaths.generalSettings,
|
||||
builder: (context, state) => const GeneralSettings(),
|
||||
),
|
||||
],
|
||||
GoRoute(
|
||||
path: RoutesPaths.settings,
|
||||
builder: (context, state) => const Settings(),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: RoutesPaths.customization,
|
||||
builder: (context, state) => const Customization(),
|
||||
),
|
||||
GoRoute(
|
||||
path: RoutesPaths.generalSettings,
|
||||
builder: (context, state) => const GeneralSettings(),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -94,13 +94,17 @@ class Links extends ConsumerWidget {
|
||||
ListTile(
|
||||
onTap: () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: link),
|
||||
isThreeLine: true,
|
||||
title: Text(
|
||||
validateStrings(link?.title, link?.websiteTitle),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
validateStrings(link?.title, link?.websiteTitle),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
String colorTranslation(int index) {
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import 'package:animations/animations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
import 'package:linkdy/widgets/system_overlay_style.dart';
|
||||
|
||||
class Layout extends StatelessWidget {
|
||||
final StatefulNavigationShell navigationShell;
|
||||
import 'package:linkdy/config/app_screens.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
|
||||
class Layout extends ConsumerWidget {
|
||||
final GoRouterState state;
|
||||
final Widget child;
|
||||
|
||||
const Layout({
|
||||
Key? key,
|
||||
required this.navigationShell,
|
||||
required this.state,
|
||||
required this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void goBranch(int index) {
|
||||
navigationShell.goBranch(
|
||||
index,
|
||||
initialLocation: index == navigationShell.currentIndex,
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final screenIndex = appScreens.map((s) => s.route).toList().indexOf("/${state.matchedLocation.split("/")[1]}");
|
||||
|
||||
return OverlayStyle(
|
||||
child: Scaffold(
|
||||
@@ -31,25 +31,19 @@ class Layout extends StatelessWidget {
|
||||
secondaryAnimation: secondaryAnimation,
|
||||
child: child,
|
||||
),
|
||||
child: navigationShell,
|
||||
child: child,
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
onDestinationSelected: (s) => goBranch(s),
|
||||
selectedIndex: navigationShell.currentIndex,
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.link_rounded),
|
||||
label: t.links.links,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.search_rounded),
|
||||
label: t.search.search,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.settings_rounded),
|
||||
label: t.settings.settings,
|
||||
),
|
||||
],
|
||||
onDestinationSelected: (s) => ref.watch(routerProvider).replace(appScreens[s].route),
|
||||
selectedIndex: screenIndex,
|
||||
destinations: appScreens
|
||||
.map(
|
||||
(screen) => NavigationDestination(
|
||||
icon: Icon(screen.icon),
|
||||
label: screen.name,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user