Skip to content

Commit

Permalink
feat[app_router]: add go_router_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
MahanRahmati committed Sep 17, 2023
1 parent 1f5d4e7 commit bbadacf
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This boilerplate includes several common dependencies that you may find useful w
| :----------------------------------------------------------------------- | :---------------------------------------------- |
| [riverpod](https://pub.dev/packages/riverpod/) | State Manager |
| [go_router](https://pub.dev/packages/go_router/) | Routing |
| [go_router_builder](https://pub.dev/packages/go_router_builder/) | Routing |
| [hive](https://pub.dev/packages/hive/) | Storage |
| [intl](https://pub.dev/packages/intl/) | Internationalization and Localization |
| [arna_logger](https://pub.dev/packages/arna_logger/) | Logger |
Expand Down
1 change: 1 addition & 0 deletions packages/app_providers/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.3

riverpod_generator: ^2.3.2
build_runner: ^2.4.6
custom_lint: ^0.5.3
Expand Down
8 changes: 1 addition & 7 deletions packages/app_router/lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
///
/// It exports the GoRouter package which provides the routing functionality.
///
/// It also exports:
///
/// - routes.dart - Defines the routes used in the app.
/// - routes_name.dart - Route name constants.
/// - routes_path.dart - Route path constants.
/// It exports the routes.dart which defines the routes used in the app.
///
/// By exporting these files, the router configuration is shared with the
/// rest of the app.
Expand All @@ -15,5 +11,3 @@ library app_router;
export 'package:go_router/go_router.dart';

export 'src/routes.dart';
export 'src/routes_name.dart';
export 'src/routes_path.dart';
71 changes: 49 additions & 22 deletions packages/app_router/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,62 @@ import 'package:screen_splash/screen_splash.dart';
import 'routes_name.dart';
import 'routes_path.dart';

part 'routes.g.dart';

/// Routes class defines the router for the application.
///
/// The router is created using the GoRouter package and contains
/// the defined routes for the app.
///
/// The routes use the route names from [RoutesName] and paths
/// from [RoutesPath] for consistency.
///
/// The builder for each route returns the screen widget to display
/// for that route.
class Routes {
Routes._();

static final GoRouter router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: RoutesPath.splash,
name: RoutesName.splash,
builder: (final BuildContext context, final GoRouterState state) {
return const SplashScreen();
},
),
GoRoute(
path: RoutesPath.home,
name: RoutesName.home,
builder: (final BuildContext context, final GoRouterState state) {
return const HomeScreen();
},
),
],
routes: $appRoutes,
);
}

/// SplashRoute defines the route for displaying the splash screen.
///
/// This class extends [GoRouteData] to create a typed route definition.
///
/// The splash screen is displayed when the app is first launched while
/// it initializes and determines which screen to navigate to next.
///
/// The [build] method returns a [SplashScreen] widget to display.
///
/// This route does not take any parameters.
@TypedGoRoute<SplashRoute>(
path: RoutesPath.splash,
name: RoutesName.splash,
)
class SplashRoute extends GoRouteData {
const SplashRoute();

@override
Widget build(final BuildContext context, final GoRouterState state) {
return const SplashScreen();
}
}

/// HomeRoute defines the route to the main home screen.
///
/// This class extends [GoRouteData] to create a typed route definition.
///
/// The home screen is the main screen displayed after the splash screen.
/// It is the central screen that users will interact with most.
///
/// The [build] method returns the [HomeScreen] widget to display.
///
/// This route does not take any parameters.
@TypedGoRoute<HomeRoute>(
path: RoutesPath.home,
name: RoutesName.home,
)
class HomeRoute extends GoRouteData {
const HomeRoute();

@override
Widget build(final BuildContext context, final GoRouterState state) {
return const HomeScreen();
}
}
58 changes: 58 additions & 0 deletions packages/app_router/lib/src/routes.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bbadacf

Please sign in to comment.