-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 135454af32477f815a7525073027a3ff9eff1bfd | ||
channel: stable | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 | ||
|
||
* Initial pre-release |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
A simple navigation resolver. | ||
|
||
> this library is currently in WIP | ||
## Features | ||
|
||
TODO: List what your package can do. Maybe include images, gifs, or videos. | ||
|
||
## Getting started | ||
|
||
Add dependency to project: | ||
|
||
```bash | ||
flutter pub add simple_nav --git-url=https://github.com/pedrox-hs/flutter_packages --git-path=simple_nav | ||
``` | ||
|
||
## Usage | ||
|
||
TODO: Include short and useful examples for package users. Add longer examples | ||
to `/example` folder. | ||
|
||
```dart | ||
const like = 'sample'; | ||
``` | ||
|
||
## Additional information | ||
|
||
TODO: Tell users more about the package: where to find more information, how to | ||
contribute to the package, how to file issues, what response they can expect | ||
from the package authors, and more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: ../flutter_lints.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
library simple_nav; | ||
|
||
export 'src/route_resolver.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
typedef PageBuilder = Widget Function( | ||
BuildContext context, | ||
RouteExtras extras, | ||
); | ||
|
||
class RouteResolver { | ||
RouteResolver(this.routes); | ||
|
||
final Map<String, PageBuilder> routes; | ||
|
||
Route<dynamic>? call(RouteSettings settings) { | ||
final result = _findRoute(settings.name!); | ||
if (result == null) return null; | ||
|
||
final extras = RouteExtras(result.arguments, settings.arguments); | ||
return MaterialPageRoute( | ||
settings: settings, | ||
builder: (context) => result.pageBuilder(context, extras), | ||
); | ||
} | ||
|
||
PageBuilderResult? _findRoute(String routeName) { | ||
final uri = Uri.parse(routeName); | ||
|
||
if (routes.containsKey(uri.path)) { | ||
return PageBuilderResult(routes[uri.path]!, {...uri.queryParameters}); | ||
} | ||
|
||
for (final String route in routes.keys) { | ||
if (!route.contains(':')) continue; | ||
|
||
final expr = route.replaceAllMapped( | ||
RegExp(':([^/]+)'), | ||
(m) => '(?<${m[1]}>[^/]+)', | ||
); | ||
final match = RegExp(expr).firstMatch(uri.path); | ||
if (match == null) continue; | ||
|
||
final arguments = { | ||
for (final key in match.groupNames) key: match.namedGroup(key) | ||
}; | ||
|
||
return PageBuilderResult( | ||
routes[route]!, | ||
{...uri.queryParameters, ...arguments}, | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
class PageBuilderResult { | ||
PageBuilderResult(this.pageBuilder, [this.arguments = const {}]); | ||
|
||
final PageBuilder pageBuilder; | ||
final Map<String, dynamic> arguments; | ||
} | ||
|
||
class RouteExtras { | ||
RouteExtras(this.arguments, this.data); | ||
|
||
final Map<String, dynamic> arguments; | ||
final dynamic data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: simple_nav | ||
description: A new Flutter package project. | ||
version: 0.1.0 | ||
homepage: https://github.com/pedrox-hs/flutter_packages | ||
repository: https://github.com/pedrox-hs/flutter_packages/tree/main/simple_nav | ||
|
||
environment: | ||
sdk: '>=2.12.0 <3.0.0' | ||
flutter: ">=1.17.0" | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
flutter_lints: ^1.0.0 | ||
|
||
# For information on the generic Dart part of this file, see the | ||
# following page: https://dart.dev/tools/pub/pubspec | ||
|
||
# The following section is specific to Flutter packages. | ||
flutter: | ||
|
||
# To add assets to your package, add an assets section, like this: | ||
# assets: | ||
# - images/a_dot_burr.jpeg | ||
# - images/a_dot_ham.jpeg | ||
# | ||
# For details regarding assets in packages, see | ||
# https://flutter.dev/assets-and-images/#from-packages | ||
# | ||
# An image asset can refer to one or more resolution-specific "variants", see | ||
# https://flutter.dev/assets-and-images/#resolution-aware | ||
|
||
# To add custom fonts to your package, add a fonts section here, | ||
# in this "flutter" section. Each entry in this list should have a | ||
# "family" key with the font family name, and a "fonts" key with a | ||
# list giving the asset and other descriptors for the font. For | ||
# example: | ||
# fonts: | ||
# - family: Schyler | ||
# fonts: | ||
# - asset: fonts/Schyler-Regular.ttf | ||
# - asset: fonts/Schyler-Italic.ttf | ||
# style: italic | ||
# - family: Trajan Pro | ||
# fonts: | ||
# - asset: fonts/TrajanPro.ttf | ||
# - asset: fonts/TrajanPro_Bold.ttf | ||
# weight: 700 | ||
# | ||
# For details regarding fonts in packages, see | ||
# https://flutter.dev/custom-fonts/#from-packages |