当前位置:网站首页>flutter 制作嵌套列表

flutter 制作嵌套列表

2022-08-10 02:37:00 氤氲息

总列,滑动,嵌套列,列表

  @override
  Widget build(BuildContext context) {
    
    return Column(//首先是一列
      children: [
      //如果想让一部分不滑动,可以在这里写
    Expanded(//填充
        child: SingleChildScrollView(//可滑动列表
      child: Column(//可滑动列表里面放一个列
        children: [
        //这里可继续添加container,因在滑动列表里面,是可以滑动的
          Container(
            child: MediaQuery.removePadding(//最后就是列表了
                removeTop: true,
                context: context,
                child: ListView.builder(
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemCount: 10,
                    itemBuilder: (BuildContext context, int index) {
    
                      return Container(
                        child: Text(""),
                      );
                    })),
          )
        ],
      ),
    ))
      ],
    );
  }

添加缺省页

  @override
  Widget build(BuildContext context) {
    
    return MaterialApp(
      color: Colors.transparent,
      home://缺省页
          richRankList == null ||
                  richRankList!.rankList == null ||
                  richRankList!.rankList!.isEmpty
              ? Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      alignment: Alignment.center,
                      child: Container(
                          margin: const EdgeInsets.only(bottom: 120),
                          child: Column(children: [
                            ContentText(S.current.bottle_no_data, 14.0,
                                CommonColors.getTextWeakColor()),
                            TopPadding(30),
                          ])),
                    )
                  ],
                )
              : Scaffold(
                  backgroundColor: Colors.transparent,
                  body: Column(
                    children: [
                      Expanded(
                        child: SingleChildScrollView(
                          child: Column(
                            children: [
                              if (getSex(0) != 0 ||
                                  getBirthday(0) != -1 ||
                                  getRank(0) != -1)
                                topThree(),
                              Container(
                                color: Colors.transparent,
                                padding: const EdgeInsets.only(bottom: 20),
                                child: MediaQuery.removePadding(
                                    removeTop: true,
                                    context: context,
                                    child: richRankList == null ||
                                            richRankList!.rankList == null ||
                                            richRankList!.rankList!.isEmpty
                                        ? Container()
                                        : ListView.builder(
                                            shrinkWrap: true,
                                            physics:
                                                const NeverScrollableScrollPhysics(),
                                            itemCount:
                                                richRankList!.rankList!.length,
                                            itemBuilder: (BuildContext context,
                                                int index) {
    
                                              RichRankList rankList =
                                                  richRankList!
                                                      .rankList![index];
                                              return GestureDetector(
                                                child: Offstage(
                                                  offstage: index == 1 ||
                                                      index == 1 ||
                                                      index == 2,
                                                  child: Container(
                                                      width: width,
                                                      margin:
                                                          const EdgeInsets.only(
                                                              top: 16,
                                                              left: 16,
                                                              right: 16),
                                                      padding:
                                                          const EdgeInsets.only(
                                                              left: 16,
                                                              top: 8,
                                                              bottom: 8,
                                                              right: 16),
                                                      decoration: BoxDecoration(
                                                        color: const Color(
                                                            0xFFFBFFF2),
                                                        borderRadius:
                                                            BorderRadius
                                                                .circular(12),
                                                        boxShadow: const [
                                                          BoxShadow(
                                                            color: Color(
                                                                0xFFDBEBB6),
                                                            blurRadius: 1,
                                                          ),
                                                        ],
                                                      ),
                                                      child: Row(
                                                        children: [
                                                          Container(
                                                            child: Text(
                                                              "${rankList.rank ?? 0}",
                                                              style: const TextStyle(
                                                                  color: Colors
                                                                      .black,
                                                                  fontSize: 16),
                                                            ),
                                                          ),
                                                          Row(
                                                            children: [
                                                              Container(
                                                                  margin: const EdgeInsets
                                                                          .only(
                                                                      top: 10,
                                                                      left: 32),
                                                                  height: 58,
                                                                  width: 58,
                                                                  child:
                                                                      ClipRRect(
                                                                    borderRadius:
                                                                        BorderRadius.circular(
                                                                            50),
                                                                    child: ImageUtile
                                                                        .imageWidget(
                                                                      rankList.avatar ??
                                                                          Global
                                                                              .defUserImag,
                                                                    ),
                                                                  )),
                                                              Container(
                                                                margin:
                                                                    const EdgeInsets
                                                                            .only(
                                                                        top: 10,
                                                                        left:
                                                                            8),
                                                                child: Column(
                                                                  crossAxisAlignment:
                                                                      CrossAxisAlignment
                                                                          .start,
                                                                  children: [
                                                                    LimitedBox(
                                                                      maxWidth:
                                                                          130,
                                                                      child:
                                                                          Text(
                                                                        rankList.nickname ??
                                                                            "",
                                                                        maxLines:
                                                                            1,
                                                                        overflow:
                                                                            TextOverflow.ellipsis,
                                                                        style:
                                                                            const TextStyle(
                                                                          fontSize:
                                                                              16,
                                                                          color:
                                                                              Color(0xFF040404),
                                                                          decoration:
                                                                              TextDecoration.none,
                                                                        ),
                                                                      ),
                                                                    ),
                                                                    Container(
                                                                      alignment:
                                                                          Alignment
                                                                              .centerLeft,
                                                                      margin: const EdgeInsets
                                                                              .only(
                                                                          top:
                                                                              7.0),
                                                                      child:
                                                                          Row(
                                                                        children: [
                                                                          Container(
                                                                            child:
                                                                                SizedBox(
                                                                              width: 20,
                                                                              height: 20,
                                                                              child: ImageUtile.imageWidget("assets/images/[email protected]"),
                                                                            ),
                                                                          ),
                                                                          Container(
                                                                              alignment: Alignment.center,
                                                                              margin: const EdgeInsets.only(right: 6),
                                                                              padding: const EdgeInsets.fromLTRB(3, 2, 5, 2),
                                                                              child: Row(mainAxisSize: MainAxisSize.min, children: [
                                                                                Image(image: AssetImage(rankList.sex == 1 ? 'assets/images/icon_gender_male.png' : 'assets/images/icon_gender_female.png'), gaplessPlayback: true, width: 11, height: 11),
                                                                                Padding(
                                                                                  padding: const EdgeInsets.only(top: 1),
                                                                                  child: Text(
                                                                                    // '${UserInfoUtil().getAge(widget.birthday!)}',
                                                                                    '${rankList.age ?? 0}',
                                                                                    style: const TextStyle(
                                                                                      fontSize: 9.0,
                                                                                      color: Colors.white,
                                                                                    ),
                                                                                  ),
                                                                                )
                                                                              ]),
                                                                              decoration: BoxDecorationUtil().setFillBoxDecoration(rankList.sex == 1 ? CommonColors.getColor7E8FF7 : CommonColors.getColorF77EBE, 10.0)),
                                                                          SizedBox(
                                                                            width:
                                                                                20,
                                                                            height:
                                                                                20,
                                                                            child:
                                                                                ImageUtile.imageWidget("assets/images/[email protected]"),
                                                                          ),
                                                                        ],
                                                                      ),
                                                                    ),
                                                                  ],
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                          const Spacer(),
                                                          Container(
                                                            alignment: Alignment
                                                                .center,
                                                            margin:
                                                                const EdgeInsets
                                                                        .only(
                                                                    top: 7.0),
                                                            child: Row(
                                                              mainAxisAlignment:
                                                                  MainAxisAlignment
                                                                      .center,
                                                              children: [
                                                                SizedBox(
                                                                  width: 20,
                                                                  height: 20,
                                                                  child: ImageUtile
                                                                      .imageWidget(
                                                                          "assets/images/[email protected]"),
                                                                ),
                                                                Container(
                                                                  alignment:
                                                                      Alignment
                                                                          .center,
                                                                  margin: const EdgeInsets
                                                                          .only(
                                                                      right: 6),
                                                                  padding:
                                                                      const EdgeInsets
                                                                              .fromLTRB(
                                                                          3,
                                                                          2,
                                                                          5,
                                                                          2),
                                                                  child: Text(
                                                                    "${rankList.richValue ?? 0}",
                                                                    style: const TextStyle(
                                                                        fontSize:
                                                                            12),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          ),
                                                        ],
                                                      )),
                                                ),
                                              );
                                            })),
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  )),
    );
  }
原网站

版权声明
本文为[氤氲息]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44911775/article/details/126244322