From aaa1520f1e8da7927e840ae8824a3a0b8b9825ee Mon Sep 17 00:00:00 2001 From: R0m4in-dooz <72380352+R0m4in-dooz@users.noreply.github.com> Date: Thu, 12 Aug 2021 10:13:04 +0200 Subject: [PATCH 1/5] support null-safety (#1) --- CHANGELOG.md | 4 + example/lib/src/app.dart | 2 +- example/lib/src/views/welcome.dart | 8 +- example/pubspec.lock | 113 ++++++++++------------------- example/pubspec.yaml | 22 ++---- lib/rc_router.dart | 55 ++++++++------ pubspec.lock | 105 +++++++++------------------ pubspec.yaml | 8 +- test/rc_router_test.dart | 4 +- test/src/route_example.dart | 5 +- 10 files changed, 130 insertions(+), 196 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb8a32e..3d62ac8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.4.0] 12/08/2021 + +- update project to support null-safety + ## [0.3.0] 11/03/2020 - update provider to version 4.x.x diff --git a/example/lib/src/app.dart b/example/lib/src/app.dart index f59663f..7ad0d55 100644 --- a/example/lib/src/app.dart +++ b/example/lib/src/app.dart @@ -8,7 +8,7 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - RcRoutes rcRoutes; + late final RcRoutes rcRoutes; @override void initState() { diff --git a/example/lib/src/views/welcome.dart b/example/lib/src/views/welcome.dart index 86a0862..68c8d3c 100644 --- a/example/lib/src/views/welcome.dart +++ b/example/lib/src/views/welcome.dart @@ -4,7 +4,7 @@ import 'package:rc_router/rc_router.dart'; import 'package:rc_router_example/src/routes/routes.dart'; class WelcomePage extends StatefulWidget { - WelcomePage({Key key}) : super(key: key); + WelcomePage({Key? key}) : super(key: key); @override _WelcomePageState createState() => _WelcomePageState(); @@ -31,18 +31,16 @@ class _WelcomePageState extends State { child: Text('Hello, $name'), ), floatingActionButton: FloatingActionButton( - child: Icon(Icons.new_releases), onPressed: () { print(RcRoute.generateRoute( GrettingsRoute.routePath, pathParams: {'name': 'kevin'}, )); Navigator.of(context).pushNamed( - GrettingsRoute.generateRoute( - 'kevin' - ), + GrettingsRoute.generateRoute('kevin'), ); }, + child: Icon(Icons.new_releases), ), ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 0fcfe34..1aa7ada 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,69 +1,62 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.1.0" + charcode: dependency: transitive description: - name: collection + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.2.0" + clock: dependency: transitive description: - name: convert + name: clock url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.0" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "1.0.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -74,76 +67,55 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" nested: dependency: transitive description: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" + version: "1.11.1" provider: dependency: "direct main" description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.0.4" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "5.0.0" rc_router: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.3.0" + version: "0.4.0" sky_engine: dependency: transitive description: flutter @@ -155,63 +127,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.12.1" + dart: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 868ea86..3822d8b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,30 +1,22 @@ name: rc_router_example -description: A new Flutter project. +description: An example of the use of rc_router API. +publish_to: none -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 1.0.1+2 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0 <3.0.0" dependencies: flutter: sdk: flutter - provider: ^4.0.0 + provider: ^5.0.0 rc_router: path: ../ # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.3 dev_dependencies: flutter_test: diff --git a/lib/rc_router.dart b/lib/rc_router.dart index 0960152..544e45b 100644 --- a/lib/rc_router.dart +++ b/lib/rc_router.dart @@ -3,27 +3,26 @@ library rc_router; import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; -typedef PageRoute NotFoundRouteFactory(RouteSettings routeSettings); +typedef NotFoundRouteFactory = PageRoute Function(RouteSettings routeSettings); class RcRoutes { - final NotFoundRouteFactory notFoundRoute; + final NotFoundRouteFactory? notFoundRoute; final List routes; - RcRoutes({this.notFoundRoute, @required List routes}) - : this.routes = routes ?? []; + RcRoutes({this.notFoundRoute, required this.routes}); /// Generate the route based on [routeSettings] /// If a valid route is found in [routes] it will return it /// Else if [notFoundRoute] exist it will show it /// Else return null - Route onGeneratedRoute(RouteSettings routeSettings) { + Route? onGeneratedRoute(RouteSettings routeSettings) { for (final route in routes) { if (route.routeNameMatchPath(routeSettings.name)) { return route.routeBuilder(routeSettings); } } if (notFoundRoute != null) { - return notFoundRoute(routeSettings); + return notFoundRoute!(routeSettings); } return null; } @@ -33,30 +32,30 @@ class RcRouteParameters { final Uri path; final Map pathParameters; final Map queryParameters; - final Object arguments; + final Object? arguments; RcRouteParameters({ - @required this.path, - @required this.pathParameters, - @required this.queryParameters, + required this.path, + required this.pathParameters, + required this.queryParameters, this.arguments, }); } -typedef Route RcRouteBuilder(RouteSettings routeSettings); +typedef RcRouteBuilder = Route Function(RouteSettings routeSettings); abstract class RcRoute extends StatelessWidget { /// helper to generate Url from the [path] combined with [pathParams] and [queryParams] static String generateRoute(String path, - {Map pathParams, Map queryParams}) { + {Map? pathParams, Map? queryParams}) { pathParams ??= {}; queryParams ??= {}; - String _path = path; + var _path = path; for (final key in pathParams.keys) { - _path = _path.replaceFirst(':$key', pathParams[key]); + _path = _path.replaceFirst(':$key', pathParams[key]!); } final sb = StringBuffer(); - for (final key in queryParams?.keys) { + for (final key in queryParams.keys) { sb.write('$key=${queryParams[key]}'); if (key != queryParams.keys.last) { sb.write('&'); @@ -70,16 +69,21 @@ abstract class RcRoute extends StatelessWidget { final String _path; - RcRoute({@required String path}) : this._path = path; + RcRoute({required String path}) : _path = path; String get path => _path; - Widget build(BuildContext context); + // ignore: annotate_overrides + Widget build(BuildContext context); // should we add override annotation ? Widget handle( - {@required BuildContext context, @required RouteSettings routeSettings}) { + {required BuildContext context, required RouteSettings routeSettings}) { + final _routeName = routeSettings.name; + if (_routeName == null) { + throw UnimplementedError('anonymous routes not implemented'); + } final routeParameters = - getRouteParameters(routeSettings.name, routeSettings.arguments); + getRouteParameters(_routeName, routeSettings.arguments); return Provider.value( value: routeParameters, child: Builder(builder: (c) => build(c)), @@ -99,11 +103,11 @@ abstract class RcRoute extends StatelessWidget { } @visibleForTesting - RcRouteParameters getRouteParameters(String routeName, Object arguments) { + RcRouteParameters getRouteParameters(String routeName, Object? arguments) { final pathParameters = {}; final pathUri = Uri.parse(routeName); final uri = Uri.parse(path); - for (int i = 0; i < pathUri.pathSegments.length; i++) { + for (var i = 0; i < pathUri.pathSegments.length; i++) { if (uri.pathSegments.length <= i) { break; } @@ -121,11 +125,14 @@ abstract class RcRoute extends StatelessWidget { } @visibleForTesting - bool routeNameMatchPath(String routeName) { + bool routeNameMatchPath(String? routeName) { + if (routeName == null) { + return false; + } final pathUri = Uri.parse(routeName); final uri = Uri.parse(path); - bool isValid = pathUri.pathSegments.length == uri.pathSegments.length; - for (int i = 0; i < pathUri.pathSegments.length; i++) { + var isValid = pathUri.pathSegments.length == uri.pathSegments.length; + for (var i = 0; i < pathUri.pathSegments.length; i++) { if (uri.pathSegments.length <= i) { isValid = false; break; diff --git a/pubspec.lock b/pubspec.lock index 11a173e..cf48c78 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,55 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.2.0" + clock: dependency: transitive description: - name: collection + name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.1.0" + collection: dependency: transitive description: - name: convert + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.15.0" + fake_async: dependency: transitive description: - name: crypto + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,69 +60,48 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" nested: dependency: transitive description: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" pedantic: dependency: "direct main" description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" + version: "1.11.1" provider: dependency: "direct main" description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.0.4" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "5.0.0" sky_engine: dependency: transitive description: flutter @@ -141,63 +113,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" - flutter: ">=1.12.1" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index 94b5d38..e5f0160 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,16 @@ name: rc_router description: A simple but powerful Flutter router. -version: 0.3.0 +version: 0.4.0 homepage: https://rushio-consulting.fr environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter - provider: ^4.0.0 - pedantic: ^1.8.0+1 + provider: ^5.0.0 + pedantic: ^1.11.1 dev_dependencies: flutter_test: diff --git a/test/rc_router_test.dart b/test/rc_router_test.dart index 376eae4..0164ff9 100644 --- a/test/rc_router_test.dart +++ b/test/rc_router_test.dart @@ -80,7 +80,7 @@ void main() { group('RcRoutes', () { group('valid', () { test('empty', () { - final rcRoutes = RcRoutes(routes: null); + final rcRoutes = RcRoutes(routes: const []); final route = rcRoutes.onGeneratedRoute(RouteSettings(name: '/example')); @@ -180,7 +180,7 @@ void main() { onGenerateRoute: rcRoutes.onGeneratedRoute, ), ); - unawaited(navigator.currentState.pushNamed('/test?key=value')); + unawaited(navigator.currentState!.pushNamed('/test?key=value')); await widgetTester.pumpAndSettle(); expect(find.text('test'), findsOneWidget); diff --git a/test/src/route_example.dart b/test/src/route_example.dart index 270431d..3ed1122 100644 --- a/test/src/route_example.dart +++ b/test/src/route_example.dart @@ -5,7 +5,10 @@ import 'package:rc_router/rc_router.dart'; class ExampleRoute extends RcRoute { final Widget child; - ExampleRoute({@required String path, this.child}) : super(path: path); + ExampleRoute({ + required String path, + this.child = const SizedBox.shrink(), + }) : super(path: path); @override Widget build(BuildContext context) { From e703263bbee860dff893b0669f8f5cb197f8004d Mon Sep 17 00:00:00 2001 From: R0m4in-dooz <72380352+R0m4in-dooz@users.noreply.github.com> Date: Sat, 14 Aug 2021 17:53:53 +0200 Subject: [PATCH 2/5] bump pkg's version (#2) --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e5f0160..76cc157 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rc_router description: A simple but powerful Flutter router. -version: 0.4.0 +version: 1.0.0 homepage: https://rushio-consulting.fr environment: From dbadb2618e8097315ed0e8bc3e897b907a11fb93 Mon Sep 17 00:00:00 2001 From: R0m4in-dooz <72380352+R0m4in-dooz@users.noreply.github.com> Date: Sat, 14 Aug 2021 17:57:38 +0200 Subject: [PATCH 3/5] update changelog (#3) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d62ac8..4b47467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [0.4.0] 12/08/2021 +## [1.0.0] 14/08/2021 - update project to support null-safety From 9a4534c0c53ce39bed80b9ff7f4724affb95de5a Mon Sep 17 00:00:00 2001 From: R0m4in-dooz <72380352+R0m4in-dooz@users.noreply.github.com> Date: Wed, 25 Aug 2021 11:54:38 +0200 Subject: [PATCH 4/5] allow null value for queryParams entries (#4) --- example/pubspec.lock | 2 +- lib/rc_router.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 1aa7ada..1aaace1 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -115,7 +115,7 @@ packages: path: ".." relative: true source: path - version: "0.4.0" + version: "1.0.0" sky_engine: dependency: transitive description: flutter diff --git a/lib/rc_router.dart b/lib/rc_router.dart index 544e45b..03a0d43 100644 --- a/lib/rc_router.dart +++ b/lib/rc_router.dart @@ -47,7 +47,7 @@ typedef RcRouteBuilder = Route Function(RouteSettings routeSettings); abstract class RcRoute extends StatelessWidget { /// helper to generate Url from the [path] combined with [pathParams] and [queryParams] static String generateRoute(String path, - {Map? pathParams, Map? queryParams}) { + {Map? pathParams, Map? queryParams}) { pathParams ??= {}; queryParams ??= {}; var _path = path; From a32018f9ce8373fec32fb9a7d25ee0de229f51a0 Mon Sep 17 00:00:00 2001 From: R0m4in-dooz Date: Tue, 9 Nov 2021 15:00:01 +0100 Subject: [PATCH 5/5] migrate to flutter_lints and provider 6.x and bump version to 1.0.1 --- analysis_options.yaml | 2 +- lib/rc_router.dart | 4 +++- pubspec.lock | 24 +++++++++++++++++++----- pubspec.yaml | 5 +++-- test/rc_router_test.dart | 36 ++++++++++++++++++++---------------- test/src/route_example.dart | 5 +++-- 6 files changed, 49 insertions(+), 27 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 108d105..f9b3034 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1 @@ -include: package:pedantic/analysis_options.yaml +include: package:flutter_lints/flutter.yaml diff --git a/lib/rc_router.dart b/lib/rc_router.dart index 03a0d43..5d7d12d 100644 --- a/lib/rc_router.dart +++ b/lib/rc_router.dart @@ -69,7 +69,9 @@ abstract class RcRoute extends StatelessWidget { final String _path; - RcRoute({required String path}) : _path = path; + const RcRoute({Key? key, required String path}) + : _path = path, + super(key: key); String get path => _path; diff --git a/pubspec.lock b/pubspec.lock index cf48c78..4e0f02e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -55,11 +55,25 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" matcher: dependency: transitive description: @@ -73,7 +87,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -101,7 +115,7 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "6.0.1" sky_engine: dependency: transitive description: flutter @@ -148,7 +162,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.2" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 76cc157..15c2eff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: rc_router description: A simple but powerful Flutter router. -version: 1.0.0 +version: 1.0.1 homepage: https://rushio-consulting.fr environment: @@ -9,9 +9,10 @@ environment: dependencies: flutter: sdk: flutter - provider: ^5.0.0 + provider: ^6.0.1 pedantic: ^1.11.1 dev_dependencies: flutter_test: sdk: flutter + flutter_lints: ^1.0.4 diff --git a/test/rc_router_test.dart b/test/rc_router_test.dart index 0164ff9..a6a2457 100644 --- a/test/rc_router_test.dart +++ b/test/rc_router_test.dart @@ -32,8 +32,8 @@ void main() { group('valid', () { test('simple', () { - final path = '/example'; - final route = ExampleRoute( + const path = '/example'; + const route = ExampleRoute( path: path, ); final match = route.routeNameMatchPath(path); @@ -41,7 +41,7 @@ void main() { }); test('with path params', () { - final route = ExampleRoute( + const route = ExampleRoute( path: '/example/:withPathParams', ); final match = route.routeNameMatchPath('/example/12'); @@ -49,7 +49,7 @@ void main() { }); test('with query params', () { - final route = ExampleRoute( + const route = ExampleRoute( path: '/example', ); final match = route.routeNameMatchPath('/example?a=a'); @@ -57,7 +57,7 @@ void main() { }); test('all', () { - final route = ExampleRoute( + const route = ExampleRoute( path: '/example/:withPathParams', ); final match = route.routeNameMatchPath('/example/12?a=a'); @@ -67,8 +67,8 @@ void main() { group('invalid', () { test('simple', () { - final path = '/example'; - final route = ExampleRoute( + const path = '/example'; + const route = ExampleRoute( path: path, ); final match = route.routeNameMatchPath('/toto'); @@ -83,12 +83,12 @@ void main() { final rcRoutes = RcRoutes(routes: const []); final route = - rcRoutes.onGeneratedRoute(RouteSettings(name: '/example')); + rcRoutes.onGeneratedRoute(const RouteSettings(name: '/example')); expect(route, isNull); }); test('simple', () { final rcRoutes = RcRoutes( - routes: [ + routes: const [ ExampleRoute( path: '/example', ), @@ -96,7 +96,7 @@ void main() { ); final route = - rcRoutes.onGeneratedRoute(RouteSettings(name: '/example')); + rcRoutes.onGeneratedRoute(const RouteSettings(name: '/example')); expect(route, isNotNull); }); }); @@ -104,20 +104,21 @@ void main() { group('invalid', () { test('simple', () { final rcRoutes = RcRoutes( - routes: [ + routes: const [ ExampleRoute( path: '/example', ), ], ); - final route = rcRoutes.onGeneratedRoute(RouteSettings(name: '/toto')); + final route = + rcRoutes.onGeneratedRoute(const RouteSettings(name: '/toto')); expect(route, isNull); }); test('fallback to not found', () { final rcRoutes = RcRoutes( - routes: [ + routes: const [ ExampleRoute( path: '/example', ), @@ -128,7 +129,8 @@ void main() { ); }, ); - final route = rcRoutes.onGeneratedRoute(RouteSettings(name: '/toto')); + final route = + rcRoutes.onGeneratedRoute(const RouteSettings(name: '/toto')); expect(route, isNotNull); }); }); @@ -137,7 +139,7 @@ void main() { group('widgets', () { testWidgets('show good widget', (widgetTester) async { final rcRoutes = RcRoutes( - routes: [ + routes: const [ ExampleRoute( path: '/', child: Scaffold( @@ -159,7 +161,7 @@ void main() { testWidgets('get parameters', (widgetTester) async { final rcRoutes = RcRoutes( - routes: [ + routes: const [ ExampleRoute( path: '/', child: Scaffold( @@ -190,6 +192,8 @@ void main() { } class Home extends StatelessWidget { + const Home({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final routeParams = Provider.of(context, listen: false); diff --git a/test/src/route_example.dart b/test/src/route_example.dart index 3ed1122..b3ae3fb 100644 --- a/test/src/route_example.dart +++ b/test/src/route_example.dart @@ -5,10 +5,11 @@ import 'package:rc_router/rc_router.dart'; class ExampleRoute extends RcRoute { final Widget child; - ExampleRoute({ + const ExampleRoute({ + Key? key, required String path, this.child = const SizedBox.shrink(), - }) : super(path: path); + }) : super(path: path, key: key); @override Widget build(BuildContext context) {