搜索历史记录的实现
用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;
}
});
});
},