当TextView聚焦时,TabController中的ListView消失

时间:2018-08-14 05:19:07

标签: flutter

我发现,如果ListView位于Tab控制器内部,则当TextView处于焦点状态时,视图内的项目就会消失。这是错误吗?

@override
Widget build(BuildContext context) {
return new Scaffold(
  appBar: new AppBar(
    title: new Text(widget.title),
  ),
  body: new Column(
    children: <Widget>[
      new TextField(),
      new Expanded(
        child: DefaultTabController(
          length: 2,
          child: Scaffold(
            appBar: AppBar(
              title: TabBar(
                tabs: [
                  Tab(text: 'Info'),
                  Tab(text: 'News'),
                ],
              ),
            ),
            body: TabBarView(
              children: [
                ListView(
                  children: <Widget>[
                    ListTile(title: Text('row 1')),
                    ListTile(title: Text('row 2')),
                    ListTile(title: Text('row 3')),
                  ],
                ),
                Text("abc"),
              ],
            ),
          ),
        ),
      )
    ],
  ),
  floatingActionButton: new FloatingActionButton(
    onPressed: _incrementCounter,
    tooltip: 'Increment',
    child: new Icon(Icons.add),
  ), // This trailing comma makes auto-formatting nicer for build methods.
);
}

从下面的第一张图片可以看到,列表视图最初显示。但是,在单击图片2中的文本字段后,该列表消失了。

enter image description here enter image description here

2 个答案:

答案 0 :(得分:1)

如果您正在使用,请不要使用双脚手架

resizeToAvoidBottomPadding: false,

在您现有的脚手架中。

答案 1 :(得分:0)

不用两个脚手架就可以得到相同的东西,看看这个:

    @override
      Widget build(BuildContext context) {
        return new DefaultTabController(
            length: 2,
            child: Scaffold(
              appBar: new AppBar(
                title: new Text("title test"),
                bottom: PreferredSize(
                  child: Column(
                    children: <Widget>[
                      Container(
                        color: Colors.white,
                        child: TextField(),
                      ),
                      TabBar(
                        indicatorColor: Colors.white,
                        tabs: [
                          Tab(text: 'Info'),
                          Tab(text: 'News'),
                        ],
                      ),
                    ],
                  ),
                  preferredSize: Size.fromHeight(100.0),
                ),
              ),
              body: TabBarView(
                children: [
                  ListView(
                    children: <Widget>[
                      ListTile(title: Text('row 1')),
                      ListTile(title: Text('row 2')),
                      ListTile(title: Text('row 3')),
                    ],
                  ),
                  Text("abc"),
                ],
              ),
              floatingActionButton: new FloatingActionButton(
                onPressed: () => null,
                tooltip: 'Increment',
                child: new Icon(Icons.add),
              ), // This trailing comma makes auto-formatting nicer for build methods.
            ));
      }