簡體   English   中英

如何在單個 flutter 屏幕中加載兩個列表視圖?

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

我使用flutter開發了一個 android 應用程序。 該應用程序有一個發布屏幕。 在此屏幕中,用戶可以查看帖子。 當用戶觸摸某個帖子時,他可以看到完整的帖子。 我想在帖子視圖屏幕上添加一個評論視圖部分 用戶必須能夠添加評論並查看其他人對相關帖子的評論。 正在檢索 node.js API 上的帖子。

我當前的帖子全視圖屏幕代碼是:

   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,
                )
              ],
            ),
          ),
        ),
      ),
      ),
    );
  }
}

我怎樣才能做到這一點?

我給你一個大致的想法,你可以在Column內使用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