首页 文章

滚动行为中的文本和ListView颤动

提问于
浏览
0

我正在尝试扑动,我遇到了一个问题 . 我有一个文本,我的结果来自一个服务和一个ListView(构建器)显示这些结果(作为一个卡,以便有一个像布局一样漂亮的盒子) .

我的目标是,当用户滚动列表时,页面(文本)的结果部分将消失 .

我按照https://docs.flutter.io/flutter/widgets/SingleChildScrollView-class.html中的描述尝试了SingleChildScrollView,但它没有用 .

截图:enter image description here

任何见解都会非常有用 . 提前致谢 .

更新(小部件树)

Widget build(BuildContext context) {
return new Scaffold(
  body: new Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: <Widget>[
      new Container(
        padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
        child: new RichText(
          text: new TextSpan(
            children: <TextSpan>[
              new TextSpan(
                text: this.model == null
                    ? "0"
                    : this.model.length.toString(),
                style: new TextStyle(
                  fontSize: 14.0,
                  fontWeight: FontWeight.bold,
                  color: Colors.black87,
                ),
              ),
              new TextSpan(
                text: ' Results',
                style: new TextStyle(
                  fontSize: 14.0,
                  color: Colors.black87,
                ),
              ),
            ],
          ),
        ),
      ),
      new Expanded(
        child: new RefreshIndicator(
          key: refreshKey,
          child: new ListView.builder(
            itemCount: this.model?.length,
            itemBuilder: (BuildContext context, int index) {
              final Model model= this.model[index];
              return new Card(child: new Text(model.id.toString()),);
            },
          ),
          onRefresh: _handleRefresh,
        ),
      ),
    ],
  ),
);

}

1 回答

  • 1

    你可以尝试下面给出的结构,看起来不那么hacky:p

    Widget build(BuildContext context) {
        List<String> results = List.generate(40, (int i) => "Result $i");
        return Scaffold(
            appBar: AppBar(title: Text("Test Screen")),
            body: SingleChildScrollView(
             child: Container(
               width: double.infinity,
              child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
                Text("RESULTS", style: TextStyle(fontWeight: FontWeight.bold)),
                Column(
                  mainAxisSize: MainAxisSize.min,
                  children: results.map((String s) => Container(
                    width: double.maxFinite,
                    child: Card(child:Text(s)))).toList(),
                ),
              ]),
            )
          )
        );
      }
    

相关问题