繁体   English   中英

Flutter Onpressed 利用列表中的完整索引

[英]Flutter Onpressed Utilize Full Index from List

我创建了一个包含所有导航路径的列表,我想单击一个按钮并通过它们单击 go 1 单击转到 0 索引,然后再次单击转到 1 索引。
这是在 index = pagesList[index]下面显示红线的那个我该如何实现? 如果我将其更改为显示像 pagesList[3] 这样的硬编码索引,它将 go 指向数组中的该索引值,但我希望它在每次单击后通过列表显示为 go。

大批:

List pagesList = [
  for (int index = 0; index < pagesList.length; index++)
    {
      AliflaammeemPg2(),
      AliflaammeemPg3(),
      AliflaammeemPg4(),
      AliflaammeemPg5(),
      AliflaammeemPg6(),
      AliflaammeemPg7(),
      AliflaammeemPg8(),
      AliflaammeemPg9(),
}
];



then on another page I have 
class _AliflaammeemPg2State extends State<AliflaammeemPg2> {
  @override
  Widget build(BuildContext context) {
    return ReusableLarge(
      forward: () {
        // String page = "{\"title\":\"Page1\",\"target\":\"p1\"}";
        // page = json.decode(page);
        // if(page['target'] == "p1"){

        // }
        //

        // ignore: unnecessary_statements
        Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => **pagesList[index]**

                // pagesList();

                // Navigator.push(
                //   context,
                //   MaterialPageRoute(builder: (context) => AliflaammeemPg3()),
                ));
      },

另外:这是 widget.forward 被按下的地方:

         child: new Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                // crossAxisAlignment: CrossAxisAlignment.center
                children: <Widget>[
                  GFButton(
                    icon: Icon(
                      styling.bottomNavBarForwardArrowIcon,
                      color: Colors.cyan,
                      size: 30,

                      // tooltip: "Forward",
                    ),
                    color: Colors.cyan,

                    textStyle: TextStyle(
                        fontSize: 20, fontWeight: FontWeight.bold),
                    text: "مستقيم",
                    // elevation: 23,
                    // iconSize: 30,
                    splashColor: Colors.lightBlue,
                    onPressed: widget.forward,

您可以将Navigate 与命名路线一起使用。

// Navigate to the second screen using a named route.
  Navigator.pushNamed(context, '/$index');

MaterialApp(
  title: 'Named Routes Demo',
  // Start the app with the "/" named route. In this case, the app starts
  // on the FirstScreen widget.
  initialRoute: '/',
  routes: {
    // When navigating to the "/" route, build the FirstScreen widget.
    '/': (context) => const FirstScreen(),
    // When navigating to the "/second" route, build the SecondScreen widget.
    '/1': (context) => const AliflaammeemPg1(),
    '/2': (context) => const AliflaammeemPg2(),
        //and so on...

  },
)




暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM