getx
getx copied to clipboard
5.0新建项目,按照demo编写报:Multiple widgets used the same GlobalKey.
ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.
Describe the bug 新建项目,按照demo开发嵌套路由,报Multiple widgets used the same GlobalKey.错误 ======== Exception caught by widgets library ======================================================= The following assertion was thrown while finalizing the widget tree: Multiple widgets used the same GlobalKey.
The key [LabeledGlobalKey<NavigatorState>#0c9e9] was used by multiple widgets. The parents of those widgets were:
- GetRouterOutlet-[LabeledGlobalKey<NavigatorState>#0c9e9](dependencies: [_RouterScope], state: RouterOutletState<GetDelegate, RouteDecoder>#75caf)
- KeyedSubtree-[GlobalKey#9d817]
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack:
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw
packages/flutter/src/widgets/framework.dart 2959:13
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach packages/flutter/src/widgets/framework.dart 2903:19 dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach packages/flutter/src/widgets/framework.dart 2898:36 packages/flutter/src/widgets/framework.dart 2966:14 [_debugVerifyGlobalKeyReservation] packages/flutter/src/widgets/framework.dart 3026:11 packages/flutter/src/widgets/framework.dart 3107:16 finalizeTree packages/flutter/src/widgets/binding.dart 866:7 drawFrame packages/flutter/src/rendering/binding.dart 381:5 [_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1289:15 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1218:9 handleDrawFrame packages/flutter/src/scheduler/binding.dart 942:7 dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback ====================================================================================================
Reproduction code NOTE: THIS IS MANDATORY, IF YOUR ISSUE DOES NOT CONTAIN IT, IT WILL BE CLOSED PRELIMINARY)
example:
void main() async{
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetMaterialApp(
getPages: AppPages.routes,
initialRoute: AppPages.initial,
);
}
}
///rootPge:
class RootPage extends StatelessWidget {
const RootPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return RouterOutlet.builder(
delegate: Get.nestedKey(null),
builder: (BuildContext context){
final title = context.location;
return Scaffold(
appBar: AppBar(
title: Text(title),
),
// 添加homePage会报上面的错误
body: GetRouterOutlet(
initialRoute: AppRoutes.home,
//delegate: Get.nestedKey(null),
//anchorRoute: '/',
)
);
}
);
}
}
///HomePage:
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetRouterOutlet.builder(
routerDelegate: Get.nestedKey(AppRoutes.home),
builder: (context) {
return const Scaffold(
body: Text("home"),
);
}
);
}
}
///appPages:
class AppPages{
AppPages._();
static const initial= AppRoutes.home;
static final routes = [
GetPage(
name: '/',
page: () => const RootPage(),
participatesInRootNavigator: true,
preventDuplicates: true,
children: [
GetPage(
name: AppRoutes.login,
page: () => const LoginPage(),
),
GetPage(
preventDuplicates: true,
name: AppRoutes.home,
page: () => const HomePage(),
// middlewares: [
// AuthMiddleware(),
// ]
),
]
)
];
}
///appRoutes
abstract class AppRoutes{
static const String home = _Paths.home;
static const String login = _Paths.login;
}
abstract class _Paths{
static const String home = '/home';
static const String login = '/login';
}
To Reproduce Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Flutter Version: Flutter 3.7.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 12cb4eb7a0 (2 days ago) • 2023-03-01 10:29:26 -0800 Engine • revision ada363ee93 Tools • Dart 2.19.3 • DevTools 2.20.1
Getx Version: get: 5.0.0-release-candidate-3
Describe on which device you found the bug: ex: Moto z2 - Android.
Minimal reproduce code Provide a minimum reproduction code for the problem
I'm also facing this problem, Very long continues logs with repeated line of "The key [LabeledGlobalKey#0c9e9] was used by multiple widgets. The parents of those widgets were:....."
same bug
期待解决😚
same bug
same
same
same