Combine SingleChildScrollView and PageView in Flutter

隐身守侯 提交于 2019-12-02 11:33:13

I have tested this to work.

class SO extends StatefulWidget {
  @override
  _SOState createState() => _SOState();
}

class _SOState extends State<SO> {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(""),
      ),
      body: PageView(
        children: <Widget>[
          _sampleForm("Page 1"),
          _sampleForm("Page 2"),
        ],
      ),
    );
  }

  _sampleForm(String title) {
    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.all(32.0),
        child: Column(
          children: <Widget>[
            Form(
              child: Column(
                children: <Widget>[
                  ListTile(title: Text(title, textAlign: TextAlign.center)),
                  for (int i = 0; i < 10; i++) TextFormField(decoration: InputDecoration(hintText: "field ${i+1}"),),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Just some extra padding to show the content is what you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!