Home > Net >  GetMaterial.router not working on getx 4.6.5
GetMaterial.router not working on getx 4.6.5

Time:07-29

I'm developing flutter web and try to run demo code getx on get 4.6.5 but when use Get.toNamed() i got error "Navigator.onGenerateRoute was null, but the route named "/second/id=3" was referenced." Then i try get.to() but the url not change and reload page i can't back to page1 Here is my code:

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp.router(
      getPages: [
        GetPage(
            participatesInRootNavigator: true,
            name: '/first',
            page: () => First()),
        GetPage(
          name: '/second/:id',
          page: () => Second(),
        ),
        GetPage(
          name: '/third',
          page: () => Third(),
        ),
      ],
      debugShowCheckedModeBanner: false,
    );
  }
}

class First extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('page one'),
        leading: IconButton(
          icon: Icon(Icons.more),
          onPressed: () {
            Get.changeTheme(
                context.isDarkMode ? ThemeData.light() : ThemeData.dark());
          },
        ),
      ),
      body: Center(
        child: Container(
          height: 300,
          width: 300,
          child: ElevatedButton(
            onPressed: () {
              Get.toNamed('/second/id=3');
            },
            child: Text('next screen'),
          ),
        ),
      ),
    );
  }
}

class Second extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('page two ${Get.parameters["id"]}'),
      ),
      body: Center(
        child: Container(
          height: 300,
          width: 300,
          child: ElevatedButton(
            onPressed: () {
              Get.toNamed('/third');
            },
            child: Text('next screen'),
          ),
        ),
      ),
    );
  }
}

I'm newbie on flutter web hope to get help from everyone

CodePudding user response:

How about doing it like this:

child: ElevatedButton(
            onPressed: () {
              Get.toNamed('/second/3');
            },
            child: Text('next screen'),
          ),

CodePudding user response:

Thank everyone, i resolve by use Get.rootDelegate.toNamed()

  • Related