Router changes

This commit is contained in:
Juan Gilsanz Polo
2024-02-23 13:06:53 +01:00
parent 25d0e230c6
commit f1e5e3ec71
6 changed files with 91 additions and 76 deletions

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

View File

@@ -27,39 +27,26 @@ 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(),
),
],
),
StatefulShellBranch(
navigatorKey: searchNavigatorKey,
initialLocation: RoutesPaths.search,
routes: [
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(),
@@ -68,8 +55,4 @@ final List<RouteBase> appRoutes = [
path: RoutesPaths.generalSettings,
builder: (context, state) => const GeneralSettings(),
),
],
),
],
),
];

View File

@@ -94,15 +94,19 @@ class Links extends ConsumerWidget {
ListTile(
onTap: () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: link),
isThreeLine: true,
title: Text(
title: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text(
validateStrings(link?.title, link?.websiteTitle),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 18,
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
subtitle: Column(
children: [
Text(

View File

@@ -1,5 +1,3 @@
import 'package:flutter/material.dart';
import 'package:linkdy/i18n/strings.g.dart';
String colorTranslation(int index) {

View File

@@ -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,
onDestinationSelected: (s) => ref.watch(routerProvider).replace(appScreens[s].route),
selectedIndex: screenIndex,
destinations: appScreens
.map(
(screen) => NavigationDestination(
icon: Icon(screen.icon),
label: screen.name,
),
NavigationDestination(
icon: const Icon(Icons.search_rounded),
label: t.search.search,
),
NavigationDestination(
icon: const Icon(Icons.settings_rounded),
label: t.settings.settings,
),
],
)
.toList(),
),
),
);