why can't I get the arguments from getx router in flutter?

Viewed 57

In page 1, I set the forward route transmission parameter to 123, which can still be obtained in the route callback function, but it becomes null when I get it in page 2. Can anyone help me analyze the problem? Below is my code and log.

[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [版本 10.0.16299.1625], locale zh-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.10.0)
[!] Android Studio (version 4.0)
    X Unable to determine bundled Java version.
[√] Android Studio (version 2021.2)
[√] Connected device (2 available)
[√] HTTP Host Availability

! Doctor found issues in 2 categories.

Page Navigator `

Widget build(BuildContext context) {
        Get.put(ProjectController());
        return Navigator(
            key: Get.nestedKey(1), // create a key by index
            initialRoute: '/',
            onGenerateRoute: (settings) {
              final name = settings.name;
              log('settings--- >${settings.toString()}');
              switch (name) {
                case '/':
                  return GetPageRoute(
                    settings: settings,
                    page: () => const ProjectList(),
                  );
                case '/detail':
                  return GetPageRoute(
                    settings: settings,
                    page: () => const ProjectDetail(),
                  );
                default:
              return GetPageRoute(
                settings: settings,
                page: () => const ProjectList(),
              );
          }
        });
}

PageOne

Widget build(BuildContext context) {
    return SizedBox(
      height: 40,
      child: Row(
        children: [
          TextButton.icon(
            onPressed: add,
            label: const Text('add'),
            icon: const Icon(
              Icons.add,
              size: 16,
            ),
          ),
          TextButton.icon(
              icon: const Icon(Icons.sync, size: 16),
              onPressed: () => Get.toNamed('/detail', id: 1, arguments: '123'),
              label: const Text('detail')),
        ],
      ),
    );

PageTwo

Widget build(BuildContext context) {
    Get.put(DetailController());
    log('widget arguments---------->${Get.arguments.toString()}');
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        foregroundColor: Theme.of(context).primaryColor,
        elevation: 1,
      ),
      body: Container(
          padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
          child: Row(
            children: const [
              Expanded(
                child: IndexCategory(),
              ),
              VerticalDivider(),
              Expanded(
                flex: 3,
                child: IndexContent(),
              ),
            ],
          )),
    );
  }

` here is the log

  1. [log] settings--- >RouteSettings("/detail", 123)
  2. [GETX] Instance "DetailController" has been created
  3. [log] controller arguments---------->null
  4. [GETX] Instance "DetailController" has been initialized
  5. [log] widget arguments---------->null
0 Answers
Related