New Wyatt GoRouter Package #232
							
								
								
									
										1
									
								
								packages/wyatt_go_router/.gitignore
									
									
									
									
										vendored
									
									
										Symbolic link
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| ../../.gitignore | ||||
							
								
								
									
										1
									
								
								packages/wyatt_go_router/.pubignore
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| ../../.pubignore | ||||
							
								
								
									
										34
									
								
								packages/wyatt_go_router/.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,34 @@ | ||||
| /* | ||||
|  * Copyright (C) 2023 WYATT GROUP | ||||
|  * Please see the AUTHORS file for details. | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
|  * GNU General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| 
 | ||||
| { | ||||
|     // Use IntelliSense to learn about possible attributes. | ||||
|     // Hover to view descriptions of existing attributes. | ||||
|     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||||
|     "version": "0.2.0", | ||||
|     "configurations": [ | ||||
|         { | ||||
|             "name": "Launch Example", | ||||
|             "request": "launch", | ||||
|             "type": "dart", | ||||
|             "cwd": "example/", | ||||
|             "program": "lib/main.dart", | ||||
|             "flutterMode": "debug" | ||||
|         }, | ||||
|     ] | ||||
| } | ||||
							
								
								
									
										72
									
								
								packages/wyatt_go_router/.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,72 @@ | ||||
| { | ||||
|   "dart.runPubGetOnPubspecChanges": "never", | ||||
|   "bloc.newCubitTemplate.type": "equatable", | ||||
|   "psi-header.changes-tracking": { | ||||
|     "isActive": true | ||||
|   }, | ||||
|   "psi-header.config": { | ||||
|     "blankLinesAfter": 1, | ||||
|     "forceToTop": true | ||||
|   }, | ||||
|   "psi-header.lang-config": [ | ||||
|     { | ||||
|       "beforeHeader": [ | ||||
|         "# -*- coding:utf-8 -*-", | ||||
|         "#!/usr/bin/env python3" | ||||
|       ], | ||||
|       "begin": "###", | ||||
|       "end": "###", | ||||
|       "language": "python", | ||||
|       "prefix": "# " | ||||
|     }, | ||||
|     { | ||||
|       "beforeHeader": [ | ||||
|         "#!/usr/bin/env sh", | ||||
|         "" | ||||
|       ], | ||||
|       "language": "shellscript", | ||||
|       "begin": "", | ||||
|       "end": "", | ||||
|       "prefix": "# " | ||||
|     }, | ||||
|     { | ||||
|       "begin": "", | ||||
|       "end": "", | ||||
|       "language": "dart", | ||||
|       "prefix": "// " | ||||
|     }, | ||||
|     { | ||||
|       "begin": "", | ||||
|       "end": "", | ||||
|       "language": "yaml", | ||||
|       "prefix": "# " | ||||
|     }, | ||||
|     { | ||||
|       "begin": "<!--", | ||||
|       "end": "-->", | ||||
|       "language": "markdown", | ||||
|     }, | ||||
|   ], | ||||
|   "psi-header.templates": [ | ||||
|     { | ||||
|       "language": "*", | ||||
|       "template": [ | ||||
|         "Copyright (C) <<year>> WYATT GROUP", | ||||
|         "Please see the AUTHORS file for details.", | ||||
|         "", | ||||
|         "This program is free software: you can redistribute it and/or modify", | ||||
|         "it under the terms of the GNU General Public License as published by", | ||||
|         "the Free Software Foundation, either version 3 of the License, or", | ||||
|         "any later version.", | ||||
|         "", | ||||
|         "This program is distributed in the hope that it will be useful,", | ||||
|         "but WITHOUT ANY WARRANTY; without even the implied warranty of", | ||||
|         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", | ||||
|         "GNU General Public License for more details.", | ||||
|         "", | ||||
|         "You should have received a copy of the GNU General Public License", | ||||
|         "along with this program. If not, see <https://www.gnu.org/licenses/>." | ||||
|       ], | ||||
|     } | ||||
|   ], | ||||
| } | ||||
							
								
								
									
										1
									
								
								packages/wyatt_go_router/AUTHORS
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| ../../AUTHORS | ||||
							
								
								
									
										3
									
								
								packages/wyatt_go_router/CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,3 @@ | ||||
| ## 1.0.0 | ||||
| 
 | ||||
| - Initial version. | ||||
							
								
								
									
										1
									
								
								packages/wyatt_go_router/LICENSE
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| ../../LICENSE | ||||
							
								
								
									
										68
									
								
								packages/wyatt_go_router/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,68 @@ | ||||
| <!-- | ||||
|  * Copyright (C) 2023 WYATT GROUP | ||||
|  * Please see the AUTHORS file for details. | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful,  | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
|  * GNU General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| --> | ||||
| 
 | ||||
| # Flutter - Wyatt Go Router | ||||
| 
 | ||||
| <p align="left"> | ||||
|   <a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a> | ||||
|   <img src="https://img.shields.io/badge/SDK-Flutter-blue?style=flat-square" alt="SDK: Flutter" /> | ||||
| </p> | ||||
| 
 | ||||
| GoRouter Enhancements for Flutter | ||||
| 
 | ||||
| This package provides a set of utilities to help you use the [GoRouter](https://pub.dev/packages/go_router) package. | ||||
| 
 | ||||
| ## Features | ||||
| 
 | ||||
| * PageProtection extension to add a protection to a page | ||||
| * currentRoute method to get the current route anywhere in the app | ||||
| * GoRouterRefreshStream to refresh the router when needed | ||||
| * RouteBase flattenization to get a list of all the routes in the router | ||||
| 
 | ||||
| ## Usage | ||||
| 
 | ||||
| If you want to protect a page, you can use the PageProtection extension: | ||||
| 
 | ||||
| ```dart | ||||
| GoRoute( | ||||
|  path: '/sign_in', | ||||
|  ... | ||||
| )..setPublic(), | ||||
| ``` | ||||
| 
 | ||||
| If you want to get the current route, you can use the currentRoute method: | ||||
| 
 | ||||
| ```dart | ||||
| final route = GoRouter.of(context).currentRoute; | ||||
| // or | ||||
| final route = context.currentRoute; | ||||
| ``` | ||||
| 
 | ||||
| If you want to refresh the router, you can use the GoRouterRefreshStream: | ||||
| 
 | ||||
| ```dart | ||||
| GoRouterRefreshStream( | ||||
|   context.read<AuthenticationCubit<Session>>().stream, | ||||
| ) | ||||
| ``` | ||||
| 
 | ||||
| If you want to get a list of all the routes in the router, you can use the RouteBase flattenization: | ||||
| 
 | ||||
| ```dart | ||||
| final routes = GoRouter.of(context).flattenedRoutes; | ||||
| ``` | ||||
							
								
								
									
										27
									
								
								packages/wyatt_go_router/analysis_options.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,27 @@ | ||||
| include: package:wyatt_analysis/analysis_options.flutter.yaml | ||||
| 
 | ||||
| analyzer: | ||||
|   plugins: | ||||
|     - dart_code_linter | ||||
| 
 | ||||
| dart_code_linter: | ||||
|   anti-patterns: | ||||
|     - long-method | ||||
|     - long-parameter-list | ||||
|   metrics: | ||||
|     cyclomatic-complexity: 20 | ||||
|     maximum-nesting-level: 5 | ||||
|     number-of-parameters: 10 | ||||
|     source-lines-of-code: 400 | ||||
|   metrics-exclude: | ||||
|     - test/** | ||||
|   rules: | ||||
|     - newline-before-return | ||||
|     - no-boolean-literal-compare | ||||
|     - no-empty-block | ||||
|     - prefer-trailing-comma | ||||
|     - prefer-conditional-expressions | ||||
|     - no-equal-then-else | ||||
|     - avoid-border-all | ||||
|     - prefer-const-border-radius | ||||
|     - prefer-using-list-view | ||||
							
								
								
									
										44
									
								
								packages/wyatt_go_router/example/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,44 @@ | ||||
| # 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 | ||||
| **/doc/api/ | ||||
| **/ios/Flutter/.last_build_id | ||||
| .dart_tool/ | ||||
| .flutter-plugins | ||||
| .flutter-plugins-dependencies | ||||
| .packages | ||||
| .pub-cache/ | ||||
| .pub/ | ||||
| /build/ | ||||
| 
 | ||||
| # Symbolication related | ||||
| app.*.symbols | ||||
| 
 | ||||
| # Obfuscation related | ||||
| app.*.map.json | ||||
| 
 | ||||
| # Android Studio will place build artifacts here | ||||
| /android/app/debug | ||||
| /android/app/profile | ||||
| /android/app/release | ||||
							
								
								
									
										30
									
								
								packages/wyatt_go_router/example/.metadata
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,30 @@ | ||||
| # 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: "d211f42860350d914a5ad8102f9ec32764dc6d06" | ||||
|   channel: "stable" | ||||
| 
 | ||||
| project_type: app | ||||
| 
 | ||||
| # Tracks metadata for the flutter migrate command | ||||
| migration: | ||||
|   platforms: | ||||
|     - platform: root | ||||
|       create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 | ||||
|       base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 | ||||
|     - platform: android | ||||
|       create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 | ||||
|       base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 | ||||
| 
 | ||||
|   # User provided section | ||||
| 
 | ||||
|   # List of Local paths (relative to this file) that should be | ||||
|   # ignored by the migrate tool. | ||||
|   # | ||||
|   # Files that are not part of the templates will be ignored by default. | ||||
|   unmanaged_files: | ||||
|     - 'lib/main.dart' | ||||
|     - 'ios/Runner.xcodeproj/project.pbxproj' | ||||
							
								
								
									
										16
									
								
								packages/wyatt_go_router/example/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,16 @@ | ||||
| # example | ||||
| 
 | ||||
| A new Flutter project. | ||||
| 
 | ||||
| ## Getting Started | ||||
| 
 | ||||
| This project is a starting point for a Flutter application. | ||||
| 
 | ||||
| A few resources to get you started if this is your first Flutter project: | ||||
| 
 | ||||
| - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) | ||||
| - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) | ||||
| 
 | ||||
| For help getting started with Flutter development, view the | ||||
| [online documentation](https://docs.flutter.dev/), which offers tutorials, | ||||
| samples, guidance on mobile development, and a full API reference. | ||||
							
								
								
									
										7
									
								
								packages/wyatt_go_router/example/analysis_options.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,7 @@ | ||||
| 
 | ||||
| include: package:wyatt_analysis/analysis_options.flutter.yaml | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
							
								
								
									
										13
									
								
								packages/wyatt_go_router/example/android/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,13 @@ | ||||
| gradle-wrapper.jar | ||||
| /.gradle | ||||
| /captures/ | ||||
| /gradlew | ||||
| /gradlew.bat | ||||
| /local.properties | ||||
| GeneratedPluginRegistrant.java | ||||
| 
 | ||||
| # Remember to never publicly share your keystore. | ||||
| # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app | ||||
| key.properties | ||||
| **/*.keystore | ||||
| **/*.jks | ||||
							
								
								
									
										67
									
								
								packages/wyatt_go_router/example/android/app/build.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,67 @@ | ||||
| plugins { | ||||
|     id "com.android.application" | ||||
|     id "kotlin-android" | ||||
|     id "dev.flutter.flutter-gradle-plugin" | ||||
| } | ||||
| 
 | ||||
| def localProperties = new Properties() | ||||
| def localPropertiesFile = rootProject.file('local.properties') | ||||
| if (localPropertiesFile.exists()) { | ||||
|     localPropertiesFile.withReader('UTF-8') { reader -> | ||||
|         localProperties.load(reader) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | ||||
| if (flutterVersionCode == null) { | ||||
|     flutterVersionCode = '1' | ||||
| } | ||||
| 
 | ||||
| def flutterVersionName = localProperties.getProperty('flutter.versionName') | ||||
| if (flutterVersionName == null) { | ||||
|     flutterVersionName = '1.0' | ||||
| } | ||||
| 
 | ||||
| android { | ||||
|     namespace "com.example.example" | ||||
|     compileSdkVersion flutter.compileSdkVersion | ||||
|     ndkVersion flutter.ndkVersion | ||||
| 
 | ||||
|     compileOptions { | ||||
|         sourceCompatibility JavaVersion.VERSION_1_8 | ||||
|         targetCompatibility JavaVersion.VERSION_1_8 | ||||
|     } | ||||
| 
 | ||||
|     kotlinOptions { | ||||
|         jvmTarget = '1.8' | ||||
|     } | ||||
| 
 | ||||
|     sourceSets { | ||||
|         main.java.srcDirs += 'src/main/kotlin' | ||||
|     } | ||||
| 
 | ||||
|     defaultConfig { | ||||
|         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||||
|         applicationId "com.example.example" | ||||
|         // You can update the following values to match your application needs. | ||||
|         // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. | ||||
|         minSdkVersion flutter.minSdkVersion | ||||
|         targetSdkVersion flutter.targetSdkVersion | ||||
|         versionCode flutterVersionCode.toInteger() | ||||
|         versionName flutterVersionName | ||||
|     } | ||||
| 
 | ||||
|     buildTypes { | ||||
|         release { | ||||
|             // TODO: Add your own signing config for the release build. | ||||
|             // Signing with the debug keys for now, so `flutter run --release` works. | ||||
|             signingConfig signingConfigs.debug | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| flutter { | ||||
|     source '../..' | ||||
| } | ||||
| 
 | ||||
| dependencies {} | ||||
| @ -0,0 +1,7 @@ | ||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <!-- The INTERNET permission is required for development. Specifically, | ||||
|          the Flutter tool needs it to communicate with the running application | ||||
|          to allow setting breakpoints, to provide hot reload, etc. | ||||
|     --> | ||||
|     <uses-permission android:name="android.permission.INTERNET"/> | ||||
| </manifest> | ||||
| @ -0,0 +1,33 @@ | ||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <application | ||||
|         android:label="example" | ||||
|         android:name="${applicationName}" | ||||
|         android:icon="@mipmap/ic_launcher"> | ||||
|         <activity | ||||
|             android:name=".MainActivity" | ||||
|             android:exported="true" | ||||
|             android:launchMode="singleTop" | ||||
|             android:theme="@style/LaunchTheme" | ||||
|             android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||||
|             android:hardwareAccelerated="true" | ||||
|             android:windowSoftInputMode="adjustResize"> | ||||
|             <!-- Specifies an Android theme to apply to this Activity as soon as | ||||
|                  the Android process has started. This theme is visible to the user | ||||
|                  while the Flutter UI initializes. After that, this theme continues | ||||
|                  to determine the Window background behind the Flutter UI. --> | ||||
|             <meta-data | ||||
|               android:name="io.flutter.embedding.android.NormalTheme" | ||||
|               android:resource="@style/NormalTheme" | ||||
|               /> | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.intent.action.MAIN"/> | ||||
|                 <category android:name="android.intent.category.LAUNCHER"/> | ||||
|             </intent-filter> | ||||
|         </activity> | ||||
|         <!-- Don't delete the meta-data below. | ||||
|              This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||||
|         <meta-data | ||||
|             android:name="flutterEmbedding" | ||||
|             android:value="2" /> | ||||
|     </application> | ||||
| </manifest> | ||||
| @ -0,0 +1,6 @@ | ||||
| package com.example.example | ||||
| 
 | ||||
| import io.flutter.embedding.android.FlutterActivity | ||||
| 
 | ||||
| class MainActivity: FlutterActivity() { | ||||
| } | ||||
| @ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <!-- Modify this file to customize your launch splash screen --> | ||||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <item android:drawable="?android:colorBackground" /> | ||||
| 
 | ||||
|     <!-- You can insert your own image assets here --> | ||||
|     <!-- <item> | ||||
|         <bitmap | ||||
|             android:gravity="center" | ||||
|             android:src="@mipmap/launch_image" /> | ||||
|     </item> --> | ||||
| </layer-list> | ||||
| @ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <!-- Modify this file to customize your launch splash screen --> | ||||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <item android:drawable="@android:color/white" /> | ||||
| 
 | ||||
|     <!-- You can insert your own image assets here --> | ||||
|     <!-- <item> | ||||
|         <bitmap | ||||
|             android:gravity="center" | ||||
|             android:src="@mipmap/launch_image" /> | ||||
|     </item> --> | ||||
| </layer-list> | ||||
| After Width: | Height: | Size: 544 B | 
| After Width: | Height: | Size: 442 B | 
| After Width: | Height: | Size: 721 B | 
| After Width: | Height: | Size: 1.0 KiB | 
| After Width: | Height: | Size: 1.4 KiB | 
| @ -0,0 +1,18 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <resources> | ||||
|     <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on --> | ||||
|     <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||||
|         <!-- Show a splash screen on the activity. Automatically removed when | ||||
|              the Flutter engine draws its first frame --> | ||||
|         <item name="android:windowBackground">@drawable/launch_background</item> | ||||
|     </style> | ||||
|     <!-- Theme applied to the Android Window as soon as the process has started. | ||||
|          This theme determines the color of the Android Window while your | ||||
|          Flutter UI initializes, as well as behind your Flutter UI while its | ||||
|          running. | ||||
| 
 | ||||
|          This Theme is only used starting with V2 of Flutter's Android embedding. --> | ||||
|     <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> | ||||
|         <item name="android:windowBackground">?android:colorBackground</item> | ||||
|     </style> | ||||
| </resources> | ||||
| @ -0,0 +1,18 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <resources> | ||||
|     <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off --> | ||||
|     <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar"> | ||||
|         <!-- Show a splash screen on the activity. Automatically removed when | ||||
|              the Flutter engine draws its first frame --> | ||||
|         <item name="android:windowBackground">@drawable/launch_background</item> | ||||
|     </style> | ||||
|     <!-- Theme applied to the Android Window as soon as the process has started. | ||||
|          This theme determines the color of the Android Window while your | ||||
|          Flutter UI initializes, as well as behind your Flutter UI while its | ||||
|          running. | ||||
| 
 | ||||
|          This Theme is only used starting with V2 of Flutter's Android embedding. --> | ||||
|     <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar"> | ||||
|         <item name="android:windowBackground">?android:colorBackground</item> | ||||
|     </style> | ||||
| </resources> | ||||
| @ -0,0 +1,7 @@ | ||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <!-- The INTERNET permission is required for development. Specifically, | ||||
|          the Flutter tool needs it to communicate with the running application | ||||
|          to allow setting breakpoints, to provide hot reload, etc. | ||||
|     --> | ||||
|     <uses-permission android:name="android.permission.INTERNET"/> | ||||
| </manifest> | ||||
							
								
								
									
										31
									
								
								packages/wyatt_go_router/example/android/build.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,31 @@ | ||||
| buildscript { | ||||
|     ext.kotlin_version = '1.7.10' | ||||
|     repositories { | ||||
|         google() | ||||
|         mavenCentral() | ||||
|     } | ||||
| 
 | ||||
|     dependencies { | ||||
|         classpath 'com.android.tools.build:gradle:7.3.0' | ||||
|         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| allprojects { | ||||
|     repositories { | ||||
|         google() | ||||
|         mavenCentral() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| rootProject.buildDir = '../build' | ||||
| subprojects { | ||||
|     project.buildDir = "${rootProject.buildDir}/${project.name}" | ||||
| } | ||||
| subprojects { | ||||
|     project.evaluationDependsOn(':app') | ||||
| } | ||||
| 
 | ||||
| tasks.register("clean", Delete) { | ||||
|     delete rootProject.buildDir | ||||
| } | ||||
| @ -0,0 +1,3 @@ | ||||
| org.gradle.jvmargs=-Xmx1536M | ||||
| android.useAndroidX=true | ||||
| android.enableJetifier=true | ||||
							
								
								
									
										5
									
								
								packages/wyatt_go_router/example/android/gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,5 @@ | ||||
| distributionBase=GRADLE_USER_HOME | ||||
| distributionPath=wrapper/dists | ||||
| zipStoreBase=GRADLE_USER_HOME | ||||
| zipStorePath=wrapper/dists | ||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip | ||||
							
								
								
									
										20
									
								
								packages/wyatt_go_router/example/android/settings.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,20 @@ | ||||
| pluginManagement { | ||||
|     def flutterSdkPath = { | ||||
|         def properties = new Properties() | ||||
|         file("local.properties").withInputStream { properties.load(it) } | ||||
|         def flutterSdkPath = properties.getProperty("flutter.sdk") | ||||
|         assert flutterSdkPath != null, "flutter.sdk not set in local.properties" | ||||
|         return flutterSdkPath | ||||
|     } | ||||
|     settings.ext.flutterSdkPath = flutterSdkPath() | ||||
| 
 | ||||
|     includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") | ||||
| 
 | ||||
|     plugins { | ||||
|         id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| include ":app" | ||||
| 
 | ||||
| apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle" | ||||
							
								
								
									
										108
									
								
								packages/wyatt_go_router/example/lib/app_router.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,108 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/cupertino.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| import 'package:wyatt_go_router_example/bottom_bar.dart'; | ||||
| import 'package:wyatt_go_router_example/page_a.dart'; | ||||
| import 'package:wyatt_go_router_example/page_b.dart'; | ||||
| import 'package:wyatt_go_router_example/page_c.dart'; | ||||
| 
 | ||||
| abstract class AppRouter { | ||||
|   /// Default transition for all pages | ||||
|   static Page<void> defaultTransition( | ||||
|     BuildContext context, | ||||
|     GoRouterState state, | ||||
|     Widget child, | ||||
|   ) => | ||||
|       CupertinoPage<void>(key: state.pageKey, child: child); | ||||
| 
 | ||||
|   /// Disable transition animation | ||||
|   static Page<void> noTransition( | ||||
|     BuildContext context, | ||||
|     GoRouterState state, | ||||
|     Widget child, | ||||
|   ) => | ||||
|       NoTransitionPage(key: state.pageKey, child: child); | ||||
| 
 | ||||
|   static final GlobalKey<NavigatorState> rootNavigatorKey = | ||||
|       GlobalKey<NavigatorState>(); | ||||
|   static final GlobalKey<NavigatorState> shellNavigatorKey = | ||||
|       GlobalKey<NavigatorState>(); | ||||
| 
 | ||||
|   /// Defines GoRoute routes. | ||||
|   static final List<RouteBase> routes = [ | ||||
|     ShellRoute( | ||||
|       navigatorKey: shellNavigatorKey, | ||||
|       builder: (context, state, child) { | ||||
|         final currentRoute = context.currentRoute; | ||||
| 
 | ||||
|         return Scaffold( | ||||
|           appBar: AppBar( | ||||
|             title: Text( | ||||
|               currentRoute.name ?? 'Unknown', | ||||
|             ), | ||||
|           ), | ||||
|           body: child, | ||||
|           bottomNavigationBar: BottomBar( | ||||
|             currentRoute: currentRoute, | ||||
|           ), | ||||
|         ); | ||||
|       }, | ||||
|       routes: [ | ||||
|         GoRoute( | ||||
|           path: '/page-a', | ||||
|           name: 'A', | ||||
|           pageBuilder: (context, state) => noTransition( | ||||
|             context, | ||||
|             state, | ||||
|             const PageA(), | ||||
|           ), | ||||
|         ), | ||||
|         GoRoute( | ||||
|           path: '/page-b', | ||||
|           name: 'B', | ||||
|           pageBuilder: (context, state) => noTransition( | ||||
|             context, | ||||
|             state, | ||||
|             const PageB(), | ||||
|           ), | ||||
|         ), | ||||
|       ], | ||||
|     ), | ||||
|     GoRoute( | ||||
|       path: '/page-c', | ||||
|       name: 'C', | ||||
|       parentNavigatorKey: rootNavigatorKey, | ||||
|       pageBuilder: (context, state) => defaultTransition( | ||||
|         context, | ||||
|         state, | ||||
|         const PageC(), | ||||
|       ), | ||||
|     ), | ||||
|   ]; | ||||
| 
 | ||||
|   static GoRouter? _router; | ||||
| 
 | ||||
|   /// Returns the router. | ||||
|   static GoRouter routerOf(BuildContext context) => _router ??= GoRouter( | ||||
|         initialLocation: '/page-a', | ||||
|         routes: AppRouter.routes, | ||||
|         navigatorKey: rootNavigatorKey, | ||||
|         debugLogDiagnostics: true, | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										47
									
								
								packages/wyatt_go_router/example/lib/bottom_bar.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,47 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| class BottomBar extends StatelessWidget { | ||||
|   const BottomBar({ | ||||
|     required this.currentRoute, | ||||
|     super.key, | ||||
|   }); | ||||
| 
 | ||||
|   final GoRoute currentRoute; | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => BottomNavigationBar( | ||||
|         items: const [ | ||||
|           BottomNavigationBarItem( | ||||
|             icon: Icon(Icons.home), | ||||
|             label: 'Home', | ||||
|           ), | ||||
|           BottomNavigationBarItem( | ||||
|             icon: Icon(Icons.settings), | ||||
|             label: 'Settings', | ||||
|           ), | ||||
|         ], | ||||
|         currentIndex: (currentRoute.name == 'A') ? 0 : 1, | ||||
|         onTap: (index) => switch (index) { | ||||
|           0 => context.goNamed('A'), | ||||
|           1 => context.goNamed('B'), | ||||
|           _ => throw Exception('Invalid index: $index'), | ||||
|         }, | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										34
									
								
								packages/wyatt_go_router/example/lib/main.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,34 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router_example/app_router.dart'; | ||||
| 
 | ||||
| void main(List<String> args) { | ||||
|   runApp(const App()); | ||||
| } | ||||
| 
 | ||||
| class App extends StatelessWidget { | ||||
|   const App({super.key}); | ||||
| 
 | ||||
|   static const String title = 'Wyatt Go Router Example'; | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => MaterialApp.router( | ||||
|         title: title, | ||||
|         routerConfig: AppRouter.routerOf(context), | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										30
									
								
								packages/wyatt_go_router/example/lib/page_a.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,30 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| class PageA extends StatelessWidget { | ||||
|   const PageA({super.key}); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Center( | ||||
|         child: Text( | ||||
|           'Page A: ${context.currentRoute}', | ||||
|           style: Theme.of(context).textTheme.headlineMedium, | ||||
|         ), | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										40
									
								
								packages/wyatt_go_router/example/lib/page_b.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,40 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| class PageB extends StatelessWidget { | ||||
|   const PageB({super.key}); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Center( | ||||
|         child: Column( | ||||
|           mainAxisAlignment: MainAxisAlignment.center, | ||||
|           children: [ | ||||
|             Text( | ||||
|               'Page B: ${context.currentRoute}', | ||||
|               style: Theme.of(context).textTheme.headlineMedium, | ||||
|             ), | ||||
|             const SizedBox(height: 16), | ||||
|             ElevatedButton( | ||||
|               onPressed: () => context.pushNamed('C'), | ||||
|               child: const Text('Go to Page C'), | ||||
|             ), | ||||
|           ], | ||||
|         ), | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										35
									
								
								packages/wyatt_go_router/example/lib/page_c.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,35 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| class PageC extends StatelessWidget { | ||||
|   const PageC({super.key}); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) => Scaffold( | ||||
|         appBar: AppBar( | ||||
|           title: const Text('Page C'), | ||||
|         ), | ||||
|         body: Center( | ||||
|           child: Text( | ||||
|             'Page C: ${context.currentRoute}', | ||||
|             style: Theme.of(context).textTheme.headlineMedium, | ||||
|           ), | ||||
|         ), | ||||
|       ); | ||||
| } | ||||
							
								
								
									
										25
									
								
								packages/wyatt_go_router/example/pubspec.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,25 @@ | ||||
| name: wyatt_go_router_example | ||||
| description: A new Flutter project. | ||||
| version: 1.0.0 | ||||
| 
 | ||||
| publish_to: "none" | ||||
| 
 | ||||
| environment: | ||||
|   sdk: ">=3.0.0 <4.0.0" | ||||
| 
 | ||||
| dependencies: | ||||
|   flutter: { sdk: flutter } | ||||
| 
 | ||||
|   wyatt_go_router: | ||||
|     path: "../" | ||||
| 
 | ||||
| dev_dependencies: | ||||
|   flutter_test: { sdk: flutter } | ||||
| 
 | ||||
|   wyatt_analysis: | ||||
|     hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub | ||||
|     version: ^2.6.1 | ||||
| 
 | ||||
| # The following section is specific to Flutter. | ||||
| flutter: | ||||
|   uses-material-design: true | ||||
							
								
								
									
										1
									
								
								packages/wyatt_go_router/example/test/widget_test.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| 
 | ||||
							
								
								
									
										
											BIN
										
									
								
								packages/wyatt_go_router/example/web/favicon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 917 B | 
							
								
								
									
										
											BIN
										
									
								
								packages/wyatt_go_router/example/web/icons/Icon-192.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 5.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/wyatt_go_router/example/web/icons/Icon-512.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 8.1 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/wyatt_go_router/example/web/icons/Icon-maskable-192.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 5.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/wyatt_go_router/example/web/icons/Icon-maskable-512.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 20 KiB | 
							
								
								
									
										59
									
								
								packages/wyatt_go_router/example/web/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,59 @@ | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
| <head> | ||||
|   <!-- | ||||
|     If you are serving your web app in a path other than the root, change the | ||||
|     href value below to reflect the base path you are serving from. | ||||
| 
 | ||||
|     The path provided below has to start and end with a slash "/" in order for | ||||
|     it to work correctly. | ||||
| 
 | ||||
|     For more details: | ||||
|     * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base | ||||
| 
 | ||||
|     This is a placeholder for base href that will be replaced by the value of | ||||
|     the `--base-href` argument provided to `flutter build`. | ||||
|   --> | ||||
|   <base href="$FLUTTER_BASE_HREF"> | ||||
| 
 | ||||
|   <meta charset="UTF-8"> | ||||
|   <meta content="IE=Edge" http-equiv="X-UA-Compatible"> | ||||
|   <meta name="description" content="A new Flutter project."> | ||||
| 
 | ||||
|   <!-- iOS meta tags & icons --> | ||||
|   <meta name="apple-mobile-web-app-capable" content="yes"> | ||||
|   <meta name="apple-mobile-web-app-status-bar-style" content="black"> | ||||
|   <meta name="apple-mobile-web-app-title" content="example"> | ||||
|   <link rel="apple-touch-icon" href="icons/Icon-192.png"> | ||||
| 
 | ||||
|   <!-- Favicon --> | ||||
|   <link rel="icon" type="image/png" href="favicon.png"/> | ||||
| 
 | ||||
|   <title>example</title> | ||||
|   <link rel="manifest" href="manifest.json"> | ||||
| 
 | ||||
|   <script> | ||||
|     // The value below is injected by flutter build, do not touch. | ||||
|     var serviceWorkerVersion = null; | ||||
|   </script> | ||||
|   <!-- This script adds the flutter initialization JS code --> | ||||
|   <script src="flutter.js" defer></script> | ||||
| </head> | ||||
| <body> | ||||
|   <script> | ||||
|     window.addEventListener('load', function(ev) { | ||||
|       // Download main.dart.js | ||||
|       _flutter.loader.loadEntrypoint({ | ||||
|         serviceWorker: { | ||||
|           serviceWorkerVersion: serviceWorkerVersion, | ||||
|         }, | ||||
|         onEntrypointLoaded: function(engineInitializer) { | ||||
|           engineInitializer.initializeEngine().then(function(appRunner) { | ||||
|             appRunner.runApp(); | ||||
|           }); | ||||
|         } | ||||
|       }); | ||||
|     }); | ||||
|   </script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										35
									
								
								packages/wyatt_go_router/example/web/manifest.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,35 @@ | ||||
| { | ||||
|     "name": "example", | ||||
|     "short_name": "example", | ||||
|     "start_url": ".", | ||||
|     "display": "standalone", | ||||
|     "background_color": "#0175C2", | ||||
|     "theme_color": "#0175C2", | ||||
|     "description": "A new Flutter project.", | ||||
|     "orientation": "portrait-primary", | ||||
|     "prefer_related_applications": false, | ||||
|     "icons": [ | ||||
|         { | ||||
|             "src": "icons/Icon-192.png", | ||||
|             "sizes": "192x192", | ||||
|             "type": "image/png" | ||||
|         }, | ||||
|         { | ||||
|             "src": "icons/Icon-512.png", | ||||
|             "sizes": "512x512", | ||||
|             "type": "image/png" | ||||
|         }, | ||||
|         { | ||||
|             "src": "icons/Icon-maskable-192.png", | ||||
|             "sizes": "192x192", | ||||
|             "type": "image/png", | ||||
|             "purpose": "maskable" | ||||
|         }, | ||||
|         { | ||||
|             "src": "icons/Icon-maskable-512.png", | ||||
|             "sizes": "512x512", | ||||
|             "type": "image/png", | ||||
|             "purpose": "maskable" | ||||
|         } | ||||
|     ] | ||||
| } | ||||
| @ -0,0 +1,29 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| /// {@template} | ||||
| /// A enum that defines the protection of a page. | ||||
| /// {@endtemplate} | ||||
| enum PageProtection { | ||||
|   /// The page can be accessed without authentication. | ||||
|   public, | ||||
| 
 | ||||
|   /// The page can only be accessed with authentication. | ||||
|   protected, | ||||
| 
 | ||||
|   /// The page protection is unknown, and the default one should be used. | ||||
|   none, | ||||
| } | ||||
| @ -0,0 +1,22 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:flutter/widgets.dart'; | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| extension BuildContextExtension on BuildContext { | ||||
|   GoRoute get currentRoute => GoRouter.of(this).currentRoute; | ||||
| } | ||||
| @ -0,0 +1,69 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:go_router/go_router.dart'; | ||||
| import 'package:wyatt_go_router/src/core/enums/page_protection.dart'; | ||||
| 
 | ||||
| /// Defines if a GoRoute is public or not. | ||||
| /// | ||||
| /// By default, all routes are in the [PageProtection.none] state. | ||||
| extension GoRouteExtension on GoRoute { | ||||
|   static final _protection = Expando<PageProtection>(); | ||||
| 
 | ||||
|   /// Returns `true` if the route is public. | ||||
|   bool get isPublic => _protection[this] == PageProtection.public; | ||||
| 
 | ||||
|   /// Returns `true` if the route is protected. | ||||
|   bool get isProtected => _protection[this] == PageProtection.protected; | ||||
| 
 | ||||
|   /// Returns `true` if the route is neither public nor protected. | ||||
|   /// This is the default state. | ||||
|   bool get isNone => _protection[this] == PageProtection.none; | ||||
| 
 | ||||
|   /// Sets the route to be public. | ||||
|   /// This is useful for routes that should be accessible | ||||
|   /// without authentication. | ||||
|   /// ```dart | ||||
|   /// GoRoute( | ||||
|   ///  path: '/sign_in', | ||||
|   ///  ... | ||||
|   /// )..setPublic(), | ||||
|   /// ``` | ||||
|   void setPublic() => _protection[this] = PageProtection.public; | ||||
| 
 | ||||
|   /// Sets the route to be protected. | ||||
|   /// This is useful for routes that should only be accessible | ||||
|   /// with authentication. | ||||
|   void setProtected() => _protection[this] = PageProtection.protected; | ||||
| 
 | ||||
|   PageProtection get protection => _protection[this] ?? PageProtection.none; | ||||
| } | ||||
| @ -0,0 +1,65 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:go_router/go_router.dart'; | ||||
| import 'package:wyatt_go_router/src/core/extensions/go_route_extension.dart'; | ||||
| 
 | ||||
| extension GoRouteIterableExtension on Iterable<GoRoute> { | ||||
|   /// Returns a list of public routes. | ||||
|   List<GoRoute> get publicRoutes => | ||||
|       where((route) => route.isPublic).toList(growable: false); | ||||
| 
 | ||||
|   /// Returns a list of protected routes. | ||||
|   List<GoRoute> get protectedRoutes => | ||||
|       where((route) => route.isProtected).toList(growable: false); | ||||
| 
 | ||||
|   /// Returns a list of routes that are neither public nor protected. | ||||
|   List<GoRoute> get noneRoutes => | ||||
|       where((route) => route.isNone).toList(growable: false); | ||||
| 
 | ||||
|   /// Returns a go route from its name. | ||||
|   /// | ||||
|   /// If no route is found, a [StateError] is thrown. | ||||
|   GoRoute fromName(String name) => firstWhere((route) => route.name == name); | ||||
| 
 | ||||
|   /// Returns a go route from its path. | ||||
|   /// | ||||
|   /// If no route is found, a [StateError] is thrown. | ||||
|   GoRoute fromPath(String path) => firstWhere((route) => route.path == path); | ||||
| 
 | ||||
|   /// Returns a go route from its name or null if no route is found. | ||||
|   GoRoute? fromNameOrNull(String name) { | ||||
|     if (any((route) => route.name == name)) { | ||||
|       return fromName(name); | ||||
|     } | ||||
| 
 | ||||
|     return null; | ||||
|   } | ||||
| 
 | ||||
|   /// Returns a go route from its path or null if no route is found. | ||||
|   GoRoute? fromPathOrNull(String path) { | ||||
|     if (any((route) => route.path == path)) { | ||||
|       return fromPath(path); | ||||
|     } | ||||
| 
 | ||||
|     return null; | ||||
|   } | ||||
| 
 | ||||
|   /// Returns a go route from its name, or null if no route is found. | ||||
|   /// | ||||
|   /// This is a shorthand for [fromNameOrNull]. | ||||
|   GoRoute? operator [](String name) => fromNameOrNull(name); | ||||
| } | ||||
| @ -0,0 +1,30 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:wyatt_go_router/wyatt_go_router.dart'; | ||||
| 
 | ||||
| extension GoRouterExtension on GoRouter { | ||||
|   List<GoRoute> get flattenedRoutes => configuration.routes | ||||
|       .map((route) => route.flatten()) | ||||
|       .expand( | ||||
|         (routeList) => routeList, | ||||
|       ) | ||||
|       .toList(); | ||||
| 
 | ||||
|   /// Returns the current route. | ||||
|   GoRoute get currentRoute => | ||||
|       flattenedRoutes.fromPath(routeInformationProvider.value.uri.path); | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'package:go_router/go_router.dart'; | ||||
| 
 | ||||
| /// Flatten the [GoRoute] tree. | ||||
| extension RouteBaseExtension on RouteBase { | ||||
|   /// Flatten a [GoRoute] or [ShellRoute] into a list of [GoRoute]s. | ||||
|   /// - If the current route is a [GoRoute], it is added to the list. | ||||
|   /// - If the current route is a [ShellRoute], all of its child routes are | ||||
|   /// flattened and added to the list. | ||||
|   List<GoRoute> flatten() { | ||||
|     final List<GoRoute> routes = []; | ||||
|     if (this is GoRoute) { | ||||
|       routes.add(this as GoRoute); | ||||
|     } else if (this is ShellRoute) { | ||||
|       routes.addAll( | ||||
|         (this as ShellRoute) | ||||
|             .routes | ||||
|             .map((route) => route.flatten()) | ||||
|             .expand((routeList) => routeList), | ||||
|       ); | ||||
|     } | ||||
| 
 | ||||
|     return routes; | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import 'dart:async'; | ||||
| 
 | ||||
| import 'package:flutter/foundation.dart'; | ||||
| 
 | ||||
| /// {@template go_router_refresh_stream} | ||||
| /// A [ChangeNotifier] that notifies its listeners when a stream emits a value. | ||||
| /// {@endtemplate} | ||||
| class GoRouterRefreshStream extends ChangeNotifier { | ||||
|   /// {@macro go_router_refresh_stream} | ||||
|   GoRouterRefreshStream(Stream<dynamic> stream) { | ||||
|     notifyListeners(); | ||||
|     _subscription = stream.asBroadcastStream().listen( | ||||
|           (dynamic _) => notifyListeners(), | ||||
|         ); | ||||
|   } | ||||
| 
 | ||||
|   late final StreamSubscription<dynamic> _subscription; | ||||
| 
 | ||||
|   @override | ||||
|   void dispose() { | ||||
|     _subscription.cancel(); | ||||
|     super.dispose(); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										23
									
								
								packages/wyatt_go_router/lib/src/wyatt_go_router.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,23 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| export 'core/enums/page_protection.dart'; | ||||
| export 'core/extensions/build_context_extension.dart'; | ||||
| export 'core/extensions/go_route_extension.dart'; | ||||
| export 'core/extensions/go_route_iterable_extension.dart'; | ||||
| export 'core/extensions/go_router_extension.dart'; | ||||
| export 'core/extensions/route_base_extension.dart'; | ||||
| export 'core/go_router_refresh_stream.dart'; | ||||
							
								
								
									
										25
									
								
								packages/wyatt_go_router/lib/wyatt_go_router.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,25 @@ | ||||
| // Copyright (C) 2023 WYATT GROUP | ||||
| // Please see the AUTHORS file for details. | ||||
| // | ||||
| // This program is free software: you can redistribute it and/or modify | ||||
| // it under the terms of the GNU General Public License as published by | ||||
| // the Free Software Foundation, either version 3 of the License, or | ||||
| // any later version. | ||||
| // | ||||
| // This program is distributed in the hope that it will be useful, | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| // GNU General Public License for more details. | ||||
| // | ||||
| // You should have received a copy of the GNU General Public License | ||||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| /// GoRouter enhancements | ||||
| /// | ||||
| /// This library provides enhancements to the GoRouter package. | ||||
| /// It also exports the GoRouter package. | ||||
| library wyatt_go_router; | ||||
| 
 | ||||
| export 'package:go_router/go_router.dart'; | ||||
| 
 | ||||
| export 'src/wyatt_go_router.dart'; | ||||
							
								
								
									
										18
									
								
								packages/wyatt_go_router/pubspec.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,18 @@ | ||||
| name: wyatt_go_router | ||||
| description: GoRouter Enhancements. | ||||
| repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_go_router | ||||
| version: 1.0.0 | ||||
| 
 | ||||
| environment: | ||||
|   sdk: ">=3.0.0 <4.0.0" | ||||
| 
 | ||||
| dependencies: | ||||
|   flutter: { sdk: flutter } | ||||
|   go_router: ^12.1.1 | ||||
| 
 | ||||
| dev_dependencies: | ||||
|   flutter_test: { sdk: flutter } | ||||
|   dart_code_linter: ^1.1.1 | ||||
|   wyatt_analysis: | ||||
|     hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub | ||||
|     version: ^2.6.1 | ||||
							
								
								
									
										1
									
								
								packages/wyatt_go_router/test/wyatt_go_router_test.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1 @@ | ||||
| // TODO(wyatt): add some tests | ||||