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