Showing
10 changed files
with
95 additions
and
12 deletions
| 1 | +## [3.20.1] | ||
| 2 | +* Fix wrong reference with unnamed routes and added more tests | ||
| 3 | + | ||
| 1 | ## [3.20.0] - Big update | 4 | ## [3.20.0] - Big update |
| 2 | * Added GetConnect. | 5 | * Added GetConnect. |
| 3 | - GetConnect is an easy way to communicate from your back to your front. With it you can: | 6 | - GetConnect is an easy way to communicate from your back to your front. With it you can: |
| @@ -34,7 +34,8 @@ class CountryView extends GetView<HomeController> { | @@ -34,7 +34,8 @@ class CountryView extends GetView<HomeController> { | ||
| 34 | final country = controller.state.countries[index]; | 34 | final country = controller.state.countries[index]; |
| 35 | return ListTile( | 35 | return ListTile( |
| 36 | onTap: () { | 36 | onTap: () { |
| 37 | - Get.toNamed('/details', arguments: country); | 37 | + Get.toNamed('/home/country/details', |
| 38 | + arguments: country); | ||
| 38 | }, | 39 | }, |
| 39 | trailing: CircleAvatar( | 40 | trailing: CircleAvatar( |
| 40 | backgroundImage: NetworkImage( | 41 | backgroundImage: NetworkImage( |
| @@ -68,7 +68,7 @@ class HomeView extends GetView<HomeController> { | @@ -68,7 +68,7 @@ class HomeView extends GetView<HomeController> { | ||
| 68 | ), | 68 | ), |
| 69 | shape: StadiumBorder(), | 69 | shape: StadiumBorder(), |
| 70 | onPressed: () { | 70 | onPressed: () { |
| 71 | - Get.toNamed('/country'); | 71 | + Get.toNamed('/home/country'); |
| 72 | }, | 72 | }, |
| 73 | child: Text( | 73 | child: Text( |
| 74 | "Fetch by country", | 74 | "Fetch by country", |
| @@ -16,14 +16,17 @@ class AppPages { | @@ -16,14 +16,17 @@ class AppPages { | ||
| 16 | name: Routes.HOME, | 16 | name: Routes.HOME, |
| 17 | page: () => HomeView(), | 17 | page: () => HomeView(), |
| 18 | binding: HomeBinding(), | 18 | binding: HomeBinding(), |
| 19 | - ), | 19 | + children: [ |
| 20 | GetPage( | 20 | GetPage( |
| 21 | name: Routes.COUNTRY, | 21 | name: Routes.COUNTRY, |
| 22 | page: () => CountryView(), | 22 | page: () => CountryView(), |
| 23 | - ), | 23 | + children: [ |
| 24 | GetPage( | 24 | GetPage( |
| 25 | name: Routes.DETAILS, | 25 | name: Routes.DETAILS, |
| 26 | page: () => DetailsView(), | 26 | page: () => DetailsView(), |
| 27 | ), | 27 | ), |
| 28 | + ], | ||
| 29 | + ), | ||
| 30 | + ]), | ||
| 28 | ]; | 31 | ]; |
| 29 | } | 32 | } |
| @@ -116,8 +116,8 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -116,8 +116,8 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 116 | Animation<double> animation, | 116 | Animation<double> animation, |
| 117 | Animation<double> secondaryAnimation, | 117 | Animation<double> secondaryAnimation, |
| 118 | ) { | 118 | ) { |
| 119 | - | ||
| 120 | // Get.reference = settings.name ?? routeName; | 119 | // Get.reference = settings.name ?? routeName; |
| 120 | + Get.reference = reference; | ||
| 121 | 121 | ||
| 122 | final middlewareRunner = MiddlewareRunner(middlewares); | 122 | final middlewareRunner = MiddlewareRunner(middlewares); |
| 123 | final bindingsToBind = middlewareRunner.runOnBindingsStart(bindings); | 123 | final bindingsToBind = middlewareRunner.runOnBindingsStart(bindings); |
| @@ -396,7 +396,6 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -396,7 +396,6 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 396 | 396 | ||
| 397 | final middlewareRunner = MiddlewareRunner(middlewares); | 397 | final middlewareRunner = MiddlewareRunner(middlewares); |
| 398 | middlewareRunner.runOnPageDispose(); | 398 | middlewareRunner.runOnPageDispose(); |
| 399 | - | ||
| 400 | } | 399 | } |
| 401 | } | 400 | } |
| 402 | 401 |
| @@ -234,10 +234,14 @@ class RxString extends _RxImpl<String> { | @@ -234,10 +234,14 @@ class RxString extends _RxImpl<String> { | ||
| 234 | class Rx<T> extends _RxImpl<T> { | 234 | class Rx<T> extends _RxImpl<T> { |
| 235 | Rx([T initial]) : super(initial); | 235 | Rx([T initial]) : super(initial); |
| 236 | 236 | ||
| 237 | - // TODO: Look for a way to throw the Exception with proper details when the | ||
| 238 | - // value [T] doesn't implement toJson(). | ||
| 239 | @override | 237 | @override |
| 240 | - dynamic toJson() => (value as dynamic)?.toJson(); | 238 | + dynamic toJson() { |
| 239 | + try { | ||
| 240 | + return (value as dynamic)?.toJson(); | ||
| 241 | + } on Exception catch (_) { | ||
| 242 | + throw '$T has not method [toJson]'; | ||
| 243 | + } | ||
| 244 | + } | ||
| 241 | } | 245 | } |
| 242 | 246 | ||
| 243 | extension StringExtension on String { | 247 | extension StringExtension on String { |
| 1 | name: get | 1 | name: get |
| 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. | 2 | description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. |
| 3 | -version: 3.20.0 | 3 | +version: 3.20.1 |
| 4 | homepage: https://github.com/jonataslaw/getx | 4 | homepage: https://github.com/jonataslaw/getx |
| 5 | 5 | ||
| 6 | environment: | 6 | environment: |
| 1 | +import 'package:flutter/widgets.dart'; | ||
| 2 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 3 | +import 'package:get/get.dart'; | ||
| 4 | + | ||
| 5 | +import 'utils/wrapper.dart'; | ||
| 6 | + | ||
| 7 | +void main() { | ||
| 8 | + testWidgets("Test dispose dependencies with unnamed routes", (tester) async { | ||
| 9 | + await tester.pumpWidget( | ||
| 10 | + Wrapper(child: Container()), | ||
| 11 | + ); | ||
| 12 | + | ||
| 13 | + expect(Get.isRegistered<Controller2>(), false); | ||
| 14 | + expect(Get.isRegistered<Controller>(), false); | ||
| 15 | + | ||
| 16 | + Get.to(First()); | ||
| 17 | + | ||
| 18 | + await tester.pumpAndSettle(); | ||
| 19 | + | ||
| 20 | + expect(find.byType(First), findsOneWidget); | ||
| 21 | + | ||
| 22 | + expect(Get.isRegistered<Controller>(), true); | ||
| 23 | + | ||
| 24 | + Get.to(Second()); | ||
| 25 | + | ||
| 26 | + await tester.pumpAndSettle(); | ||
| 27 | + | ||
| 28 | + expect(find.byType(Second), findsOneWidget); | ||
| 29 | + | ||
| 30 | + expect(Get.isRegistered<Controller>(), true); | ||
| 31 | + expect(Get.isRegistered<Controller2>(), true); | ||
| 32 | + | ||
| 33 | + Get.back(); | ||
| 34 | + | ||
| 35 | + await tester.pumpAndSettle(); | ||
| 36 | + | ||
| 37 | + expect(find.byType(First), findsOneWidget); | ||
| 38 | + | ||
| 39 | + expect(Get.isRegistered<Controller>(), true); | ||
| 40 | + expect(Get.isRegistered<Controller2>(), false); | ||
| 41 | + | ||
| 42 | + Get.back(); | ||
| 43 | + | ||
| 44 | + await tester.pumpAndSettle(); | ||
| 45 | + | ||
| 46 | + expect(Get.isRegistered<Controller>(), false); | ||
| 47 | + expect(Get.isRegistered<Controller2>(), false); | ||
| 48 | + }); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +class Controller extends GetxController {} | ||
| 52 | + | ||
| 53 | +class Controller2 extends GetxController {} | ||
| 54 | + | ||
| 55 | +class First extends StatelessWidget { | ||
| 56 | + @override | ||
| 57 | + Widget build(BuildContext context) { | ||
| 58 | + Get.put(Controller()); | ||
| 59 | + return Center( | ||
| 60 | + child: Text("first"), | ||
| 61 | + ); | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +class Second extends StatelessWidget { | ||
| 66 | + @override | ||
| 67 | + Widget build(BuildContext context) { | ||
| 68 | + Get.put(Controller2()); | ||
| 69 | + return Center( | ||
| 70 | + child: Text("second"), | ||
| 71 | + ); | ||
| 72 | + } | ||
| 73 | +} |
| @@ -9,7 +9,7 @@ class RedirectMiddleware extends GetMiddleware { | @@ -9,7 +9,7 @@ class RedirectMiddleware extends GetMiddleware { | ||
| 9 | RouteSettings redirect(String route) => RouteSettings(name: '/second'); | 9 | RouteSettings redirect(String route) => RouteSettings(name: '/second'); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | -main() { | 12 | +void main() { |
| 13 | testWidgets("Middleware redirect smoke test", (tester) async { | 13 | testWidgets("Middleware redirect smoke test", (tester) async { |
| 14 | await tester.pumpWidget( | 14 | await tester.pumpWidget( |
| 15 | GetMaterialApp( | 15 | GetMaterialApp( |
-
Please register or login to post a comment