Showing
8 changed files
with
80 additions
and
25 deletions
@@ -71,9 +71,7 @@ class HomeView extends GetView<HomeController> { | @@ -71,9 +71,7 @@ class HomeView extends GetView<HomeController> { | ||
71 | shape: StadiumBorder(), | 71 | shape: StadiumBorder(), |
72 | ), | 72 | ), |
73 | onPressed: () async { | 73 | onPressed: () async { |
74 | - final data = | ||
75 | - await Get.rootDelegate.toNamed('/home/country'); | ||
76 | - print('DATA: $data'); | 74 | + await Get.rootDelegate.toNamed('/home/country'); |
77 | }, | 75 | }, |
78 | child: Text( | 76 | child: Text( |
79 | 'fetch_country'.tr, | 77 | 'fetch_country'.tr, |
1 | +import 'dart:async'; | ||
2 | + | ||
3 | +import 'package:get/get.dart'; | ||
4 | +import 'package:async/async.dart'; | ||
5 | + | ||
6 | +class SplashService extends GetxService { | ||
7 | + final welcomeStr = ['GetX', 'Rules!']; | ||
8 | + final activeStr = 0.obs; | ||
9 | + | ||
10 | + final memo = AsyncMemoizer<void>(); | ||
11 | + Future<void> init() { | ||
12 | + return memo.runOnce(_initFunction); | ||
13 | + } | ||
14 | + | ||
15 | + void _changeActiveString() { | ||
16 | + activeStr.value = (activeStr.value + 1) % welcomeStr.length; | ||
17 | + } | ||
18 | + | ||
19 | + Future<void> _initFunction() async { | ||
20 | + final t = Timer.periodic( | ||
21 | + Duration(milliseconds: 500), | ||
22 | + (t) => _changeActiveString(), | ||
23 | + ); | ||
24 | + //simulate some long running operation | ||
25 | + await Future.delayed(Duration(seconds: 5)); | ||
26 | + //cancel the timer once we are done | ||
27 | + t.cancel(); | ||
28 | + } | ||
29 | +} |
1 | +import 'package:flutter/material.dart'; | ||
2 | + | ||
3 | +import 'package:get/get.dart'; | ||
4 | + | ||
5 | +import '../controllers/splash_service.dart'; | ||
6 | + | ||
7 | +class SplashView extends GetView<SplashService> { | ||
8 | + @override | ||
9 | + Widget build(BuildContext context) { | ||
10 | + return Scaffold( | ||
11 | + body: Center( | ||
12 | + child: Column( | ||
13 | + mainAxisSize: MainAxisSize.min, | ||
14 | + children: [ | ||
15 | + Obx( | ||
16 | + () => Text( | ||
17 | + controller.welcomeStr[controller.activeStr.value], | ||
18 | + style: TextStyle(fontSize: 20), | ||
19 | + ), | ||
20 | + ), | ||
21 | + CircularProgressIndicator(), | ||
22 | + ], | ||
23 | + ), | ||
24 | + ), | ||
25 | + ); | ||
26 | + } | ||
27 | +} |
1 | +import 'package:example_nav2/app/modules/splash/controllers/splash_service.dart'; | ||
2 | +import 'package:example_nav2/app/modules/splash/views/splash_view.dart'; | ||
1 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
2 | import 'package:get/get.dart'; | 4 | import 'package:get/get.dart'; |
3 | 5 | ||
@@ -10,10 +12,23 @@ void main() { | @@ -10,10 +12,23 @@ void main() { | ||
10 | title: "Application", | 12 | title: "Application", |
11 | initialBinding: BindingsBuilder( | 13 | initialBinding: BindingsBuilder( |
12 | () { | 14 | () { |
15 | + Get.put(SplashService()); | ||
13 | Get.put(AuthService()); | 16 | Get.put(AuthService()); |
14 | }, | 17 | }, |
15 | ), | 18 | ), |
16 | getPages: AppPages.routes, | 19 | getPages: AppPages.routes, |
20 | + builder: (context, child) { | ||
21 | + return FutureBuilder<void>( | ||
22 | + key: ValueKey('initFuture'), | ||
23 | + future: Get.find<SplashService>().init(), | ||
24 | + builder: (context, snapshot) { | ||
25 | + if (snapshot.connectionState == ConnectionState.done) { | ||
26 | + return child ?? SizedBox.shrink(); | ||
27 | + } | ||
28 | + return SplashView(); | ||
29 | + }, | ||
30 | + ); | ||
31 | + }, | ||
17 | // routeInformationParser: GetInformationParser( | 32 | // routeInformationParser: GetInformationParser( |
18 | // // initialRoute: Routes.HOME, | 33 | // // initialRoute: Routes.HOME, |
19 | // ), | 34 | // ), |
@@ -2,8 +2,6 @@ | @@ -2,8 +2,6 @@ | ||
2 | // Generated file. Do not edit. | 2 | // Generated file. Do not edit. |
3 | // | 3 | // |
4 | 4 | ||
5 | -// clang-format off | ||
6 | - | ||
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ |
8 | #define GENERATED_PLUGIN_REGISTRANT_ | 6 | #define GENERATED_PLUGIN_REGISTRANT_ |
9 | 7 |
@@ -56,5 +56,5 @@ class GetNavConfig extends RouteInformation { | @@ -56,5 +56,5 @@ class GetNavConfig extends RouteInformation { | ||
56 | 56 | ||
57 | @override | 57 | @override |
58 | String toString() => ''' | 58 | String toString() => ''' |
59 | -======GetNavConfig=====\ncurrentTreeBranch: $currentTreeBranch\ncurrentPage: $currentPage\n======GetNavConfig====='''; | 59 | +======GetNavConfig=====\nlocation: $location\ncurrentTreeBranch: $currentTreeBranch\n======GetNavConfig====='''; |
60 | } | 60 | } |
@@ -311,7 +311,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -311,7 +311,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
311 | return route; | 311 | return route; |
312 | } | 312 | } |
313 | 313 | ||
314 | - Future<T> toNamed<T>( | 314 | + Future<void> toNamed( |
315 | String page, { | 315 | String page, { |
316 | dynamic arguments, | 316 | dynamic arguments, |
317 | Map<String, String>? parameters, | 317 | Map<String, String>? parameters, |
@@ -324,10 +324,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -324,10 +324,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
324 | final decoder = Get.routeTree.matchRoute(page, arguments: arguments); | 324 | final decoder = Get.routeTree.matchRoute(page, arguments: arguments); |
325 | decoder.replaceArguments(arguments); | 325 | decoder.replaceArguments(arguments); |
326 | 326 | ||
327 | - final completer = Completer<T>(); | ||
328 | - | ||
329 | if (decoder.route != null) { | 327 | if (decoder.route != null) { |
330 | - _allCompleters[decoder.route!] = completer; | ||
331 | await pushHistory( | 328 | await pushHistory( |
332 | GetNavConfig( | 329 | GetNavConfig( |
333 | currentTreeBranch: decoder.treeBranch, | 330 | currentTreeBranch: decoder.treeBranch, |
@@ -335,8 +332,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -335,8 +332,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
335 | state: null, //TODO: persist state? | 332 | state: null, //TODO: persist state? |
336 | ), | 333 | ), |
337 | ); | 334 | ); |
338 | - | ||
339 | - return completer.future; | ||
340 | } else { | 335 | } else { |
341 | ///TODO: IMPLEMENT ROUTE NOT FOUND | 336 | ///TODO: IMPLEMENT ROUTE NOT FOUND |
342 | 337 | ||
@@ -344,7 +339,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -344,7 +339,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
344 | } | 339 | } |
345 | } | 340 | } |
346 | 341 | ||
347 | - Future<T?>? offAndToNamed<T>( | 342 | + Future<void>? offAndToNamed( |
348 | String page, { | 343 | String page, { |
349 | dynamic arguments, | 344 | dynamic arguments, |
350 | int? id, | 345 | int? id, |
@@ -361,13 +356,13 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -361,13 +356,13 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
361 | return toNamed(page, arguments: arguments, parameters: parameters); | 356 | return toNamed(page, arguments: arguments, parameters: parameters); |
362 | } | 357 | } |
363 | 358 | ||
364 | - Future<T> offNamed<T>( | 359 | + Future<void> offNamed( |
365 | String page, { | 360 | String page, { |
366 | dynamic arguments, | 361 | dynamic arguments, |
367 | Map<String, String>? parameters, | 362 | Map<String, String>? parameters, |
368 | }) async { | 363 | }) async { |
369 | history.removeLast(); | 364 | history.removeLast(); |
370 | - return toNamed<T>(page, arguments: arguments, parameters: parameters); | 365 | + return toNamed(page, arguments: arguments, parameters: parameters); |
371 | } | 366 | } |
372 | 367 | ||
373 | /// Removes routes according to [PopMode] | 368 | /// Removes routes according to [PopMode] |
@@ -375,7 +370,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -375,7 +370,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
375 | /// DOES NOT remove the [fullRoute] | 370 | /// DOES NOT remove the [fullRoute] |
376 | Future<void> backUntil( | 371 | Future<void> backUntil( |
377 | String fullRoute, { | 372 | String fullRoute, { |
378 | - PopMode popMode = PopMode.Page, | 373 | + PopMode popMode = PopMode.History, |
379 | }) async { | 374 | }) async { |
380 | // remove history or page entries until you meet route | 375 | // remove history or page entries until you meet route |
381 | var iterator = currentConfiguration; | 376 | var iterator = currentConfiguration; |
@@ -406,7 +401,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -406,7 +401,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
406 | @override | 401 | @override |
407 | Future<bool> popRoute({ | 402 | Future<bool> popRoute({ |
408 | Object? result, | 403 | Object? result, |
409 | - PopMode popMode = PopMode.Page, | 404 | + PopMode popMode = PopMode.History, |
410 | }) async { | 405 | }) async { |
411 | //Returning false will cause the entire app to be popped. | 406 | //Returning false will cause the entire app to be popped. |
412 | final wasPopup = await handlePopupRoutes(result: result); | 407 | final wasPopup = await handlePopupRoutes(result: result); |
@@ -420,8 +415,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -420,8 +415,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
420 | return false; | 415 | return false; |
421 | } | 416 | } |
422 | 417 | ||
423 | - final _allCompleters = <GetPage, Completer>{}; | ||
424 | - | ||
425 | bool _onPopVisualRoute(Route<dynamic> route, dynamic result) { | 418 | bool _onPopVisualRoute(Route<dynamic> route, dynamic result) { |
426 | final didPop = route.didPop(result); | 419 | final didPop = route.didPop(result); |
427 | if (!didPop) { | 420 | if (!didPop) { |
@@ -436,9 +429,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -436,9 +429,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
436 | if (config != null) { | 429 | if (config != null) { |
437 | _removeHistoryEntry(config); | 430 | _removeHistoryEntry(config); |
438 | } | 431 | } |
439 | - if (_allCompleters.containsKey(settings)) { | ||
440 | - _allCompleters[settings]?.complete(route.popped); | ||
441 | - } | ||
442 | } | 432 | } |
443 | refresh(); | 433 | refresh(); |
444 | 434 | ||
@@ -467,7 +457,7 @@ class GetNavigator extends Navigator { | @@ -467,7 +457,7 @@ class GetNavigator extends Navigator { | ||
467 | } | 457 | } |
468 | return true; | 458 | return true; |
469 | }, | 459 | }, |
470 | - onGenerateRoute: (RouteSettings settings) { | 460 | + onGenerateRoute: (settings) { |
471 | final selectedPageList = | 461 | final selectedPageList = |
472 | pages.where((element) => element.name == settings.name); | 462 | pages.where((element) => element.name == settings.name); |
473 | if (selectedPageList.isNotEmpty) { | 463 | if (selectedPageList.isNotEmpty) { |
-
Please register or login to post a comment