jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.39k stars 1.63k forks source link

GetRouterOutlet not effect #3242

Open ANC1024GO opened 3 weeks ago

ANC1024GO commented 3 weeks ago

log not log, not eorro

example:

//main.dart
GetMaterialApp(
      getPages: AppRoute().routes,
      initialRoute:AppRouteName.home,
)
//AppRoute
class AppRoute {
  final List<GetPage> routes = [
    GetPage(
      name:  AppRouteName.home,
      page: () => HomePage(title: 'Hello',),

    ),
    GetPage(
      name:  AppRouteName.listPage,
      page: () => Container(child: Center(child: Text('hello list'),),color: Colors.orange.withOpacity(0.3),),
      children:[
        GetPage(
          name:  AppRouteName.widget,
          page: ()=>WidgetPage(),
        ),
        GetPage(
          name:  AppRouteName.test,
          page: ()=>TestPage(),
        ),
      ]
    ),
    GetPage(
      name:  AppRouteName.login,
      page: () => LoginPage(),

    ),
  ];

}
class AppRouteName {
  static const String home = '/';
  static const String listPage = '/list';
  static const String widget = '/list/widget';
  static const String test = '/list/test';

  static const String login = '/login';

}
// home page
class HomePage extends StatefulWidget {
  const HomePage({super.key});
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        title: Text('home '),
      ),
      body: Row(
        children: [
          Container(
              width: 200,
              child: ListView(children: [
                ListTile(
                  title: Text('widget'),
                  onTap: () {
                    Get.toNamed(AppRouteName.widget,id:1);
                  },
                ),
                ListTile(
                  title: Text('test'),
                  onTap: () {
                    Get.toNamed(AppRouteName.test,id: 1);
                  },
                ),
              ])),
            Expanded(
              flex: 1,
              child: GetRouterOutlet(
                  anchorRoute:AppRouteName.listPage,
                  initialRoute:AppRouteName.widget,
                  key: Get.nestedKey(1),
                  filterPages: (afterAnchor) {
                    return afterAnchor.take(1);
                  },
                ),
            )
        ],
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
  }
}

Screenshots

Flutter Version: Flutter 3.22.3 • channel stable

Getx Version: (get: ^4.6.6)

ANC1024GO commented 3 weeks ago

There is no response when clicking the button,https://i.makeagif.com/media/10-21-2024/sC-rqK.gif