flutter小记(5)

搜索历史记录的实现
用constrainedbox限制最小高度实现,而没有最大高度来实现

ConstrainedBox(
      constraints: BoxConstraints(
      minWidth: double.infinity, //宽度尽可能大
      minHeight: height[i],
      ),
      child: Container(
         padding: EdgeInsets.only(bottom: 30),
         child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                  Row(
                  children: [
                      Container(
                        height: height[i],
                        margin: EdgeInsets.only(left: 20),
                        child: Text(                        
                        AppStrings.Search_cookies[i],
                        style: TextStyle(fontWeight: FontWeight.bold,
                        fontSize: 20.0,
                        fontFamily: 'PH',
                        color: Colors.black,
                         ),
                         ),
                         decoration: BoxDecoration(
                         gradient: LinearGradient( //渐变位置
                         begin: Alignment.topCenter, //右上
                         end: Alignment.bottomCenter,//左下
                         stops: [0, 0.59, 0.6, 1.0],//[渐变起始点, 渐变结束点]
                         //渐变颜色[始点颜色, 结束颜色]
                         colors: [Colors.transparent,
                              Colors.transparent,      
                              AppColors.COLOR_FCD864,         
                              AppColors.COLOR_FCD864 ],
                              )),
                              ),
                              Container(
                               width: 45,
                               height: iconheight[i],
                               margin: EdgeInsets.only(left: 240),
                               child: IconButton(
                               icon: Image.asset(
                                   'images/delete.png',
                                     color: cont[i]),
                               onPressed: () {setState(() 
                               {
                                  text[0].clear();
                                   height[0] =ScreenUtil().setHeight(0);
                                   num[0] = 0;
                                   textlen = 0;             
                                   cont[0]=Colors.transparent;
                                   iconheight[0]=0;});
                                    },
                                     )),
                                      ],
                                      ),
                                Container(
                                 margin: EdgeInsets.only(left: 40),
                                  child: Wrap(
                                  spacing: 25,
                                  alignment: WrapAlignment.start,
                                  runSpacing: 10.0,
                                   children:
                                     List<Widget>.generate(num[i], (j) {
                                                  return Text(
                                                    text[i][j],
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        fontFamily: 'PH',
                                                        fontWeight: FontWeight.bold),
                                                  );
                                                }),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ));

由于网络请求的延迟性,所以在改变ui控件上需要加延时,也就是Future.delayed(Duration(milliseconds: 200),(){})

MaterialButton(onPressed: (){
                                          setState(() {
                                            _textEditingController.text=text[i][j];
                                            searchname = _textEditingController.text;
                                            getSearchres();
                                            Future.delayed(Duration(milliseconds: 200), () {
                                              setState(() {
                                                if (res_error == "未找到符合相关条件现场演出") {
                                                  return showDialog(
                                                      context: context,
                                                      barrierDismissible: true,
                                                      builder: (context) {
                                                        return AlertDialog(
                                                          content: Text(res_error),
                                                        );
                                                      });
                                                } else {
                                                  offstage = false;
                                                }
                                              });

                                              if (!_textEditingController.text.isEmpty &&
                                                  num[0] < 10) {
                                                for (var i = 0; i < num[0]; i++) {
                                                  if (Comparable.compare(text[0][i],
                                                      _textEditingController.text) ==
                                                      0) {
                                                    text[0].removeAt(i);
                                                    num[0]--;
                                                  }
                                                }
                                                text[0].insert(0, _textEditingController.text);
                                                height[0] = ScreenUtil().setHeight(50);
                                                cont[0] = Colors.black;
                                                iconheight[0] = 45.0;
                                                num[0]++;
                                              } else if (!_textEditingController.text.isEmpty) {
                                                for (var i = 0; i < num[0]; i++) {
                                                  if (Comparable.compare(text[0][i],
                                                      _textEditingController.text) ==
                                                      0) {
                                                    text[0].removeAt(i);
                                                  }
                                                }
                                                text[0].removeAt(text[0].length - 1);
                                                text[0].insert(0, _textEditingController.text);
                                                height[0] = ScreenUtil().setHeight(50);
                                                cont[0] = Colors.black;
                                                iconheight[0] = 45.0;
                                              }
                                            });
                                          });
                                        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值