【问题标题】:flutter How to edit the index in PageView in another widget and main index change automatic?颤振如何在另一个小部件中编辑PageView中的索引并且主索引自动更改?
【发布时间】:2021-08-10 20:19:59
【问题描述】:

如何在另一个小部件中更改 PageView 索引,同时将其应用到主页上?

PageView.builder(
        reverse: true,
        itemBuilder: (BuildContext ctx, int position) {
          return PageViewWidget(
            displayZekr: _displayZekr,
            position: position,
          );
        },
        controller: s,
        itemCount: _displayZekr.length,
      ),

【问题讨论】:

  • 您需要更好地解释您的问题。您可以在开头和结尾使用三个严重标记格式化代码:```dart ```

标签: flutter flutter-layout flutter-dependencies


【解决方案1】:

你应该做 5 个步骤:

  1. 将您的小部件设为Stateful Widget,这样您就可以更改它的状态(在您的示例页面索引中)
  2. 为页面索引创建一个全局int:int pageIdx = 1;
  3. 创建一个改变页面索引的函数:
void changePageIndex(){
   setState((){pageIndex++;});
}
  1. 随时随地调用此函数
  2. 将全局索引用作活动页面!

【讨论】:

    猜你喜欢
    • 2023-02-04
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 2020-02-15
    • 2018-12-13
    • 1970-01-01
    • 2021-01-01
    • 2020-08-31
    相关资源
    最近更新 更多