簡體   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