diff --git a/apps/wyatt_app_template/brickgen.yaml b/apps/wyatt_app_template/brickgen.yaml index 9d7c417..01468b7 100644 --- a/apps/wyatt_app_template/brickgen.yaml +++ b/apps/wyatt_app_template/brickgen.yaml @@ -17,7 +17,7 @@ name: wyatt_app_template description: New app template for Wyatt Studio projects. -version: 0.2.1 +version: 0.2.2 vars: display_name: diff --git a/apps/wyatt_app_template/starting_template/lib/core/enums/page_protection.dart b/apps/wyatt_app_template/starting_template/lib/core/enums/page_protection.dart deleted file mode 100644 index 4d63018..0000000 --- a/apps/wyatt_app_template/starting_template/lib/core/enums/page_protection.dart +++ /dev/null @@ -1,10 +0,0 @@ -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, -} diff --git a/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_guard.dart b/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_guard.dart deleted file mode 100644 index c9148d1..0000000 --- a/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_guard.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:go_router/go_router.dart'; -import 'package:starting_template/core/enums/page_protection.dart'; - -/// Defines if a GoRoute is public or not. -/// -/// By default, all routes are in the [PageProtection.none] state. -extension GoRouteGuard on GoRoute { - static final _guard = Expando(); - - /// Returns `true` if the route is public. - bool get isPublic => _guard[this] == PageProtection.public; - - /// Returns `true` if the route is protected. - bool get isProtected => _guard[this] == PageProtection.protected; - - /// Returns `true` if the route is neither public nor protected. - /// This is the default state. - bool get isNone => _guard[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() => _guard[this] = PageProtection.public; - - /// Sets the route to be protected. - /// This is useful for routes that should only be accessible - /// with authentication. - void setProtected() => _guard[this] = PageProtection.protected; - - PageProtection get guard => _guard[this] ?? PageProtection.none; -} diff --git a/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_list_extension.dart b/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_list_extension.dart deleted file mode 100644 index b7a9fd6..0000000 --- a/apps/wyatt_app_template/starting_template/lib/core/extensions/go_route_list_extension.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:go_router/go_router.dart'; -import 'package:starting_template/core/extensions/go_route_guard.dart'; - -extension GoRouteListExtension on Iterable { - /// Returns a list of public routes. - List get publicRoutes => - where((route) => route.isPublic).toList(growable: false); - - /// Returns a list of protected routes. - List get protectedRoutes => - where((route) => route.isProtected).toList(growable: false); - - /// Returns a list of routes that are neither public nor protected. - List get noneRoutes => - where((route) => route.isNone).toList(growable: false); - - GoRoute fromName(String name) => firstWhere((route) => route.name == name); - GoRoute fromPath(String path) => firstWhere((route) => route.path == path); - - GoRoute operator [](String name) => fromName(name); -} diff --git a/apps/wyatt_app_template/starting_template/lib/core/extensions/route_base_extension.dart b/apps/wyatt_app_template/starting_template/lib/core/extensions/route_base_extension.dart deleted file mode 100644 index 9866537..0000000 --- a/apps/wyatt_app_template/starting_template/lib/core/extensions/route_base_extension.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:go_router/go_router.dart'; - -/// Flatten the [GoRoute] tree. -extension RouteBaseExtension on RouteBase { - List flatten() { - final List 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; - } -} diff --git a/apps/wyatt_app_template/starting_template/lib/core/routes/app_router.dart b/apps/wyatt_app_template/starting_template/lib/core/routes/app_router.dart index 63b0ae8..5f132c9 100644 --- a/apps/wyatt_app_template/starting_template/lib/core/routes/app_router.dart +++ b/apps/wyatt_app_template/starting_template/lib/core/routes/app_router.dart @@ -1,10 +1,6 @@ import 'package:flutter/cupertino.dart'; -import 'package:go_router/go_router.dart'; -import 'package:starting_template/core/enums/page_protection.dart'; -import 'package:starting_template/core/extensions/go_route_guard.dart'; -import 'package:starting_template/core/extensions/route_base_extension.dart'; -import 'package:starting_template/core/routes/go_router_refresh_stream.dart'; import 'package:starting_template/presentation/features/home/home.dart'; +import 'package:wyatt_go_router/wyatt_go_router.dart'; abstract class AppRouter { /// Default transition for all pages @@ -52,34 +48,15 @@ abstract class AppRouter { /// Define the default guard /// This is the guard that will be used if the route /// does not have a guard set. (It is set to [PageProtection.none]) - const defaultGuard = PageProtection.protected; - - /// Recursively get all routes and subroutes in a one-dimensional list - /// This will work for any level of nesting - final routes = - AppRouter.routes.map((route) => route.flatten()).expand( - (routeList) => routeList, - ); - - /// Matches is a list of all routes that match the current uri - final matches = _router?.configuration - .findMatch( - state.uri.toString(), - ) - .routes - .map((route) => route.flatten()) - .expand( - (routeList) => routeList, - ) ?? - routes; + const defaultProtection = PageProtection.protected; /// Get the current route - final currentRoute = matches.last; + final currentRoute = context.currentRoute; /// Get the guard of the current route - final guard = (currentRoute.guard == PageProtection.none) - ? defaultGuard - : currentRoute.guard; + final _ = (currentRoute.protection == PageProtection.none) + ? defaultProtection + : currentRoute.protection; return null; }, diff --git a/apps/wyatt_app_template/starting_template/lib/core/routes/go_router_refresh_stream.dart b/apps/wyatt_app_template/starting_template/lib/core/routes/go_router_refresh_stream.dart deleted file mode 100644 index 269555c..0000000 --- a/apps/wyatt_app_template/starting_template/lib/core/routes/go_router_refresh_stream.dart +++ /dev/null @@ -1,24 +0,0 @@ -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 stream) { - notifyListeners(); - _subscription = stream.asBroadcastStream().listen( - (dynamic _) => notifyListeners(), - ); - } - - late final StreamSubscription _subscription; - - @override - void dispose() { - _subscription.cancel(); - super.dispose(); - } -} diff --git a/apps/wyatt_app_template/starting_template/pubspec.yaml b/apps/wyatt_app_template/starting_template/pubspec.yaml index 4efc88d..02d6208 100644 --- a/apps/wyatt_app_template/starting_template/pubspec.yaml +++ b/apps/wyatt_app_template/starting_template/pubspec.yaml @@ -15,9 +15,9 @@ dependencies: freezed_annotation: ^2.4.1 gap: ^3.0.1 get_it: ^7.6.4 - go_router: ^10.1.2 intl: ^0.18.1 json_annotation: ^4.8.1 + logging: ^1.2.0 flutter: sdk: flutter @@ -41,7 +41,12 @@ dependencies: hosted: name: wyatt_type_utils url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ - logging: ^1.2.0 + + wyatt_go_router: + version: ^1.0.0 + hosted: + name: wyatt_go_router + url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ dev_dependencies: build_runner: ^2.4.6 diff --git a/apps/wyatt_package_template/brickgen.yaml b/apps/wyatt_package_template/brickgen.yaml index acf3390..12d19e6 100644 --- a/apps/wyatt_package_template/brickgen.yaml +++ b/apps/wyatt_package_template/brickgen.yaml @@ -1,7 +1,7 @@ name: wyatt_package_template description: New package template for Wyatt Studio projects. -version: 0.2.1 +version: 0.2.2 vars: package_name: diff --git a/apps/wyatt_package_template/wyatt_package_template/example/pubspec.yaml b/apps/wyatt_package_template/wyatt_package_template/example/pubspec.yaml index f88cfcd..49a0d24 100644 --- a/apps/wyatt_package_template/wyatt_package_template/example/pubspec.yaml +++ b/apps/wyatt_package_template/wyatt_package_template/example/pubspec.yaml @@ -5,7 +5,7 @@ version: 1.0.0 publish_to: 'none' environment: - sdk: ">=2.19.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ### {{#flutter}} @@ -25,10 +25,10 @@ dev_dependencies: wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub - version: ^2.4.0 + version: ^2.6.1 ###{{#flutter}} #### The following section is specific to Flutter. ###flutter: ### uses-material-design: true -###{{/flutter}} \ No newline at end of file +###{{/flutter}} diff --git a/apps/wyatt_package_template/wyatt_package_template/pubspec.yaml b/apps/wyatt_package_template/wyatt_package_template/pubspec.yaml index 265625b..bf9eb56 100644 --- a/apps/wyatt_package_template/wyatt_package_template/pubspec.yaml +++ b/apps/wyatt_package_template/wyatt_package_template/pubspec.yaml @@ -3,6 +3,8 @@ description: A short package description. repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/package_name version: 1.0.0 +publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub + environment: sdk: ">=3.0.0 <4.0.0" diff --git a/bricks/wyatt_app_template/__brick__/lib/core/enums/page_protection.dart b/bricks/wyatt_app_template/__brick__/lib/core/enums/page_protection.dart deleted file mode 100644 index 4d63018..0000000 --- a/bricks/wyatt_app_template/__brick__/lib/core/enums/page_protection.dart +++ /dev/null @@ -1,10 +0,0 @@ -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, -} diff --git a/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_guard.dart b/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_guard.dart deleted file mode 100644 index e5e8ecd..0000000 --- a/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_guard.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:go_router/go_router.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/enums/page_protection.dart'; - -/// Defines if a GoRoute is public or not. -/// -/// By default, all routes are in the [PageProtection.none] state. -extension GoRouteGuard on GoRoute { - static final _guard = Expando(); - - /// Returns `true` if the route is public. - bool get isPublic => _guard[this] == PageProtection.public; - - /// Returns `true` if the route is protected. - bool get isProtected => _guard[this] == PageProtection.protected; - - /// Returns `true` if the route is neither public nor protected. - /// This is the default state. - bool get isNone => _guard[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() => _guard[this] = PageProtection.public; - - /// Sets the route to be protected. - /// This is useful for routes that should only be accessible - /// with authentication. - void setProtected() => _guard[this] = PageProtection.protected; - - PageProtection get guard => _guard[this] ?? PageProtection.none; -} diff --git a/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_list_extension.dart b/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_list_extension.dart deleted file mode 100644 index f1eb6ab..0000000 --- a/bricks/wyatt_app_template/__brick__/lib/core/extensions/go_route_list_extension.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:go_router/go_router.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/extensions/go_route_guard.dart'; - -extension GoRouteListExtension on Iterable { - /// Returns a list of public routes. - List get publicRoutes => - where((route) => route.isPublic).toList(growable: false); - - /// Returns a list of protected routes. - List get protectedRoutes => - where((route) => route.isProtected).toList(growable: false); - - /// Returns a list of routes that are neither public nor protected. - List get noneRoutes => - where((route) => route.isNone).toList(growable: false); - - GoRoute fromName(String name) => firstWhere((route) => route.name == name); - GoRoute fromPath(String path) => firstWhere((route) => route.path == path); - - GoRoute operator [](String name) => fromName(name); -} diff --git a/bricks/wyatt_app_template/__brick__/lib/core/extensions/route_base_extension.dart b/bricks/wyatt_app_template/__brick__/lib/core/extensions/route_base_extension.dart deleted file mode 100644 index 9866537..0000000 --- a/bricks/wyatt_app_template/__brick__/lib/core/extensions/route_base_extension.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:go_router/go_router.dart'; - -/// Flatten the [GoRoute] tree. -extension RouteBaseExtension on RouteBase { - List flatten() { - final List 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; - } -} diff --git a/bricks/wyatt_app_template/__brick__/lib/core/routes/app_router.dart b/bricks/wyatt_app_template/__brick__/lib/core/routes/app_router.dart index 0a63502..f6f5d19 100644 --- a/bricks/wyatt_app_template/__brick__/lib/core/routes/app_router.dart +++ b/bricks/wyatt_app_template/__brick__/lib/core/routes/app_router.dart @@ -1,10 +1,6 @@ import 'package:flutter/cupertino.dart'; -import 'package:go_router/go_router.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/enums/page_protection.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/extensions/go_route_guard.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/extensions/route_base_extension.dart'; -import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/routes/go_router_refresh_stream.dart'; import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/presentation/features/home/home.dart'; +import 'package:wyatt_go_router/wyatt_go_router.dart'; abstract class AppRouter { /// Default transition for all pages @@ -52,34 +48,15 @@ abstract class AppRouter { /// Define the default guard /// This is the guard that will be used if the route /// does not have a guard set. (It is set to [PageProtection.none]) - const defaultGuard = PageProtection.protected; - - /// Recursively get all routes and subroutes in a one-dimensional list - /// This will work for any level of nesting - final routes = - AppRouter.routes.map((route) => route.flatten()).expand( - (routeList) => routeList, - ); - - /// Matches is a list of all routes that match the current uri - final matches = _router?.configuration - .findMatch( - state.uri.toString(), - ) - .routes - .map((route) => route.flatten()) - .expand( - (routeList) => routeList, - ) ?? - routes; + const defaultProtection = PageProtection.protected; /// Get the current route - final currentRoute = matches.last; + final currentRoute = context.currentRoute; /// Get the guard of the current route - final guard = (currentRoute.guard == PageProtection.none) - ? defaultGuard - : currentRoute.guard; + final _ = (currentRoute.protection == PageProtection.none) + ? defaultProtection + : currentRoute.protection; return null; }, diff --git a/bricks/wyatt_app_template/__brick__/lib/core/routes/go_router_refresh_stream.dart b/bricks/wyatt_app_template/__brick__/lib/core/routes/go_router_refresh_stream.dart deleted file mode 100644 index 269555c..0000000 --- a/bricks/wyatt_app_template/__brick__/lib/core/routes/go_router_refresh_stream.dart +++ /dev/null @@ -1,24 +0,0 @@ -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 stream) { - notifyListeners(); - _subscription = stream.asBroadcastStream().listen( - (dynamic _) => notifyListeners(), - ); - } - - late final StreamSubscription _subscription; - - @override - void dispose() { - _subscription.cancel(); - super.dispose(); - } -} diff --git a/bricks/wyatt_app_template/__brick__/pubspec.yaml b/bricks/wyatt_app_template/__brick__/pubspec.yaml index 2454d01..221fa8a 100644 --- a/bricks/wyatt_app_template/__brick__/pubspec.yaml +++ b/bricks/wyatt_app_template/__brick__/pubspec.yaml @@ -15,9 +15,9 @@ dependencies: freezed_annotation: ^2.4.1 gap: ^3.0.1 get_it: ^7.6.4 - go_router: ^10.1.2 intl: ^0.18.1 json_annotation: ^4.8.1 + logging: ^1.2.0 flutter: sdk: flutter @@ -41,7 +41,12 @@ dependencies: hosted: name: wyatt_type_utils url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ - logging: ^1.2.0 + + wyatt_go_router: + version: ^1.0.0 + hosted: + name: wyatt_go_router + url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ dev_dependencies: build_runner: ^2.4.6 diff --git a/bricks/wyatt_app_template/brick.yaml b/bricks/wyatt_app_template/brick.yaml index d184f99..aab4a03 100644 --- a/bricks/wyatt_app_template/brick.yaml +++ b/bricks/wyatt_app_template/brick.yaml @@ -1,7 +1,7 @@ name: wyatt_app_template description: New app template for Wyatt Studio projects. -version: 0.2.1 +version: 0.2.2 vars: display_name: diff --git a/bricks/wyatt_package_template/__brick__/example/pubspec.yaml b/bricks/wyatt_package_template/__brick__/example/pubspec.yaml index 8e171f8..b2cd197 100644 --- a/bricks/wyatt_package_template/__brick__/example/pubspec.yaml +++ b/bricks/wyatt_package_template/__brick__/example/pubspec.yaml @@ -5,7 +5,7 @@ version: 1.0.0 publish_to: 'none' environment: - sdk: ">=2.19.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: {{#flutter}} @@ -31,7 +31,7 @@ dev_dependencies: wyatt_analysis: hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub - version: ^2.4.0 + version: ^2.6.1 {{#flutter}} # The following section is specific to Flutter. @@ -39,3 +39,4 @@ flutter: uses-material-design: true {{/flutter}} + diff --git a/bricks/wyatt_package_template/__brick__/pubspec.yaml b/bricks/wyatt_package_template/__brick__/pubspec.yaml index 93a689e..c46a14f 100644 --- a/bricks/wyatt_package_template/__brick__/pubspec.yaml +++ b/bricks/wyatt_package_template/__brick__/pubspec.yaml @@ -3,6 +3,8 @@ description: {{#sentenceCase}}{{description}}{{/sentenceCase}}. repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/{{#snakeCase}}{{package_name}}{{/snakeCase}} version: 1.0.0 +publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub + environment: sdk: ">=3.0.0 <4.0.0" diff --git a/bricks/wyatt_package_template/brick.yaml b/bricks/wyatt_package_template/brick.yaml index c268787..5844dd6 100644 --- a/bricks/wyatt_package_template/brick.yaml +++ b/bricks/wyatt_package_template/brick.yaml @@ -1,7 +1,7 @@ name: wyatt_package_template description: New package template for Wyatt Studio projects. -version: 0.2.1 +version: 0.2.2 vars: package_name: diff --git a/tools/brick_generator/lib/core/logger.dart b/tools/brick_generator/lib/core/logger.dart index 5176418..7c2cc0c 100644 --- a/tools/brick_generator/lib/core/logger.dart +++ b/tools/brick_generator/lib/core/logger.dart @@ -24,7 +24,7 @@ class Logger { static void setVerbose() => verbose = true; static void log(Object? message, {LogLevel level = LogLevel.info}) { - stdout.writeln('${level.prefix} ${message.toString()}'); + stdout.writeln('${level.prefix} $message'); } static void debug(Object? message) { diff --git a/tools/brick_generator/lib/core/shell.dart b/tools/brick_generator/lib/core/shell.dart index ad5a92e..1714d90 100644 --- a/tools/brick_generator/lib/core/shell.dart +++ b/tools/brick_generator/lib/core/shell.dart @@ -57,7 +57,7 @@ abstract class _Cmd { if (pr.exitCode != 0) { final values = { 'Standard out': pr.stdout.toString().trim(), - 'Standard error': pr.stderr.toString().trim() + 'Standard error': pr.stderr.toString().trim(), }..removeWhere((k, v) => v.isEmpty); String message; diff --git a/tools/brick_generator/pubspec.yaml b/tools/brick_generator/pubspec.yaml index bccc5e3..bcfe71c 100644 --- a/tools/brick_generator/pubspec.yaml +++ b/tools/brick_generator/pubspec.yaml @@ -18,4 +18,4 @@ dev_dependencies: hosted: url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ name: wyatt_analysis - version: 2.3.0 + version: 2.6.1