【问题标题】:Flutter : How to use router on dialogFlutter:如何在对话框中使用路由器
【发布时间】:2021-12-31 10:59:48
【问题描述】:

首先我有一个按钮来打开一个对话框

当点击重复时,我想用户导航器在对话框中推送一个页面,如下所示

我怎么不能用颤振做到这一点?感谢您的帮助!

【问题讨论】:

  • 任何机构有解决方案?

标签: flutter dialog flutter-getx


【解决方案1】:

您可以使用 PageView.builderPageController 来实现您的预​​期结果。我分享了一个参考example,您可以根据需要对其进行修改。

class WelcomeScreen extends StatefulWidget {
  @override
  _WelcomeScreenState createState() => _WelcomeScreenState();
}

class _WelcomeScreenState extends State<WelcomeScreen> {
  PageController _controller = PageController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Pagination Example"),
      ),
      body: Padding(
        padding: EdgeInsets.all(24.0),
        child: Center(
          child: PageView.builder(
              controller: _controller,
              itemCount: 2,
              itemBuilder: (context, index) => Scaffold(
                    appBar: AppBar(
                      title: Text("Page $index"),
                      leading: index == 1
                          ? IconButton(
                              onPressed: () {
                                _controller.previousPage(
                                    duration: Duration(milliseconds: 100),
                                    curve: Curves.ease);
                              },
                              icon: Icon(Icons.arrow_back),
                            )
                          : null,
                    ),
                    body: Column(
                      children: [
                        Text("Content of Page $index"),
                        Visibility(
                          visible: index == 1 ? false : true,
                          child: ElevatedButton(
                              onPressed: () {
                                _controller.nextPage(
                                    duration: Duration(milliseconds: 100),
                                    curve: Curves.ease);
                              },
                              child: Text("Next Page")),
                        )
                      ],
                    ),
                  )),
        ),
      ),
    );
  }
}

【讨论】:

  • 这个答案很好,感谢您的帮助
  • 很高兴为您提供帮助...:)
【解决方案2】:

您是否尝试过更改对话框的内容而不是使用路由器?就像使用当你点击重复更新对话框内容时改变的状态变量,然后当你点击保存时恢复它

【讨论】:

  • 我也想过。但是内容多了,就很难维护了。所以我认为对话中的路由器是最好的方法:D,感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
  • 2017-11-19
  • 2021-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多