Skip to content

Commit 09461be

Browse files
feat: Set up routing using Get.
feat: Set up routing using `Get`.
2 parents b0a3743 + 6bdc20b commit 09461be

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

lib/data/constants/routes.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
1+
/// Constant strings representing the names of the routes for easy refactoring.
2+
class AppRoutes {
3+
static const String splash = '/';
4+
static const String login = '/login';
5+
static const String home = '/home';
6+
}

lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Future<void> _initFirebase() async {
5353
final notification = message.notification;
5454
if (notification != null) {
5555
debugPrint(
56-
'title: ${notification.title} \t body: ${notification.body}');
56+
'title: ${notification.title} \t body: ${notification.body}',
57+
);
5758
}
5859
},
5960
);

lib/presentation/core/main_app.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import 'package:flutter/material.dart';
2+
import 'package:get/get.dart';
3+
import 'package:sentry_flutter/sentry_flutter.dart';
4+
5+
import 'router.dart';
26

37
class Codephile extends StatelessWidget {
48
const Codephile({Key? key}) : super(key: key);
59

610
@override
711
Widget build(BuildContext context) {
8-
return const MaterialApp(
12+
return GetMaterialApp(
913
debugShowCheckedModeBanner: false,
14+
// home: const SplashScreen(),
15+
navigatorObservers: <NavigatorObserver>[
16+
SentryNavigatorObserver(),
17+
],
18+
onGenerateRoute: AppRouter.generateRoute,
19+
title: 'Codephile',
1020
);
1121
}
1222

lib/presentation/core/router.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:get/get.dart';
13

4+
import '../../data/constants/routes.dart';
5+
6+
/// Wrapper for a single method to be passed to [GetMaterialApp.onGenerateRoute].
7+
class AppRouter {
8+
static Route<dynamic> generateRoute(RouteSettings settings) {
9+
switch (settings.name) {
10+
case AppRoutes.splash:
11+
return GetPageRoute(
12+
// page: () => const SplashScreen(),
13+
routeName: settings.name,
14+
settings: settings,
15+
);
16+
case AppRoutes.home:
17+
return GetPageRoute(
18+
// page: () => const HomeScreen(),
19+
routeName: settings.name,
20+
settings: settings,
21+
);
22+
case AppRoutes.login:
23+
return GetPageRoute(
24+
// page: () => const LoginScreen(),
25+
routeName: settings.name,
26+
settings: settings,
27+
);
28+
default:
29+
return GetPageRoute(
30+
page: () => Scaffold(
31+
body: Center(
32+
child: Text(
33+
'No route defined for '
34+
'${settings.name}',
35+
),
36+
),
37+
),
38+
routeName: '/undefined',
39+
settings: settings,
40+
);
41+
}
42+
}
43+
}

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ packages:
324324
url: "https://pub.dartlang.org"
325325
source: hosted
326326
version: "2.1.2"
327+
get:
328+
dependency: "direct main"
329+
description:
330+
name: get
331+
url: "https://pub.dartlang.org"
332+
source: hosted
333+
version: "4.6.1"
327334
glob:
328335
dependency: transitive
329336
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
sdk: flutter
1818
flutter_bloc: ^8.0.1
1919
freezed_annotation: ^1.1.0
20+
get: ^4.6.1
2021
hive_flutter: ^1.1.0
2122
hydrated_bloc: ^8.0.0
2223
json_annotation: ^4.4.0

0 commit comments

Comments
 (0)