创建一个颤动的 GetX 持久的 BottomNaviagtionBar 并努力导航到维护底部栏的选项卡视图内的内部页面......
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_persistent_bottombar/app/routes/app_pages.dart';
import '../controllers/tab1_controller.dart';
class Tab1View extends GetView<Tab1Controller> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tab1View'),
centerTitle: true,
),
body: Center(
child: Column(
children: [
Text(
'Tab1View is working',
style: TextStyle(fontSize: 20),
),
ElevatedButton(
onPressed: () => Get.toNamed(Routes.INTERNAL1),
child: Text("internal 1"),
),
ElevatedButton(
onPressed: () => Get.toNamed(Routes.INTERNAL2, id: 0),
child: Text("internal 2"),
),
],
),
),
);
}
}
请注意,在 Get.toNamed() 上传递 'id' 参数时,internal1 最重要的是打开,internal2 会返回错误:
======== Exception caught by gesture ===============================================================
The following message was thrown while handling a gesture:
Route id (0) not found
When the exception was thrown, this was the stack:
#0 GetNavigation.global (package:get/get_navigation/src/extension_navigation.dart:1088:9)
#1 GetNavigation.toNamed (package:get/get_navigation/src/extension_navigation.dart:592:12)
#2 Tab1View.build.<anonymous closure> (package:getx_persistent_bottombar/app/modules/tab1/views/tab1_view.dart:27:36)
#3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:608:11)
#6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#7 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
#8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:563:9)
#9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:94:12)
#10 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:139:9)
#11 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:539:8)
#12 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:137:18)
#13 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:123:7)
#14 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:439:19)
#15 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
#16 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:322:11)
#17 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
#18 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
#19 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
#20 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
#24 _invoke1 (dart:ui/hooks.dart:169:10)
#25 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:293:7)
#26 _dispatchPointerDataPacket (dart:ui/hooks.dart:88:31)
(elided 3 frames from dart:async)
Handler: "onTap"
Recognizer: TapGestureRecognizer#46f01
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(182.2, 186.4)
finalLocalPosition: Offset(47.7, 23.9)
button: 1
sent tap down
====================================================================================================
完整的代码在
https://github.com/tva77/getx_persistent_bottombar
那么,如何使用 GetX 处理内部页面并维护底栏?