简体   繁体   English

如何在单个 flutter 屏幕中加载两个列表视图?

[英]How I load two List views in single flutter screen?

I developed an android application using flutter .我使用flutter开发了一个 android 应用程序。 The application has a post screen.该应用程序有一个发布屏幕。 In this screen, the user can see posts.在此屏幕中,用户可以查看帖子。 And when the user touches some post he can able to see the full post.当用户触摸某个帖子时,他可以看到完整的帖子。 But I want to add a comment view section to the post view screen .我想在帖子视图屏幕上添加一个评论视图部分 The user must able to add comments and see other's comments on the related post.用户必须能够添加评论并查看其他人对相关帖子的评论。 posts are retrieving on node.js API.正在检索 node.js API 上的帖子。

my current post full view screen code is:我当前的帖子全视图屏幕代码是:

   class FullPostView extends StatefulWidget {
  List list;
  int index;
  FullPostView({this.index, this.list});

  @override
  _FullPostViewState createState() => _FullPostViewState();
}

class _FullPostViewState extends State<FullPostView> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: new AppBar(
         iconTheme: IconThemeData(
            color: Colors.black, // back button color
          ),
         elevation: 0,
        backgroundColor: Colors.white,
        title: new Center(child:  new Text("${widget.list[widget.index]['title']}", style: TextStyle(color: Colors.black,fontFamily: 'Montserrat', fontWeight: FontWeight.bold ),)),
      ),
      body: new Container(
         height: MediaQuery.of(context).size.height * 0.8, 
        child: new SingleChildScrollView(

        padding: const EdgeInsets.all(20.0),
        child: new Card(
          child: new Center(
            child: new Column(
              children: <Widget>[
                new Padding(padding: const EdgeInsets.only(top: 30.0, left: 2),),
               new Image.asset('assets/images/ex.jpg',height: 210,),
               Container(
                  margin: new EdgeInsetsDirectional.only(start: 1.0, end: 210.0, top: 10),
                  child: new Text(" Post By: ${widget.list[widget.index]['authortype']}", style: new TextStyle(fontFamily: 'Montserrat',fontSize: 11.0, color: Colors.redAccent[200]),),
                ),
                new Text(" \n\n ${widget.list[widget.index]['subject']}", style: new TextStyle(fontFamily: 'Montserrat',fontWeight: FontWeight.bold, fontSize: 18.0),),
                new Padding(padding: const EdgeInsets.only(top: 13.0),),
                Container(
                  margin: new EdgeInsetsDirectional.only(start: 1.0, end: 1.0, top: 10),
                  child: new Text(" ${widget.list[widget.index]['discription']}", style: new TextStyle(fontFamily: 'Montserrat',fontSize: 13.0, color: Colors.brown),),
                ),
                SizedBox(
                  height:10,
                )
              ],
            ),
          ),
        ),
      ),
      ),
    );
  }
}

How can I do that?我怎样才能做到这一点?

I am giving you general idea, you can use Expanded inside Column and put your list in it.我给你一个大致的想法,你可以在Column内使用Expanded并将你的列表放入其中。 For fixed size, you can use SizedBox instead of Expanded .对于固定大小,您可以使用SizedBox而不是Expanded

return Column(
  children: [
    Expanded(
      flex: 2,
      child: FirstList(),
    ),
    Expanded(
      flex: 3,
      child: SecondList(),
    )
  ],
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM