{"id":32302244,"url":"https://github.com/bitsydarel/db_navigator","last_synced_at":"2025-10-23T05:56:00.411Z","repository":{"id":37073222,"uuid":"392795418","full_name":"bitsydarel/db_navigator","owner":"bitsydarel","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-10T08:40:26.000Z","size":155,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T05:55:38.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause-clear","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitsydarel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-04T18:47:39.000Z","updated_at":"2025-04-10T08:40:31.000Z","dependencies_parsed_at":"2022-06-24T20:01:45.064Z","dependency_job_id":null,"html_url":"https://github.com/bitsydarel/db_navigator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bitsydarel/db_navigator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsydarel%2Fdb_navigator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsydarel%2Fdb_navigator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsydarel%2Fdb_navigator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsydarel%2Fdb_navigator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitsydarel","download_url":"https://codeload.github.com/bitsydarel/db_navigator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsydarel%2Fdb_navigator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280569893,"owners_count":26352860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-23T05:55:59.404Z","updated_at":"2025-10-23T05:56:00.403Z","avatar_url":"https://github.com/bitsydarel.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DB Navigator\n\n## Introduction\n\nDB Navigator is a Flutter package designed to simplify navigation within Flutter applications. It provides a structured approach to managing routes and pages, making it easier to navigate between screens and manage complex navigation flows.\n\n## Installation\n\nRefer to the [install instructions](https://pub.dev/packages/db_navigator/install)\n\n## Getting Started\n\n### Create a screen\n\nA screen is a User Interface component that can act as a navigation destination. This could be a Flutter widget that usually occupies the entire screen viewport. \n\n**home_screen.dart**.\n\n```dart\nclass HomeScreen extends StatelessWidget {\n  const HomeScreen({super.key});\n\n  /// URL Path for this screen\n  static const String path = '/home';\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(title: const Text('Home')),\n    );\n  }\n}\n```\n\n### Create a DBPageBuilder\n\nA [`DBPageBuilder`](https://pub.dev/documentation/db_navigator/latest/db_navigator/DBPageBuilder-class.html) should be defined for each screen in your application. `DBPageBuilder` builds `DBPage` from `Destination` paths.\n\nHere's an example of how to define a basic page builder for the home screen\n\n**home_page_builder.dart**\n\n```dart\nclass HomePageBuilder extends DBPageBuilder {\n  // Implementation details follow...\n}\n```\n\n### Implement Methods for DBPageBuilder\n\nYour page builder must implement two methods from the `DBPageBuilder` class\n- `buildPage`: Returns a `Future\u003cDBPage\u003e` for different `destination`\n- `supportRoute`: Returns a `bool` to indicate whether a specific destination should be handled by a the builder\n\nAdditionally, its a common practice to define an initial page that will be reused across different parts of the application. This can be done by setting a static `initialPage` in your page builder class.\n\n```dart\nclass HomePageBuilder extends DBPageBuilder {\n  static final DBPage initialPage = DBMaterialPage(\n    key: const ValueKey(HomeScreen.path),\n    destination: const Destination(path: HomeScreen.path),\n    child: const HomeScreen(),\n  );\n\n  @override\n  Future\u003cDBPage\u003e buildPage(Destination destination) {\n    return switch (destination.path) {\n      HomeScreen.path =\u003e SynchronousFuture(initialPage),\n      _ =\u003e Future.error(PageNotFoundException(destination))\n    };\n  }\n\n  @override\n  bool supportRoute(Destination destination) {\n    return destination.path == HomeScreen.path;\n  }\n}\n```\n\n### Integrating the Builder with the Router\n\nTo use the page builder within the application, you will need to integrate it with the router setup. This involves creating a `DBRouterDelegate` and configuring it with your page builders and initial page.\n\n#### Configuring the Router Delegate\n\n```dart\nDBRouterDelegate(\n  pageBuilders: \u003cDBPageBuilder\u003e[\n    HomePageBuilder(),\n  ],\n  initialPage: HomePageBuilder.initialPage,\n)\n```\n\n#### Setting up Route Information Provider\n\nEnsure your application is correctly set up to handle route information by providing a `PlatformRouteInformationProvider`.\n\n```dart\nPlatformRouteInformationProvider(\n  initialRouteInformation: HomePageBuilder\n       .initialPage\n       .destination\n       .toRouteInformation(),\n)\n```\n\n#### Complete Router Configuration\n\nFinally, configure your `MaterialApp.router` to use the `DBNavigator` components.\n\n```dart\nclass MainApp extends StatelessWidget {\n  const MainApp();\n\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp.router(\n      routeInformationParser: const DBRouteInformationParser(),\n      routerDelegate: DBRouterDelegate(\n        pageBuilders: \u003cDBPageBuilder\u003e[\n          HomePageBuilder(),\n        ],\n        initialPage: HomePageBuilder.initialPage,\n      ),\n      routeInformationProvider: PlatformRouteInformationProvider(\n        initialRouteInformation: HomePageBuilder\n           .initialPage\n           .destination\n           .toRouteInformation(),\n      ),\n    );\n  }\n}\n```\n\nNavigation within your app can now be performed using the `DBRouterDelegate`'s `navigateTo` method.\n\n```dart\nDBRouterDelegate.of(context).navigateTo(location: ProfileScreen.path);\n```\n\n## Advanced Features\n\n### Passing Arguments\n\nDB Navigator allows you to pass arguments to navigated routes. This is achieved by utilizing the `arguments` parameter during navigation. \n\n```dart\nDBRouterDelegate.of(context).navigateTo(\n  location: ProfileScreen.path, \n  arguments: User(name: 'John Doe'),\n);\n```\n\nHowever, since this parameter is not type-safe, you'll need to perform type checking within your page builder.\n\n```dart\n(Destination destination) {\n    final Object? arguments = destination.metadata.arguments;\n    assert(arguments is User, 'Argument not of type User');\n    final user = arguments as User;\n    return DBMaterialPage(\n        //...\n        child: ProfileScreen(user: user),\n    );\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsydarel%2Fdb_navigator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitsydarel%2Fdb_navigator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsydarel%2Fdb_navigator/lists"}