From a3b941a4b442758081005730de47548efcc21c8d Mon Sep 17 00:00:00 2001 From: xamantra Date: Fri, 8 Jan 2021 08:41:21 +0800 Subject: [PATCH] Renamed `Router` class to `MomentumRouter` #31 --- .gitignore | 1 + coverage/lcov.info | 196 +++++++++++++------------ docs/_sidebar.md | 4 +- docs/event-system.md | 2 +- docs/inject_service.md | 2 +- docs/momentum-controller.md | 2 +- docs/persistence.md | 14 +- docs/restart-app.md | 4 +- docs/router.md | 38 ++--- docs/router_mixin.md | 6 +- docs/streams.md | 2 +- lib/momentum.dart | 2 +- lib/src/in_memory_storage.dart | 1 + lib/src/momentum_base.dart | 21 ++- lib/src/momentum_router.dart | 28 ++-- test/momentum_tester.dart | 2 +- test/router.dart | 52 +++---- test/widgets/counter_obsolete.dart | 1 + test/widgets/router_error_widget.dart | 6 +- test/widgets/router_exit.dart | 6 +- test/widgets/router_page_test_pop.dart | 10 +- test/widgets/router_params.dart | 20 +-- test/widgets/router_test_widget.dart | 14 +- test/widgets/router_transition.dart | 10 +- 24 files changed, 225 insertions(+), 219 deletions(-) diff --git a/.gitignore b/.gitignore index df3f9ef..ffffc6b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ doc/api/ /.idea/dictionaries/xamantra.xml example/lib/temp.dart CODECOV_TOKEN +sandbox/ \ No newline at end of file diff --git a/coverage/lcov.info b/coverage/lcov.info index 06c2d10..cd7b157 100644 --- a/coverage/lcov.info +++ b/coverage/lcov.info @@ -549,115 +549,119 @@ DA:1559,2 DA:1561,1 DA:1563,2 DA:1564,1 -DA:1575,2 -DA:1576,4 -DA:1577,4 -DA:1578,2 -DA:1579,1 -DA:1580,1 +DA:1574,1 +DA:1576,2 +DA:1577,2 +DA:1578,1 +DA:1579,0 +DA:1580,0 DA:1588,2 -DA:1589,2 -DA:1598,1 -DA:1599,2 -DA:1605,1 -DA:1609,2 -DA:1612,2 -DA:1613,4 -DA:1616,1 -DA:1617,2 -DA:1620,1 -DA:1628,1 -DA:1631,3 -DA:1632,3 -DA:1633,3 -DA:1634,3 -DA:1635,3 -DA:1636,3 +DA:1589,4 +DA:1590,4 +DA:1591,2 +DA:1592,1 +DA:1593,1 +DA:1603,1 +DA:1605,2 +DA:1611,1 +DA:1615,2 +DA:1618,2 +DA:1619,4 +DA:1622,1 +DA:1623,2 +DA:1626,1 +DA:1634,1 DA:1637,3 DA:1638,3 -DA:1642,1 -DA:1644,1 -DA:1645,2 -DA:1646,1 -DA:1647,2 -DA:1650,2 +DA:1639,3 +DA:1640,3 +DA:1641,3 +DA:1642,3 +DA:1643,3 +DA:1644,3 +DA:1648,1 +DA:1650,1 DA:1651,2 -DA:1652,2 -DA:1657,1 +DA:1652,1 +DA:1653,2 +DA:1656,2 +DA:1657,2 DA:1658,2 -DA:1659,1 DA:1663,1 DA:1664,2 -DA:1666,1 -DA:1667,1 -DA:1668,1 +DA:1665,1 DA:1669,1 -DA:1670,1 -DA:1671,1 +DA:1670,2 DA:1672,1 -DA:1674,2 -DA:1679,1 -DA:1680,3 -DA:1681,1 -DA:1683,2 +DA:1673,1 +DA:1674,1 +DA:1675,1 +DA:1676,1 +DA:1677,1 +DA:1678,1 +DA:1680,2 DA:1685,1 -DA:1690,1 -DA:1691,2 -DA:1692,3 -DA:1693,1 -DA:1695,1 -DA:1696,2 +DA:1686,3 +DA:1687,1 +DA:1689,2 +DA:1691,1 +DA:1696,1 DA:1697,2 -DA:1698,1 -DA:1699,2 -DA:1700,2 -DA:1701,3 -DA:1705,1 +DA:1698,3 +DA:1699,1 +DA:1701,1 +DA:1702,2 +DA:1703,2 +DA:1704,1 +DA:1705,2 DA:1706,2 -DA:1707,4 -DA:1708,1 +DA:1707,3 +DA:1711,1 +DA:1712,2 +DA:1713,4 DA:1714,1 -DA:1715,1 -DA:1716,2 -DA:1717,1 -DA:1719,2 DA:1720,1 -DA:1724,2 -DA:1725,3 +DA:1721,1 +DA:1722,2 +DA:1723,1 +DA:1725,2 DA:1726,1 -DA:1729,1 -DA:1730,1 -DA:1731,4 -DA:1733,1 -DA:1734,1 +DA:1730,2 +DA:1731,3 +DA:1732,1 DA:1735,1 -DA:1737,1 -DA:1738,4 +DA:1736,1 +DA:1737,4 +DA:1739,1 DA:1740,1 -DA:1744,1 -DA:1745,1 -DA:1746,4 -DA:1748,1 -DA:1749,1 +DA:1741,1 +DA:1743,1 +DA:1744,4 +DA:1746,1 +DA:1750,1 DA:1751,1 -DA:1752,6 -DA:1753,1 +DA:1752,4 +DA:1754,1 DA:1755,1 -DA:1758,2 +DA:1757,1 +DA:1758,6 DA:1759,1 -DA:1761,2 -DA:1768,1 -DA:1769,3 -DA:1775,1 -DA:1776,1 -DA:1777,1 -DA:1778,1 -DA:1779,2 +DA:1761,1 +DA:1764,2 +DA:1765,1 +DA:1767,2 +DA:1774,1 +DA:1775,3 +DA:1781,1 +DA:1782,1 +DA:1783,1 DA:1784,1 DA:1785,2 -DA:1786,3 -LF:657 -LH:657 +DA:1790,1 +DA:1791,2 +DA:1792,3 +LF:661 +LH:659 end_of_record SF:lib\src\momentum_router.dart DA:10,1 @@ -796,16 +800,16 @@ DA:5,3 DA:12,1 DA:13,2 DA:14,2 -DA:18,1 -DA:20,1 -DA:22,3 -DA:23,2 -DA:29,1 -DA:30,3 -DA:31,5 -DA:36,1 -DA:37,2 +DA:19,1 +DA:21,1 +DA:23,3 +DA:24,2 +DA:30,1 +DA:31,3 +DA:32,5 +DA:37,1 DA:38,2 +DA:39,2 LF:14 LH:14 end_of_record diff --git a/docs/_sidebar.md b/docs/_sidebar.md index b1b4c99..a5666f0 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -28,8 +28,8 @@ - [MomentumState](momentum-state.md "MomentumState - For event system | Momentum") - [MomentumService](momentum-service.md "MomentumService - Services Dependency Injection | Momentum") - [InjectService](inject_service.md "InjectService - Indentical Services Dependency Injection | Momentum") - - [Router](router.md "Router - For persistent routing | Momentum") - - [RouterMixin](router_mixin.md "Router - Handling route parameters | Momentum") + - [MomentumRouter](router.md "MomentumRouter - For persistent routing | Momentum") + - [RouterMixin](router_mixin.md "MomentumRouter - Handling route parameters | Momentum") - [MomentumTester](momentum-tester.md "MomentumTester - Testing tool | Momentum") - More diff --git a/docs/event-system.md b/docs/event-system.md index 70f89da..7789aca 100644 --- a/docs/event-system.md +++ b/docs/event-system.md @@ -82,7 +82,7 @@ class _LoginWidgetState extends MomentumState { invoke: (event) { switch (event.action) { case LoginEventAction.LoginSuccess: - Router.goto(context, Home); + MomentumRouter.goto(context, Home); break; case LoginEventAction.UsernameDoesntExists: showSnackbar(message: event.message); diff --git a/docs/inject_service.md b/docs/inject_service.md index 2cee3e3..c9bd73d 100644 --- a/docs/inject_service.md +++ b/docs/inject_service.md @@ -62,4 +62,4 @@ InjectService(ApiAlias.withLogs, ApiService(enableLogs: true)), ``` Momentum will just basically return the one tagged with `ApiAlias.withoutLogs` because it if the first instance. -!> `InjectService` is also a built in `MomentumService` like the `Router`. \ No newline at end of file +!> `InjectService` is also a built in `MomentumService` like the `MomentumRouter`. \ No newline at end of file diff --git a/docs/momentum-controller.md b/docs/momentum-controller.md index 09f0f81..7cb2324 100644 --- a/docs/momentum-controller.md +++ b/docs/momentum-controller.md @@ -273,7 +273,7 @@ class _ExampleState extends MomentumState { // "event" is of type "LoginEvent". if (event.success) { // go to home page for example. - Router.goto(context, Home); + MomentumRouter.goto(context, Home); } else { showSnackbar(message: event.message, error: true); } diff --git a/docs/persistence.md b/docs/persistence.md index c6ccdec..80c2995 100644 --- a/docs/persistence.md +++ b/docs/persistence.md @@ -98,13 +98,13 @@ Momentum has a custom router system to enable persistence for the app's navigati - The featured example app for momentum implements this feature. See this [preview](/?id=preview). - #### Guide - 1. You need to instantiate the built-in service called `Router` in the momentum root widget in the `services` parameter. The `Router` class has a parameter which is a list of widgets and those widgets must be a screen or page type widgets: + 1. You need to instantiate the built-in service called `MomentumRouter` in the momentum root widget in the `services` parameter. The `MomentumRouter` class has a parameter which is a list of widgets and those widgets must be a screen or page type widgets: ```dart Momentum( // ... services: [ // ... - Router([ + MomentumRouter([ PageA(), PageB(), PageC(), @@ -131,13 +131,13 @@ Momentum has a custom router system to enable persistence for the app's navigati } } ``` - 3. Now you can navigate between pages using `Router.goto(...)` and `Router.pop(context)`: + 3. Now you can navigate between pages using `MomentumRouter.goto(...)` and `MomentumRouter.pop(context)`: ```dart // "PageC". use type not an instance or string route name. - Router.goto(context, PageC); + MomentumRouter.goto(context, PageC); // Go back to previous page - Router.pop(context); + MomentumRouter.pop(context); ``` - As you can see in the guide section above, you navigate between pages using *types* not instance or string route name. That is one of the best parts of momentum. @@ -148,5 +148,5 @@ Momentum has a custom router system to enable persistence for the app's navigati - `persistSave` will use the `.toJson()` serialization. - `persistGet` will use the `.fromJson(...)` serialization. -- `Router` uses both `persistSave` and `persistGet`. So if you want to use persistent navigation you need to implement those two function parameters. -- The Persistent router saves the `indexes` of the pages. If you added a new page or reordered the items in the list inside the `Router` constructor, it is recommended to clear the data of the app to avoid errors. \ No newline at end of file +- `MomentumRouter` uses both `persistSave` and `persistGet`. So if you want to use persistent navigation you need to implement those two function parameters. +- The Persistent router saves the `indexes` of the pages. If you added a new page or reordered the items in the list inside the `MomentumRouter` constructor, it is recommended to clear the data of the app to avoid errors. \ No newline at end of file diff --git a/docs/restart-app.md b/docs/restart-app.md index e6b3d6c..c67bcbf 100644 --- a/docs/restart-app.md +++ b/docs/restart-app.md @@ -51,10 +51,10 @@ Momentum momentum() { Here's the two line code you're waiting for: ```dart -await Router.resetWithContext(context); +await MomentumRouter.resetWithContext(context); Momentum.restart(context, momentum()); ``` -- If you are using persistent navigation, we need to call `Router.resetWithContext` to set the initial page when the app restarts. +- If you are using persistent navigation, we need to call `MomentumRouter.resetWithContext` to set the initial page when the app restarts. - `Momentum.restart(...)` called the method `momentum()`. - Requires context so you need to call this inside a widget like a button click. \ No newline at end of file diff --git a/docs/router.md b/docs/router.md index 2ea29f1..e5852a1 100644 --- a/docs/router.md +++ b/docs/router.md @@ -1,4 +1,4 @@ -# Router +# MomentumRouter A built-in `MomentumService` for persistent navigation system. ```dart void main() { @@ -6,7 +6,7 @@ void main() { Momentum( // child: ..., services: [ - Router([ + MomentumRouter([ LoginPage(), HomePage(), SettingsPage(), @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget { return MaterialApp( title: // ..., theme: // ..., - home: Router.getActivePage(context), + home: MomentumRouter.getActivePage(context), // ... ); } @@ -48,13 +48,13 @@ class MyApp extends StatelessWidget { The function to navigate to a specific route. You specify the route using a `type` NOT a string route name or a MaterialPageRoute. You can also create a custom transition animation using the `transition` parameter. This is equivalent to `Navigator.push(...)`. You can also optionally pass in a route param and access it anywhere. ```dart // go to home page -Router.goto(context, HomePage); +MomentumRouter.goto(context, HomePage); // with parameters -Router.goto(context, HomePage, params: HomeParam(title: 'Hello World')); +MomentumRouter.goto(context, HomePage, params: HomeParam(title: 'Hello World')); // access the parameters using context -var param = Router.getParam(context); +var param = MomentumRouter.getParam(context); print(param.title); // or display it in a widget ... // access the parameters inside the controller @@ -62,7 +62,7 @@ var param = getParam(); print(param.title); // or bind this in your model ... // with custom animation -Router.goto( +MomentumRouter.goto( context, HomePage, transition: (context, page) { @@ -79,16 +79,16 @@ Router.goto( - Category: `Static Method` - Type: `void` -Equivalent to `Navigator.pop(...)`. For closing dialogs, do not use this one, use `Navigator.pop(...)` instead. Similar to `Router.goto`, you can also pass in parameters optionally but the name is `result`. The reason why it's named `result` is to follow flutter's original convention for `Navigator.pop` which also has `result` parameter. +Equivalent to `Navigator.pop(...)`. For closing dialogs, do not use this one, use `Navigator.pop(...)` instead. Similar to `MomentumRouter.goto`, you can also pass in parameters optionally but the name is `result`. The reason why it's named `result` is to follow flutter's original convention for `Navigator.pop` which also has `result` parameter. ```dart // go back to the previous page. -Router.pop(context); +MomentumRouter.pop(context); // with parameters, assuming you are from HomePage. -Router.pop(context, result: LoginParam(action: 'User had logged out.')); +MomentumRouter.pop(context, result: LoginParam(action: 'User had logged out.')); // access the parameters using context -var param = Router.getParam(context); +var param = MomentumRouter.getParam(context); print(param.action); // or display it in a widget ... // access the parameters inside the controller @@ -96,7 +96,7 @@ var param = getParam(); print(param.action); // or bind this in your model ... // with custom animation -Router.goto( +MomentumRouter.goto( context, transition: (context, page) { // MaterialPageRoute is not the one you need here :) @@ -123,7 +123,7 @@ class ExampleParam extends RouterParam { // usage -Router.goto(context, HomePage, params: ExampleParam('Hello', 'World')); +MomentumRouter.goto(context, HomePage, params: ExampleParam('Hello', 'World')); ```
@@ -132,7 +132,7 @@ Router.goto(context, HomePage, params: ExampleParam('Hello', 'World')); - Category: `Static Method` - Type: `T` extends `RouterParam` -Get the current route parameters specified using the params parameter in Router.goto(...) method. +Get the current route parameters specified using the params parameter in MomentumRouter.goto(...) method. ```dart class ExamplePage extends StatelessWidget { @@ -140,7 +140,7 @@ class ExamplePage extends StatelessWidget { @override Widget build(BuildContext context) { - var param = Router.getParam(context); + var param = MomentumRouter.getParam(context); return Scaffold( body: Column( children: [ @@ -161,7 +161,7 @@ class ExamplePage extends StatelessWidget { Clear the navigation history. Popping will close the app. ```dart -var router = Momentum.service(context); +var router = Momentum.service(context); await router.clearHistory(); ``` @@ -173,7 +173,7 @@ await router.clearHistory(); Shorthand for `.clearHistory()`. ```dart -await Router.clearHistoryWithContext(context); +await MomentumRouter.clearHistoryWithContext(context); ```
@@ -184,7 +184,7 @@ await Router.clearHistoryWithContext(context); Clear navigation history and set an initial page. The recommended use case for this is when you want to restart your app. ```dart -var router = Momentum.service(context); +var router = Momentum.service(context); // this will not automatically go to the login page. await router.reset(); // will be restarted in the login page. @@ -200,7 +200,7 @@ Momentum.restart(context, momentum()); Shorthand for `.reset()`. ```dart // this will not automatically go to login page. -await Router.resetWithContext(context); +await MomentumRouter.resetWithContext(context); // will be restarted in login page. Momentum.restart(context, momentum()); ``` \ No newline at end of file diff --git a/docs/router_mixin.md b/docs/router_mixin.md index aa2a5a3..4ca9410 100644 --- a/docs/router_mixin.md +++ b/docs/router_mixin.md @@ -15,10 +15,10 @@ class ExampleController extends MomentumController with RouterMixi - Category: `Method` - Type: `T` extends `RouterParam` -Get the current route parameters specified using the `params` parameter in `Router.goto(...)` or `Router.pop` method. Returns `null` if no parameter is provided. +Get the current route parameters specified using the `params` parameter in `MomentumRouter.goto(...)` or `MomentumRouter.pop` method. Returns `null` if no parameter is provided. ```dart // setting the route params. -Router.goto(context, DashboardPage, params: ExampleParam(...)); +MomentumRouter.goto(context, DashboardPage, params: ExampleParam(...)); // accessing the route params inside controllers. var params = getParam(); @@ -30,7 +30,7 @@ var params = getParam(); - Category: `Virtual Method` - Type: `void` -A callback whenever `Router.goto` or `Router.pop` is called. The `RouterParam` is also injected here, will be `null` if not provided. +A callback whenever `MomentumRouter.goto` or `MomentumRouter.pop` is called. The `RouterParam` is also injected here, will be `null` if not provided. Example: ```dart diff --git a/docs/streams.md b/docs/streams.md index 6be2b52..8152eba 100644 --- a/docs/streams.md +++ b/docs/streams.md @@ -172,7 +172,7 @@ FlatButton( var chatController = Momentum.controller(context); await chatController.disposeStream(); // set the router to clear history and assign login page as initial page in the route. - await Router.resetWithContext(context); + await MomentumRouter.resetWithContext(context); // restart the app (this will show login page). Momentum.restart(context, momentum()); }, diff --git a/lib/momentum.dart b/lib/momentum.dart index 840a18e..028a21c 100644 --- a/lib/momentum.dart +++ b/lib/momentum.dart @@ -14,4 +14,4 @@ export 'src/momentum_base.dart' InjectService, MomentumTester, RouterMixin; -export 'src/momentum_router.dart' show Router, RouterPage, RouterParam; +export 'src/momentum_router.dart' show MomentumRouter, RouterPage, RouterParam; diff --git a/lib/src/in_memory_storage.dart b/lib/src/in_memory_storage.dart index 6cd6f54..a56b468 100644 --- a/lib/src/in_memory_storage.dart +++ b/lib/src/in_memory_storage.dart @@ -15,6 +15,7 @@ class InMemoryStorage extends MomentumService { } else { InMemoryStorage inMemoryStorage; if (context != null) { + // ignore: deprecated_member_use_from_same_package inMemoryStorage = Momentum.getService(context); } else { inMemoryStorage = InMemoryStorage(); diff --git a/lib/src/momentum_base.dart b/lib/src/momentum_base.dart index 27de969..9a42d59 100644 --- a/lib/src/momentum_base.dart +++ b/lib/src/momentum_base.dart @@ -8,7 +8,6 @@ import 'in_memory_storage.dart'; import 'momentum_error.dart'; import 'momentum_event.dart'; import 'momentum_router.dart'; -import 'momentum_router.dart' as momentum_router; import 'momentum_types.dart'; Type _getType() => T; @@ -83,15 +82,15 @@ class _MomentumListener { /// handle route changes from momentum's built-in routing system. mixin RouterMixin on _ControllerBase { /// Get the current route parameters specified using - /// the `params` parameter in `Router.goto(...)` method. + /// the `params` parameter in `MomentumRouter.goto(...)` method. /// /// ### Example: /// ```dart /// // setting the route params. - /// Router.goto(context, DashboardPage, params: DashboardParams(...)); + /// MomentumRouter.goto(context, DashboardPage, params: DashboardParams(...)); /// /// // accessing the route params inside widgets. - /// var params = Router.getParam(context); + /// var params = MomentumRouter.getParam(context); /// /// // accessing the route params inside controllers. /// var params = getParam(); @@ -108,12 +107,12 @@ mixin RouterMixin on _ControllerBase { } return null; } - var result = momentum_router.Router.getParam(_mRootContext); + var result = MomentumRouter.getParam(_mRootContext); return result; } - /// A callback whenever [momentum_router.Router.goto] - /// or [momentum_router.Router.pop] is called. + /// A callback whenever [momentum_router.MomentumRouter.goto] + /// or [momentum_router.MomentumRouter.pop] is called. /// The [RouterParam] is also provided. void onRouteChanged(RouterParam param) {} } @@ -1169,7 +1168,7 @@ class _MomentumRootState extends State<_MomentumRoot> { for (var service in services) { if (service != null) { service._context = context; - if (service is momentum_router.Router) { + if (service is MomentumRouter) { _momentumEvent.on().listen((event) { for (var controller in widget.controllers) { if (controller is RouterMixin) { @@ -1771,8 +1770,8 @@ class MomentumTester { return result; } - momentum_router.Router _getRouterIfPresent() { - var result = trycatch(() => service()); + MomentumRouter _getRouterIfPresent() { + var result = trycatch(() => service()); return result; } @@ -1788,7 +1787,7 @@ class MomentumTester { /// Mock router params for testing. void mockRouterParam(RouterParam param) { - service().mockParam(param); + service().mockParam(param); print('Mock params has been set (${param.runtimeType}): $param'); } } diff --git a/lib/src/momentum_router.dart b/lib/src/momentum_router.dart index ccc9111..eb8569c 100644 --- a/lib/src/momentum_router.dart +++ b/lib/src/momentum_router.dart @@ -10,12 +10,12 @@ import 'momentum_types.dart'; Type _getType() => T; /// A built-in momentum service for persistent navigation system. -class Router extends MomentumService { - /// Create an instance of [Router] +class MomentumRouter extends MomentumService { + /// Create an instance of [MomentumRouter] /// that can be injected to momentum /// as a service. Takes a list of /// widgets as routes. - Router( + MomentumRouter( List pages, { bool enablePersistence, }) : _pages = pages, @@ -107,7 +107,7 @@ class Router extends MomentumService { _momentumEvent.trigger(RouterSignal(_currentRouteParam)); Navigator.pushAndRemoveUntil(context, r, (r) => false); } else { - print('[$MomentumService -> $Router]: Unable to ' + print('[$MomentumService -> $MomentumRouter]: Unable to ' 'find page widget of type "$route".'); } } @@ -258,7 +258,7 @@ class Router extends MomentumService { Route Function(BuildContext, Widget) transition, RouterParam params, }) { - var service = Momentum.service(context); + var service = Momentum.service(context); service._goto( context, route, @@ -273,7 +273,7 @@ class Router extends MomentumService { Route Function(BuildContext, Widget) transition, RouterParam result, }) { - var service = Momentum.service(context); + var service = Momentum.service(context); var routeResult = service._pop( context, transition: transition, @@ -292,21 +292,21 @@ class Router extends MomentumService { } /// Get the current route parameters specified using - /// the `params` parameter in `Router.goto(...)` method. + /// the `params` parameter in `MomentumRouter.goto(...)` method. /// /// ### Example: /// ```dart /// // setting the route params. - /// Router.goto(context, DashboardPage, params: DashboardParams(...)); + /// MomentumRouter.goto(context, DashboardPage, params: DashboardParams(...)); /// /// // accessing the route params inside widgets. - /// var params = Router.getParam(context); + /// var params = MomentumRouter.getParam(context); /// /// // accessing the route params inside controllers. /// var params = getParam(); /// ``` static T getParam(BuildContext context) { - var service = Momentum.service(context); + var service = Momentum.service(context); var result = service.getCurrentParam(); return result; } @@ -315,14 +315,14 @@ class Router extends MomentumService { /// You may want this to be your initial /// widget when your app starts. static Widget getActivePage(BuildContext context) { - var service = Momentum.service(context); + var service = Momentum.service(context); var page = service.getActive(); return page; } /// Clear navigation history using context. static Future clearHistoryWithContext(BuildContext context) async { - var service = Momentum.service(context); + var service = Momentum.service(context); await service.clearHistory(); } @@ -330,7 +330,7 @@ class Router extends MomentumService { static Future resetWithContext( BuildContext context, ) async { - var service = Momentum.service(context); + var service = Momentum.service(context); await service.reset(); } } @@ -362,7 +362,7 @@ class RouterPage extends StatelessWidget { return WillPopScope( onWillPop: onWillPop ?? () async { - Router.pop(context); + MomentumRouter.pop(context); return false; }, child: child, diff --git a/test/momentum_tester.dart b/test/momentum_tester.dart index 3ce708f..8124964 100644 --- a/test/momentum_tester.dart +++ b/test/momentum_tester.dart @@ -52,7 +52,7 @@ void main() { RouterParamController(), ], services: [ - Router([]), + MomentumRouter([]), ], ), ); diff --git a/test/router.dart b/test/router.dart index c99109f..0adee92 100644 --- a/test/router.dart +++ b/test/router.dart @@ -14,7 +14,7 @@ void main() { testWidgets('Initialize', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); }); @@ -22,7 +22,7 @@ void main() { testWidgets('#1 goto(...)', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(gotoPageBKey)); @@ -33,7 +33,7 @@ void main() { testWidgets('Restart', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); }); @@ -41,7 +41,7 @@ void main() { testWidgets('#2 goto(...)', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); await tester.tap(find.byKey(gotoPageCKey)); @@ -52,7 +52,7 @@ void main() { testWidgets('pop', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); await tester.tap(find.byKey(fromPageCPop)); @@ -63,7 +63,7 @@ void main() { testWidgets('#3 goto(...): error test', (tester) async { var widget = routerErrorTest(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageErrorTestA, true); await tester.tap(find.byKey(errorTestGotoPageBKey)); @@ -75,7 +75,7 @@ void main() { testWidgets('#2 pop(...): exit app', (tester) async { var widget = routerExitApp(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageExitTest, true); await tester.tap(find.byKey(routerExitButtonKey)); @@ -86,7 +86,7 @@ void main() { testWidgets('#1 transition goto(...)', (tester) async { var widget = routerTransitionTest(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is TransitionPageA, true); await tester.tap(find.byKey(transitionToBKey)); @@ -97,7 +97,7 @@ void main() { testWidgets('transition Restart', (tester) async { var widget = routerTransitionTest(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is TransitionPageB, true); }); @@ -105,7 +105,7 @@ void main() { testWidgets('#2 transition goto(...)', (tester) async { var widget = routerTransitionTest(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is TransitionPageB, true); await tester.tap(find.byKey(transitionToCKey)); @@ -119,7 +119,7 @@ void main() { testWidgets('goto and clear history', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); await tester.tap(find.byKey(gotoPageCKey)); @@ -133,7 +133,7 @@ void main() { testWidgets('#1 router reset', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(gotoPageBKey)); @@ -146,7 +146,7 @@ void main() { testWidgets('#2 router reset', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); }); @@ -154,7 +154,7 @@ void main() { testWidgets('clearHistoryWithContext', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); await tester.tap(find.byKey(clearHistoryButton)); @@ -165,7 +165,7 @@ void main() { testWidgets('resetWithContext', (tester) async { var widget = routerTestWidget(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(resetHistoryButton)); @@ -176,7 +176,7 @@ void main() { testWidgets('RouterPage Test', (tester) async { var widget = routerPageTest(); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is RouterPageA, true); await tester.tap(find.byKey(gotoRouterPageB)); @@ -198,7 +198,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); }); @@ -209,7 +209,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(gotoPageBKey)); @@ -223,7 +223,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); }); @@ -234,7 +234,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); await tester.tap(find.byKey(gotoPageCKey)); @@ -248,7 +248,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); await tester.tap(find.byKey(fromPageCPop)); @@ -262,7 +262,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageB, true); await tester.tap(find.byKey(gotoPageCKey)); @@ -279,7 +279,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(gotoPageBKey)); @@ -295,7 +295,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); }); @@ -306,7 +306,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageC, true); await tester.tap(find.byKey(clearHistoryButton)); @@ -320,7 +320,7 @@ void main() { sessionName: 'routerTestWidget: testModeParam', ); await launch(tester, widget); - var router = widget.serviceForTest(); + var router = widget.serviceForTest(); expect(router == null, false); expect(router.getActive() is PageA, true); await tester.tap(find.byKey(resetHistoryButton)); diff --git a/test/widgets/counter_obsolete.dart b/test/widgets/counter_obsolete.dart index 3cf42f7..0f9dd08 100644 --- a/test/widgets/counter_obsolete.dart +++ b/test/widgets/counter_obsolete.dart @@ -33,6 +33,7 @@ class CounterObsoleteApp extends StatelessWidget { floatingActionButton: FloatingActionButton( key: keyCounterObsoleteIncrement, onPressed: () { + // ignore: deprecated_member_use_from_same_package Momentum.of(context).increment(); }, ), diff --git a/test/widgets/router_error_widget.dart b/test/widgets/router_error_widget.dart index d936df8..d1c6b0a 100644 --- a/test/widgets/router_error_widget.dart +++ b/test/widgets/router_error_widget.dart @@ -12,7 +12,7 @@ Momentum routerErrorTest() { child: MyApp(), controllers: [CounterController()], services: [ - momentum.Router([ + momentum.MomentumRouter([ PageErrorTestA(), ]), InMemoryStorage(), @@ -37,7 +37,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Counter App', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -54,7 +54,7 @@ class PageErrorTestA extends StatelessWidget { child: FlatButton( key: errorTestGotoPageBKey, onPressed: () { - momentum.Router.goto(context, PageErrorTestB); + momentum.MomentumRouter.goto(context, PageErrorTestB); }, child: Text('Goto PageB'), ), diff --git a/test/widgets/router_exit.dart b/test/widgets/router_exit.dart index 2b86bbc..536b2f2 100644 --- a/test/widgets/router_exit.dart +++ b/test/widgets/router_exit.dart @@ -12,7 +12,7 @@ Momentum routerExitApp() { child: MyApp(), controllers: [CounterController()], services: [ - momentum.Router([ + momentum.MomentumRouter([ PageExitTest(), ]), InMemoryStorage(), @@ -37,7 +37,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Counter App', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -54,7 +54,7 @@ class PageExitTest extends StatelessWidget { child: FlatButton( key: routerExitButtonKey, onPressed: () { - momentum.Router.pop(context); + momentum.MomentumRouter.pop(context); }, child: Text('Exit'), ), diff --git a/test/widgets/router_page_test_pop.dart b/test/widgets/router_page_test_pop.dart index 539feb3..3687e43 100644 --- a/test/widgets/router_page_test_pop.dart +++ b/test/widgets/router_page_test_pop.dart @@ -13,7 +13,7 @@ Momentum routerPageTest() { child: MyApp(), controllers: [CounterController()], services: [ - momentum.Router([ + momentum.MomentumRouter([ RouterPageA(), RouterPageB(), ]), @@ -39,7 +39,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Counter App', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -60,7 +60,7 @@ class RouterPageA extends StatelessWidget { FlatButton( key: gotoRouterPageB, onPressed: () { - momentum.Router.goto(context, RouterPageB); + momentum.MomentumRouter.goto(context, RouterPageB); }, child: Text('Goto PageB'), ), @@ -81,7 +81,7 @@ class RouterPageB extends StatelessWidget { Widget build(BuildContext context) { return RouterPage( onWillPop: () async { - momentum.Router.pop(context); + momentum.MomentumRouter.pop(context); return false; }, child: Scaffold( @@ -91,7 +91,7 @@ class RouterPageB extends StatelessWidget { FlatButton( key: gotoRouterPopKey, onPressed: () { - momentum.Router.pop(context); + momentum.MomentumRouter.pop(context); }, child: Text('Pop'), ), diff --git a/test/widgets/router_params.dart b/test/widgets/router_params.dart index e24abc4..80fdd61 100644 --- a/test/widgets/router_params.dart +++ b/test/widgets/router_params.dart @@ -20,7 +20,7 @@ Momentum routerParamsTest([String sessionKey]) { RouterParamMixinController(), ], services: [ - momentum.Router([ + momentum.MomentumRouter([ RouterParamsTestA(), RouterParamsTestB(), RouterParamsTestC(), @@ -95,7 +95,7 @@ class BasePage extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'BasePage', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -112,7 +112,7 @@ class RouterParamsTestA extends StatelessWidget { FlatButton( key: routerParamsBTestButtonKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, RouterParamsTestB, params: TestRouterParamsB('Hello World'), @@ -123,7 +123,7 @@ class RouterParamsTestA extends StatelessWidget { FlatButton( key: routerParamsCTestButtonKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, RouterParamsTestC, params: TestRouterParamsB('Hello World'), @@ -134,7 +134,7 @@ class RouterParamsTestA extends StatelessWidget { FlatButton( key: routerParamsDTestButtonKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, RouterParamsTestD, params: TestRouterParamsC('Flutter is awesome!'), @@ -153,7 +153,7 @@ class RouterParamsTestB extends StatelessWidget { @override Widget build(BuildContext context) { - var params = momentum.Router.getParam(context); + var params = momentum.MomentumRouter.getParam(context); return Scaffold( body: Text(params.value), ); @@ -165,7 +165,7 @@ class RouterParamsTestC extends StatelessWidget { @override Widget build(BuildContext context) { - var params = momentum.Router.getParam(context); + var params = momentum.MomentumRouter.getParam(context); return Scaffold( body: Column( children: [ @@ -189,7 +189,7 @@ class RouterParamsTestD extends StatelessWidget { FlatButton( key: routerParamsDErrorButtonKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, RouterParamsTestE, params: TestRouterParamsD('12345'), @@ -208,7 +208,7 @@ class RouterParamsTestE extends StatelessWidget { @override Widget build(BuildContext context) { - var params = momentum.Router.getParam(context); + var params = momentum.MomentumRouter.getParam(context); return Scaffold( body: Column( children: [ @@ -216,7 +216,7 @@ class RouterParamsTestE extends StatelessWidget { FlatButton( key: routerParamsPopButtonKey, onPressed: () { - momentum.Router.pop( + momentum.MomentumRouter.pop( context, result: TestRouterParamsC('789'), ); diff --git a/test/widgets/router_test_widget.dart b/test/widgets/router_test_widget.dart index e84682a..cec0d5c 100644 --- a/test/widgets/router_test_widget.dart +++ b/test/widgets/router_test_widget.dart @@ -21,7 +21,7 @@ Momentum routerTestWidget({ child: MyApp(), controllers: [CounterController()], services: [ - momentum.Router([ + momentum.MomentumRouter([ PageA(), PageB(), PageC(), @@ -48,7 +48,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Counter App', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -67,14 +67,14 @@ class PageA extends StatelessWidget { FlatButton( key: gotoPageBKey, onPressed: () { - momentum.Router.goto(context, PageB); + momentum.MomentumRouter.goto(context, PageB); }, child: Text('Goto PageB'), ), FlatButton( key: resetHistoryButton, onPressed: () { - momentum.Router.resetWithContext(context); + momentum.MomentumRouter.resetWithContext(context); }, child: Text('Reset Router'), ), @@ -95,7 +95,7 @@ class PageB extends StatelessWidget { child: FlatButton( key: gotoPageCKey, onPressed: () { - momentum.Router.goto(context, PageC); + momentum.MomentumRouter.goto(context, PageC); }, child: Text('Goto PageC'), ), @@ -116,14 +116,14 @@ class PageC extends StatelessWidget { FlatButton( key: fromPageCPop, onPressed: () { - momentum.Router.pop(context); + momentum.MomentumRouter.pop(context); }, child: Text('Pop From PageC'), ), FlatButton( key: clearHistoryButton, onPressed: () { - momentum.Router.clearHistoryWithContext(context); + momentum.MomentumRouter.clearHistoryWithContext(context); }, child: Text('Clear History'), ), diff --git a/test/widgets/router_transition.dart b/test/widgets/router_transition.dart index 582e85c..ba71818 100644 --- a/test/widgets/router_transition.dart +++ b/test/widgets/router_transition.dart @@ -14,7 +14,7 @@ Momentum routerTransitionTest() { child: MyApp(), controllers: [CounterController()], services: [ - momentum.Router([ + momentum.MomentumRouter([ TransitionPageA(), TransitionPageB(), TransitionPageC(), @@ -41,7 +41,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Counter App', - home: momentum.Router.getActivePage(context), + home: momentum.MomentumRouter.getActivePage(context), ); } } @@ -58,7 +58,7 @@ class TransitionPageA extends StatelessWidget { child: FlatButton( key: transitionToBKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, TransitionPageB, transition: (context, page) { @@ -83,7 +83,7 @@ class TransitionPageB extends StatelessWidget { child: FlatButton( key: transitionToCKey, onPressed: () { - momentum.Router.goto( + momentum.MomentumRouter.goto( context, TransitionPageC, transition: (context, page) { @@ -108,7 +108,7 @@ class TransitionPageC extends StatelessWidget { child: FlatButton( key: transitionCPop, onPressed: () { - momentum.Router.pop(context, transition: (context, page) { + momentum.MomentumRouter.pop(context, transition: (context, page) { return MaterialPageRoute(builder: (context) => page); }); },