Skip to content

Commit cea552c

Browse files
committed
refactor: Improved navigation with go_router
- Configured routes for headlines - Added routes for search - Integrated AppScaffold
1 parent 31fa310 commit cea552c

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

lib/app/view/app_scaffold.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:ht_main/router/routes.dart';
35

46
class AppScaffold extends StatelessWidget {
5-
const AppScaffold({super.key});
7+
const AppScaffold({required this.child, super.key});
8+
9+
final Widget child;
610

711
@override
812
Widget build(BuildContext context) {
913
return AdaptiveScaffold(
10-
// NAVIGATION
1114
useDrawer: false,
1215
destinations: const [
1316
NavigationDestination(
1417
icon: Icon(Icons.view_headline),
1518
label: 'Headlines',
19+
selectedIcon: Icon(Icons.view_headline),
1620
),
1721
NavigationDestination(
1822
icon: Icon(Icons.search),
1923
label: 'Search',
24+
selectedIcon: Icon(Icons.search),
2025
),
2126
],
22-
// MAIN BODY
23-
smallBody: (context) => const Placeholder(),
24-
body: (context) => const Placeholder(),
25-
largeBody: (context) => const Placeholder(),
26-
27-
// SECONDARY BODY
27+
smallBody: (_) => child,
28+
body: (_) => child,
29+
largeBody: (_) => child,
2830
smallSecondaryBody: AdaptiveScaffold.emptyBuilder,
2931
secondaryBody: AdaptiveScaffold.emptyBuilder,
3032
largeSecondaryBody: AdaptiveScaffold.emptyBuilder,
33+
onSelectedIndexChange: (index) {
34+
if (index == 0) {
35+
context.go(Routes.headlines);
36+
} else if (index == 1) {
37+
context.go(Routes.search);
38+
}
39+
},
3140
);
3241
}
3342
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:flutter/material.dart';
2+
3+
class HeadlinesPage extends StatelessWidget {
4+
const HeadlinesPage({super.key});
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return const Placeholder(); // Placeholder for now
9+
}
10+
}

lib/router/router.dart

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import 'package:flutter/material.dart';
22
import 'package:go_router/go_router.dart';
33
import 'package:ht_main/app/view/app_scaffold.dart';
4+
import 'package:ht_main/router/routes.dart';
5+
import 'package:ht_main/search/search.dart';
46

57
final appRouter = GoRouter(
68
routes: [
7-
GoRoute(
8-
path: '/',
9-
builder: (BuildContext context, GoRouterState state) {
10-
return const AppScaffold();
9+
ShellRoute(
10+
builder: (context, state, child) {
11+
return AppScaffold(child: child);
1112
},
13+
routes: [
14+
GoRoute(
15+
path: Routes.headlines,
16+
builder: (BuildContext context, GoRouterState state) {
17+
return const Placeholder(); // Use Placeholder for Headlines
18+
},
19+
),
20+
GoRoute(
21+
path: Routes.search,
22+
builder: (BuildContext context, GoRouterState state) {
23+
return const SearchPage();
24+
},
25+
),
26+
],
1227
),
1328
],
1429
);

lib/router/routes.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abstract final class Routes {
2+
static const home = '/';
3+
static const headlines = '/headlines';
4+
static const search = '/search';
5+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ht_main
22
description: main headlines toolkit mobile app.
3-
version: 0.3.0
3+
version: 0.3.1
44
publish_to: none
55
repository: https://github.com/Headlines-Toolkit/ht-main
66
environment:

0 commit comments

Comments
 (0)