hyzp_ybqx-Commit001:代码刚转换好,编译通过
This commit is contained in:
@@ -0,0 +1,676 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:hyzp_ybqx/services/EventBus.dart';
|
||||
import 'package:hyzp_ybqx/widget/JdButton.dart';
|
||||
import 'package:keyboard_avoider/keyboard_avoider.dart';
|
||||
|
||||
import '../../../components/commonFun.dart';
|
||||
import '../../../components/dioFun.dart';
|
||||
import '../../../components/hyxx_data_handle.dart';
|
||||
import '../../../widget/DropdownItem.dart';
|
||||
|
||||
class LedXsxxContent extends StatefulWidget {
|
||||
LedXsxxContent({
|
||||
@required this.sbgllx, //sbgllx: 'led_xsxx', //设备管理类型:LED显示信息
|
||||
@required this.title,
|
||||
@required this.id,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
String title;
|
||||
int id;
|
||||
String sbgllx;
|
||||
|
||||
_LedXsxxPageState createState() => _LedXsxxPageState();
|
||||
}
|
||||
|
||||
//用TabController实现顶部tab切换
|
||||
class _LedXsxxPageState extends State<LedXsxxContent> {
|
||||
//try_setState(); //避免异常报错
|
||||
try_setState() {
|
||||
try {
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
print('setState(() {})异常:${e}');
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _title = '';
|
||||
|
||||
//flutter_screenUtil 4.x 用法,ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //设备宽度
|
||||
double _screenWidth = 1.sw;
|
||||
|
||||
double _marginLeft = 15;
|
||||
double _marginCenter = 5;
|
||||
double _marginCenterHeight = 20;
|
||||
double _widgetHeight = 35;
|
||||
double _fontSize = 16;
|
||||
double _widthLeft = 40; // = _screenWidth / 3;
|
||||
double _iconSize = 18;
|
||||
double _stampSize = 100;
|
||||
double _listTileHeight = 30;
|
||||
Color _iconColor = Colors.blue;
|
||||
double _titleWidth = 130;
|
||||
|
||||
//处理全部记录
|
||||
bool _modifyAll = false;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// listLedXsxxGetList2.clear();
|
||||
// ///从接口 mapHyshlx[hyshlx]['api'] 获取第 iPage 页的列表数据,返回 list
|
||||
// getPageList().then((value) {
|
||||
// listLedXsxxGetList2 = value;
|
||||
// //按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
// });
|
||||
|
||||
///从接口 mapHyshlx[theHyshlx]['api'] 获取指定类型第 page 页的列表数据,返回 list
|
||||
///获取点位信息数据
|
||||
listDwinfoGetList2.clear();
|
||||
getThePageList(theHyshlx: 'dwxx').then((value) {
|
||||
listDwinfoGetList2 = value;
|
||||
print('listDwinfoGetList2 = \n$listDwinfoGetList2');
|
||||
getListFlields();
|
||||
});
|
||||
//listDwinfoGetList2 = [{
|
||||
// "id": 1,
|
||||
// "dwip": "172.16.3.1",
|
||||
// "dwmc": "江北振兴大道",
|
||||
// "dwbh": 1,
|
||||
// "dwinfo": "江北振兴大道入城方向",
|
||||
// "dwzb": "104.607091|28.807061",
|
||||
// "dwms": "江北振兴大道入城方向,识别孜岩、红坝路入城排放黑烟车辆"
|
||||
//},
|
||||
//{
|
||||
// "id": 2,
|
||||
// "dwip": "172.16.3.2",
|
||||
// "dwmc": "宜飞路",
|
||||
// "dwbh": 2,
|
||||
// "dwinfo": "宜宾南收费站宜飞路入城方向",
|
||||
// "dwzb": "104.589904|28.787078",
|
||||
// "dwms": "宜宾南收费站宜飞路入城方向,识别屏山、菜坝入城排放黑烟车辆"
|
||||
//},];
|
||||
|
||||
_widthLeft = _screenWidth / 2.6;
|
||||
|
||||
//监听 选择LED点位 更新事件
|
||||
eventBus.on<SelectLedDwUpdateEvent>().listen((event) async {
|
||||
//获取用户选择项对应的记录id
|
||||
widget.id = _listItems.indexOf(event.selectedValue);
|
||||
print('原生 widget.id = ${widget.id}');
|
||||
if (widget.id < 1) {
|
||||
_modifyAll = true; //处理全部记录
|
||||
widget.id = 1;
|
||||
} else {
|
||||
_modifyAll = false; //处理全部记录
|
||||
}
|
||||
print('widget.id = ${widget.id}');
|
||||
|
||||
//刷新页面数据
|
||||
await getListFlields();
|
||||
|
||||
//刷新 显示违章记录 Dropdown
|
||||
// print('_mapGetLedXsxxGetData = ${_mapGetLedXsxxGetData}');
|
||||
// print('_mapGetLedXsxxGetData["xsts"] = ${_mapGetLedXsxxGetData["xsts"]}');
|
||||
// print(
|
||||
// 'getWzjlString(_mapGetLedXsxxGetData["xsts"]) = ${getWzjlString(_mapGetLedXsxxGetData["xsts"])}');
|
||||
eventBus.fire(SelectWzjlUpdateEvent(
|
||||
'external_SelectWzjlUpdateEvent', getWzjlString(_mapGetLedXsxxGetData["xsts"])));
|
||||
|
||||
try_setState(); //避免异常报错
|
||||
print(event.str);
|
||||
});
|
||||
|
||||
//监听 选择显示违章记录 更新事件
|
||||
eventBus.on<SelectWzjlUpdateEvent>().listen((event) async {
|
||||
print('SelectWzjlUpdateEvent: ${event.str}');
|
||||
print('SelectWzjlUpdateEvent: ${event.selectedValue}');
|
||||
_selectedValue = event.selectedValue;
|
||||
_xsts = getWzjlCount(event.selectedValue);
|
||||
//只响应内部发送的'insider_SelectWzjlUpdateEvent'
|
||||
//不响应外部发送的'external_SelectWzjlUpdateEvent'
|
||||
if (event.str == 'external_SelectWzjlUpdateEvent') {
|
||||
//刷新页面数据
|
||||
try_setState(); //避免异常报错
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//App.Car_Led.Get接口获取的记录数据结构(比App.Car_Led.GetList接口获取的丰富)
|
||||
Map _mapGetLedXsxxGetData = {
|
||||
"id": 2,
|
||||
"dwip": "172.16.3.2",
|
||||
"xsnr": "绿水青山就是金山银山 宜宾市生态环境局宣。",
|
||||
"xsts": 0, //显示抓拍到的多少条违章记录
|
||||
"stime": "07:00",
|
||||
"etime": "23:00",
|
||||
"addtime": "2021-01-20 10:16:07",
|
||||
"updatetime": "2021-02-13 11:48:51"
|
||||
};
|
||||
|
||||
//Web管理平台LED点位名称。除第一项外,估计后面都按ID号排列
|
||||
// 全部
|
||||
// 1 '江北振兴大道',
|
||||
// 2 '宜飞路',
|
||||
// 3 '宜宾南收费站',
|
||||
// 4 '一曼路',
|
||||
// 5 '柏溪收费站',
|
||||
// 6 '七星路万达广场',
|
||||
// 7 '宜宾财政局',
|
||||
// 8 '宜威路南广镇',
|
||||
// 9 '宜长路',
|
||||
// 10 '宜南快速通道',
|
||||
// 11 '观斗山隧道',
|
||||
// 12 '大麦坝',
|
||||
// 13 '外江路',
|
||||
|
||||
//LED点位名称List,除第一项外,后面都按ID号排列
|
||||
List _listItems = [
|
||||
// '全部',
|
||||
// '1、江北振兴大道',
|
||||
// '2、宜飞路',
|
||||
// '3、宜宾南收费站',
|
||||
// '4、一曼路',
|
||||
// '5、柏溪收费站',
|
||||
// '6、七星路万达广场',
|
||||
// '7、宜宾财政局',
|
||||
// '8、宜威路南广镇',
|
||||
// '9、宜长路',
|
||||
// '10、宜南快速通道',
|
||||
// '11、观斗山隧道',
|
||||
// '12、大麦坝',
|
||||
// '13、外江路',
|
||||
];
|
||||
|
||||
String _selectedValue = '不显示';
|
||||
int _xsts = 0;
|
||||
String _startTime = '07:00';
|
||||
String _endTime = '23:00';
|
||||
String _ledMessage = '绿水青山就是金山银山 宜宾市生态环境局宣。';
|
||||
|
||||
//App.Car_Led.Get接口获取的记录数据结构(比App.Car_Led.GetList接口获取的丰富)
|
||||
// Map _mapGetLedXsxxGetData = {
|
||||
// "id": 2,
|
||||
// "dwip": "172.16.3.2",
|
||||
// "xsnr": "绿水青山就是金山银山 宜宾市生态环境局宣。",
|
||||
// "xsts": 0, //显示抓拍到的多少条违章记录
|
||||
// "stime": "07:00",
|
||||
// "etime": "23:00",
|
||||
// "addtime": "2021-01-20 10:16:07",
|
||||
// "updatetime": "2021-02-13 11:48:51"
|
||||
// };
|
||||
|
||||
Future getListFlields() async {
|
||||
//实时更新_listItems内容
|
||||
_listItems = ['全部']; //LED点位名称List,除第一项外,后面都按ID号排列
|
||||
int len = listDwinfoGetList2.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
_listItems.add('${i + 1}、${listDwinfoGetList2[i]['dwmc']}');
|
||||
}
|
||||
print('_listItems = $_listItems');
|
||||
|
||||
//获取指定id的LED记录数据返回 _mapGetLedXsxxGetData
|
||||
_mapGetLedXsxxGetData = await getLedXsxxGetData(id: widget.id, theSbgllx: widget.sbgllx);
|
||||
//printWrapped('_mapGetLedXsxxGetData = ${_mapGetLedXsxxGetData}');
|
||||
//_mapGetLedXsxxGetData = {
|
||||
// "id": 1,
|
||||
// "dwip": "172.16.3.1",
|
||||
// "xsnr": "绿水青山就是金山银山 宜宾市生态环境局宣。",
|
||||
// "xsts": 0,
|
||||
// "stime": "07:00",
|
||||
// "etime": "23:00",
|
||||
// "addtime": "2021-01-06 00:59:43",
|
||||
// "updatetime": "2021-02-03 19:57:55"
|
||||
// };
|
||||
|
||||
_xsts = _mapGetLedXsxxGetData['xsts'];
|
||||
_ledMessage = _mapGetLedXsxxGetData['xsnr'];
|
||||
_startTime = _mapGetLedXsxxGetData['stime'];
|
||||
_endTime = _mapGetLedXsxxGetData['etime'];
|
||||
|
||||
try {
|
||||
// _title =listDwinfoGetList2
|
||||
// '${widget.title}(${(getIndex(widget.id) + 1).toString()} / ${listLedXsxxGetList2.length})id:${widget.id.toString()}';
|
||||
//_title = '${widget.title}(${widget.id.toString()} / ${listDwinfoGetList2.length})id:${widget.id.toString()}';
|
||||
//_title = '${widget.title}(${widget.id.toString()} / ${listDwinfoGetList2.length})${listDwinfoGetList2[widget.id - 1]['dwmc']}';
|
||||
_title = '${widget.title}(${widget.id.toString()} / ${listDwinfoGetList2.length})';
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
print('setState(() {})异常:${e}');
|
||||
}
|
||||
|
||||
// List listLedXsxxGetData = [];
|
||||
// for(int i = 0; i < 13; i++) {
|
||||
// listLedXsxxGetData.add(await getLedXsxxGetData(i + 1));
|
||||
// }
|
||||
// print('listLedXsxxGetData = \nlistLedXsxxGetData');
|
||||
}
|
||||
|
||||
//获取 listLedXsxxGetList2 中ID号为 _id 的索引号
|
||||
// int getIndex(int _id) {
|
||||
// int len = listLedXsxxGetList2.length;
|
||||
// int _index;
|
||||
// for (_index = 0; _index < len; _index++) {
|
||||
// if (listLedXsxxGetList2[_index]['id'] == _id) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return _index;
|
||||
// }
|
||||
|
||||
Widget getTitleText(String text, {double fontSize = 16}) {
|
||||
return Text(text,
|
||||
style: TextStyle(fontSize: fontSize),
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis);
|
||||
}
|
||||
|
||||
Widget getSizeText(String text, {double fontSize = 16, double width = 100, double top = 0}) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: top),
|
||||
width: width,
|
||||
child: Text(text,
|
||||
style: TextStyle(fontSize: fontSize),
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getIcon(IconData _iconData) {
|
||||
return Container(
|
||||
width: _iconSize - 2,
|
||||
height: _iconSize,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 2),
|
||||
child: Icon(_iconData, size: _iconSize, color: _iconColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//5、得到LED显示信息确认组件
|
||||
Widget getLedQr() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
JdButton(
|
||||
height: 126,
|
||||
//JdText中已经使用ScreenUtil().setHeight(126),此处不能传 ScreenUtil().setHeight(126) ,否则严重错位
|
||||
width: 350,
|
||||
text: "更新",
|
||||
color: Color.fromRGBO(45, 202, 115, 1),
|
||||
onTop: () {
|
||||
printWrapped('_message = ${_ledMessage}');
|
||||
print('_xsts = ${_xsts}');
|
||||
print('_startTime = ${_startTime}');
|
||||
print('_endTime = ${_endTime}');
|
||||
|
||||
//updateLedData({@required int id, @required String theSbgllx, @required Map map})
|
||||
//_modifyAll = true; //id = -1,处理全部记录
|
||||
updateLedData(id: _modifyAll ? -1 : widget.id, theSbgllx: 'led_update', map: {
|
||||
'xsnr': _ledMessage,
|
||||
'xsts': _xsts,
|
||||
'stime': _startTime,
|
||||
'etime': _endTime,
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
JdButton(
|
||||
height: 126,
|
||||
//JdText中已经使用ScreenUtil().setHeight(126),此处不能传 ScreenUtil().setHeight(126) ,否则严重错位
|
||||
width: 350,
|
||||
text: "取消",
|
||||
color: Color.fromRGBO(43, 163, 255, 1),
|
||||
onTop: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
//得到LED信息页面组件
|
||||
//1、得到 选择LED点位 组件
|
||||
Widget getSelectLedDw() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
getSizeText('选择点位:', width: _titleWidth),
|
||||
//SizedBox(width: _marginCenter),
|
||||
//Expanded(child: SizedBox.shrink()),
|
||||
DropdownItem(
|
||||
listItems: _listItems,
|
||||
//初始值 initValue 必须是 listItems 中的已有元素
|
||||
initValue: _listItems[widget.id],
|
||||
dropdownEvent: 'SelectLedDwUpdateEvent',
|
||||
width: ScreenUtil().setWidth(590),
|
||||
height: _widgetHeight,
|
||||
), //SizedBox(width: _marginLeft),
|
||||
SizedBox(width: _marginLeft),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
//2、得到选择 显示违章记录 组件
|
||||
Widget getSelectWzjl() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
getSizeText('显示违章记录:', width: _titleWidth),
|
||||
// Expanded(child: SizedBox.shrink()),
|
||||
DropdownItem(
|
||||
listItems: _listItemsWzjl,
|
||||
initValue: getWzjlString(_xsts),
|
||||
width: ScreenUtil().setWidth(590),
|
||||
height: _widgetHeight,
|
||||
dropdownEvent: 'SelectWzjlUpdateEvent',
|
||||
),
|
||||
SizedBox(width: _marginLeft),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List _listItemsWzjl = [
|
||||
'不显示',
|
||||
'显示3条',
|
||||
'显示5条',
|
||||
'显示10条',
|
||||
];
|
||||
|
||||
//通过违章信息的条数得到显示的字符串
|
||||
String getWzjlString(int wzjlCount) {
|
||||
String _wzjlString = '';
|
||||
switch (wzjlCount) {
|
||||
case 0:
|
||||
_wzjlString = _listItemsWzjl[0];
|
||||
break;
|
||||
case 3:
|
||||
_wzjlString = _listItemsWzjl[1];
|
||||
break;
|
||||
case 5:
|
||||
_wzjlString = _listItemsWzjl[2];
|
||||
break;
|
||||
case 10:
|
||||
_wzjlString = _listItemsWzjl[3];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return _wzjlString;
|
||||
}
|
||||
|
||||
//通过字符串得到显示违章信息的条数
|
||||
int getWzjlCount(String wzjlString) {
|
||||
int _wzjlCount = -1;
|
||||
switch (wzjlString) {
|
||||
case '不显示':
|
||||
_wzjlCount = 0;
|
||||
break;
|
||||
case '显示3条':
|
||||
_wzjlCount = 3;
|
||||
break;
|
||||
case '显示5条':
|
||||
_wzjlCount = 5;
|
||||
break;
|
||||
case '显示10条':
|
||||
_wzjlCount = 10;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return _wzjlCount;
|
||||
}
|
||||
|
||||
//3、得到 启用时段 组件
|
||||
Widget getOpenTime() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
getSizeText('启用时段:', width: _titleWidth),
|
||||
//SizedBox(width: _marginCenter),
|
||||
getInBox(0, _widgetHeight), //whichTime:0为_startTime,1为_endTime
|
||||
Text(' - '),
|
||||
getInBox(1, _widgetHeight), //whichTime:0为_startTime,1为_endTime
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
//4、得到 显示信息 组件
|
||||
Widget getLedMessage(double _width, double _height) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
getSizeText('显示信息:', width: _titleWidth, top: 2),
|
||||
],
|
||||
),
|
||||
SizedBox(height: ScreenUtil().setHeight(10)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
getInBoxMsg(_width, _height), //whichTime:0为_startTime,1为_endTime
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
//显示信息 输入框
|
||||
Widget getInBoxMsg(double _width, double _height) {
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: ScreenUtil().setHeight(_height),
|
||||
maxHeight: ScreenUtil().setHeight(_height),
|
||||
minWidth: ScreenUtil().setWidth(_width),
|
||||
maxWidth: ScreenUtil().setWidth(_width),
|
||||
),
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: 10,
|
||||
//不限制行数
|
||||
textAlign: TextAlign.justify,
|
||||
style: TextStyle(fontSize: my_fontSize),
|
||||
decoration: InputDecoration(
|
||||
hintText: '请输入LED显示信息',
|
||||
contentPadding: EdgeInsets.only(top: 4, left: 8, bottom: 4, right: 8),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 2.0),
|
||||
borderRadius: BorderRadius.circular(3.0)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 2.0),
|
||||
borderRadius: BorderRadius.circular(3.0)),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 2.0,
|
||||
),
|
||||
),
|
||||
// border: OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(3.0),
|
||||
// borderSide: BorderSide(color: Colors.grey, width: 0)),
|
||||
),
|
||||
controller: TextEditingController.fromValue(TextEditingValue(
|
||||
text: _ledMessage,
|
||||
// 保持光标在最后
|
||||
// selection: TextSelection.fromPosition(
|
||||
// TextPosition(affinity: TextAffinity.downstream, offset: _message.length))
|
||||
)),
|
||||
enabled: true,
|
||||
onChanged: (value) {
|
||||
_ledMessage = value;
|
||||
printWrapped(_ledMessage);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//whichTime:0为_startTime,1为_endTime
|
||||
Widget getInBox(int _whichTime, double _height) {
|
||||
return Container(
|
||||
alignment: Alignment(0, 0),
|
||||
height: _height,
|
||||
width: 90,
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(color: Colors.grey, width: 2),
|
||||
// borderRadius: BorderRadius.all(Radius.circular(3.0)),
|
||||
// ),
|
||||
child: TextField(
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: my_fontSize),
|
||||
decoration: InputDecoration(
|
||||
hintText: _whichTime == 0 ? '启用时间' : '关闭时间',
|
||||
contentPadding: EdgeInsets.all(0),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 2.0),
|
||||
borderRadius: BorderRadius.circular(3.0)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 2.0),
|
||||
borderRadius: BorderRadius.circular(3.0)),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 2.0,
|
||||
),
|
||||
),
|
||||
// border: OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(3.0),
|
||||
// borderSide: BorderSide(color: Colors.grey, width: 0)),
|
||||
),
|
||||
controller: TextEditingController.fromValue(TextEditingValue(
|
||||
text: (_whichTime == 0 ? _startTime : _endTime),
|
||||
// 保持光标在最后
|
||||
selection: TextSelection.fromPosition(TextPosition(
|
||||
affinity: TextAffinity.downstream,
|
||||
offset: (_whichTime == 0 ? _startTime : _endTime).length)))),
|
||||
enabled: true,
|
||||
onChanged: (value) {
|
||||
if (_whichTime == 0) {
|
||||
_startTime = value;
|
||||
} else {
|
||||
_endTime = value;
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _sizedropDown = 'brown';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
//resizeToAvoidBottomPadding: false,
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
|
||||
child: AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
centerTitle: true,
|
||||
titleSpacing: 0.0,
|
||||
//设置title的左边距
|
||||
flexibleSpace: Container(
|
||||
//SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
|
||||
// SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
|
||||
padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
|
||||
child: Container(
|
||||
//height: ScreenUtil().setHeight(173),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.centerLeft,
|
||||
end: Alignment.centerRight,
|
||||
colors: [
|
||||
Color.fromRGBO(12, 186, 156, 1),
|
||||
Color.fromRGBO(39, 127, 235, 1),
|
||||
],
|
||||
),
|
||||
),
|
||||
// decoration: BoxDecoration(
|
||||
// gradient: LinearGradient(colors: [
|
||||
// Color(0xFF0018EB),
|
||||
// Color(0xFF01C1D9),
|
||||
// ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
|
||||
// ),
|
||||
),
|
||||
),
|
||||
title: Padding(
|
||||
padding: EdgeInsets.only(left: 0, right: 0),
|
||||
child: Row(
|
||||
//mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
getIconAndTextButton(
|
||||
iconColor: Colors.white,
|
||||
iconData: Icons.chevron_left_outlined,
|
||||
onPress: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Text(_title,
|
||||
style: TextStyle(color: Colors.white, fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
SizedBox(width: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: _listItems.isEmpty || _mapGetLedXsxxGetData == null
|
||||
? getMoreWidget(color: Colors.grey)
|
||||
: KeyboardAvoider(
|
||||
autoScroll: true,
|
||||
child: Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
//1、得到选择LED点位组件
|
||||
SizedBox(height: _marginCenterHeight),
|
||||
getSelectLedDw(),
|
||||
Divider(height: _marginCenterHeight),
|
||||
//2、得到选择 显示违章记录 组件
|
||||
getSelectWzjl(),
|
||||
Divider(height: _marginCenterHeight),
|
||||
//3、得到 启用时段 组件
|
||||
getOpenTime(),
|
||||
Divider(height: _marginCenterHeight),
|
||||
//4、得到 显示信息 组件
|
||||
getLedMessage(980, 570),
|
||||
Divider(height: _marginCenterHeight),
|
||||
SizedBox(height: _marginCenterHeight),
|
||||
//5、得到Led确认组件
|
||||
getLedQr(),
|
||||
SizedBox(height: _marginCenterHeight),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBtnSizeX({@required text, width = 70.0, height = 35.0, onPressedFun}) {
|
||||
return Container(
|
||||
color: Colors.white12, //onPressedFun为null时无效
|
||||
width: width,
|
||||
height: height,
|
||||
child: RaisedButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
textColor: Colors.black,
|
||||
child: Text(text),
|
||||
onPressed: onPressedFun,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,568 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
import 'led_xsxx_content.dart';
|
||||
import '../../../components/dioFun.dart';
|
||||
import '../../../components/hyxx_data_handle.dart';
|
||||
import '../../../components/commonFun.dart';
|
||||
import '../../../services/EventBus.dart';
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
import '../../../components/doJSON.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
|
||||
//LedXsxx是本项目中“LED显示信息”的统一缩写
|
||||
class LedXsxxGetList extends StatefulWidget {
|
||||
//hyshlx为黑烟审核类型,处理'LedXsxx'LED显示信息。mapHyshlx[hyshlx]获取为各种类型的设置数据
|
||||
LedXsxxGetList({this.sbgllx = 'led_xsxx', Key key}) : super(key: key);
|
||||
String sbgllx;
|
||||
|
||||
_LedXsxxPageState createState() => _LedXsxxPageState();
|
||||
}
|
||||
|
||||
class _LedXsxxPageState extends State<LedXsxxGetList> {
|
||||
//try_setState(); //避免异常报错
|
||||
try_setState() {
|
||||
try {
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
print('setState(() {})异常:${e}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose(); //销毁控制器
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
hyshlx = widget.sbgllx;
|
||||
iPage = 0;
|
||||
listLedXsxxGetList2.clear();
|
||||
|
||||
///从接口 mapHyshlx[hyshlx]['api'] 获取第 iPage 页的列表数据,返回 list
|
||||
getPageList().then((value) {
|
||||
listLedXsxxGetList2 = value;
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
firstIndex = 0;
|
||||
lastIndex = 7;
|
||||
});
|
||||
|
||||
///从接口 mapHyshlx[theHyshlx]['api'] 获取指定类型第 page 页的列表数据,返回 list
|
||||
///获取点位信息数据
|
||||
listDwinfoGetList2.clear();
|
||||
getThePageList(theHyshlx: 'dwxx').then((value) {
|
||||
listDwinfoGetList2 = value;
|
||||
print('listDwinfoGetList2 = \n$listDwinfoGetList2');
|
||||
});
|
||||
|
||||
//监听违章信息数据更新事件
|
||||
eventBus.on<LedXsxxUpdateEvent>().listen((event) async {
|
||||
iPage = 0;
|
||||
print(event.str);
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
});
|
||||
|
||||
//监听违章信息数据审核事件
|
||||
eventBus.on<WzxxDataAuditEvent>().listen((event) async {
|
||||
print('LedXsxxGetList: ' + event.str);
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
});
|
||||
|
||||
//监听违章信息Listview滚动事件
|
||||
eventBus.on<WzxxDataScrollEvent>().listen((event) async {
|
||||
firstIndex = event.firstIndex;
|
||||
lastIndex = event.lastIndex;
|
||||
try_setState();
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
//Led数据变量
|
||||
// Map mapGetLedXsxxGetData = {
|
||||
// "id": 2,
|
||||
// "xsnr": "绿水青山就是金山银山 宜宾市生态环境局宣。",
|
||||
// "addtime": "2021-01-20 10:16:07",
|
||||
// "updatetime": "2021-02-13 11:48:51"
|
||||
// };
|
||||
Widget _getListTile(BuildContext context, indexRecord) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
//leading: new Icon(Icons.phone),
|
||||
title: Text(
|
||||
"${(indexRecord + 1).toString()}. " +
|
||||
listLedXsxxGetList2[indexRecord]['addtime'] +
|
||||
' 添加',
|
||||
style: TextStyle(fontSize: 10)),
|
||||
subtitle: Text(getDate(listLedXsxxGetList2[indexRecord]['updatetime']) + ' 更新',
|
||||
style: TextStyle(fontSize: 10)),
|
||||
trailing: Container(
|
||||
width: 180,
|
||||
child: Text(
|
||||
'id:' +
|
||||
listLedXsxxGetList2[indexRecord]['id'].toString() +
|
||||
', 显示信息:' +
|
||||
listLedXsxxGetList2[indexRecord]['xsnr'],
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
//textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
|
||||
enabled: true,
|
||||
onTap: () async {
|
||||
int ret = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LedXsxxContent(
|
||||
title: 'LED显示信息详情',
|
||||
sbgllx: widget.sbgllx,
|
||||
id: listLedXsxxGetList2[indexRecord]['id'],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
print('ret = $ret');
|
||||
},
|
||||
),
|
||||
Divider(height: 1.0),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
ScrollController _controller = ScrollController(); //ListView控制器
|
||||
bool isLoading = false; //正在处理下载数据、跳转到首项、跳转到尾项等操作
|
||||
int firstIndex = 0; //ListView当前显示页面首项0基序号
|
||||
int lastIndex = 0; //ListView当前显示页面末项0基序号
|
||||
int itemOnPage = 8; //估计一屏显示的项目数量
|
||||
|
||||
Widget getIconButton({IconData iconData, var onPressed, double iconSize = 22}) {
|
||||
return SizedBox(
|
||||
height: iconSize,
|
||||
width: iconSize + 10,
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(0.0),
|
||||
icon: Icon(iconData, size: iconSize),
|
||||
onPressed: onPressed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
centerTitle: true,
|
||||
//leading: Text(''),
|
||||
titleSpacing: 0.0,
|
||||
//设置title的左边距
|
||||
title: Padding(
|
||||
padding: EdgeInsets.only(left: 0, right: 0),
|
||||
child: Row(
|
||||
//mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
getIconAndTextButton(
|
||||
iconData: Icons.arrow_back,
|
||||
onPress: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Text("${mapHyshlx[hyshlx]['text']}",
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: widget.sbgllx == 'fhycx' ? TextStyle(fontSize: 16) : null),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
getDropdownButton(),
|
||||
SizedBox(width: 10),
|
||||
getIconButton(
|
||||
iconData: Icons.cloud_download,
|
||||
onPressed: !isLoading
|
||||
? () async {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
//print("I Pressed the Iconbutton");
|
||||
int oldItems = listLedXsxxGetList2.length;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
List list = await getPageList();
|
||||
if (list.length > 0) {
|
||||
listLedXsxxGetList2.addAll(list); //加载累加
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 1000), () async {
|
||||
if (listLedXsxxGetList2.length > oldItems) {
|
||||
eventBus.fire(WzxxDataAuditEvent('${mapHyshlx[hyshlx]['text']}数据已更新'));
|
||||
Fluttertoast.showToast(
|
||||
msg: '新增 ${listLedXsxxGetList2.length - oldItems} 条数据下载完成!',
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
);
|
||||
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
}
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
});
|
||||
}
|
||||
: null,
|
||||
),
|
||||
getIconButton(
|
||||
iconData: Icons.vertical_align_top_outlined,
|
||||
onPressed: (!isLoading && (firstIndex > 0)) //未到顶部
|
||||
? () async {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
|
||||
//必须延时执行,否则不能及时完成按钮状态更新
|
||||
Timer(
|
||||
Duration(milliseconds: 500),
|
||||
() {
|
||||
_controller.jumpTo(_controller.position.minScrollExtent);
|
||||
},
|
||||
);
|
||||
|
||||
Timer(
|
||||
Duration(milliseconds: 1000),
|
||||
() {
|
||||
// Fluttertoast.showToast(
|
||||
// msg: '已经跳转到开头记录!',
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.CENTER,
|
||||
// );
|
||||
firstIndex = 0;
|
||||
lastIndex = itemOnPage - 1; //0基序号,所以需要减1
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
getIconButton(
|
||||
iconData: Icons.vertical_align_bottom_outlined,
|
||||
onPressed: (!isLoading && (lastIndex < listLedXsxxGetList2.length)) //未到尾部
|
||||
? () async {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
|
||||
//必须延时执行,否则不能及时完成按钮状态更新
|
||||
Timer(
|
||||
Duration(milliseconds: 500),
|
||||
() {
|
||||
_controller.jumpTo(_controller.position.maxScrollExtent);
|
||||
},
|
||||
);
|
||||
|
||||
Timer(
|
||||
Duration(milliseconds: 1000),
|
||||
() {
|
||||
// Fluttertoast.showToast(
|
||||
// msg: '已经跳转到末尾记录!',
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.CENTER,
|
||||
// );
|
||||
//0基序号需要减1,再加上底部有一组显示信息,所以需要减2
|
||||
firstIndex = listLedXsxxGetList2.length - itemOnPage - 2;
|
||||
lastIndex = listLedXsxxGetList2.length;
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: (0 == listLedXsxxGetList2.length)
|
||||
? getMoreWidget(color: Colors.black38)
|
||||
: EasyRefresh(
|
||||
child: ListView.custom(
|
||||
controller: _controller,
|
||||
cacheExtent: 1.0, // 只有设置了1.0 才能够准确的标记position 位置
|
||||
childrenDelegate: MyChildrenDelegate(
|
||||
_getListTile,
|
||||
childCount: listLedXsxxGetList2.length,
|
||||
),
|
||||
),
|
||||
onRefresh: () async {
|
||||
// await Future.delayed(const Duration(seconds: 1), () async {
|
||||
// iPage = 0;
|
||||
// //await getWzxxGetList();
|
||||
// listLedXsxxGetList2 = await getPageList();
|
||||
// eventBus.fire(WzxxDataAuditEvent('${mapHyshlx[hyshlx]['text']}数据已更新'));
|
||||
// });
|
||||
},
|
||||
onLoad: () async {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
|
||||
print('iPage = $iPage');
|
||||
await Future.delayed(const Duration(seconds: 1), () async {
|
||||
//await getWzxxGetList();
|
||||
List list = await getPageList();
|
||||
if (list.length > 0) {
|
||||
listLedXsxxGetList2.addAll(list); //加载累加
|
||||
eventBus.fire(WzxxDataAuditEvent('${mapHyshlx[hyshlx]['text']}数据已更新'));
|
||||
}
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
});
|
||||
},
|
||||
header: getHeader(),
|
||||
footer: getFooter(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//DropdownButton需要设置初始值的时候,初始值必须是显示列表里面的值,否则会导致弹出框异常。
|
||||
// 比如说:你的DropdownButton的items属性使用的是list这个列表里面的值,那么你的初始值应该在list[index]里面取,要不就会报错。
|
||||
//
|
||||
// There should be exactly one item with [DropdownButton]'s value: 0.0.
|
||||
// Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
|
||||
// 'package:flutter/src/material/dropdown.dart':
|
||||
// Failed assertion: line 834 pos 15: 'items == null || items.isEmpty || value == null ||
|
||||
// items.where((DropdownMenuItem<T> item) {
|
||||
// return item.value == value;
|
||||
// }).length == 1'
|
||||
String _selectedValue = '主键ID';
|
||||
bool _descending = false; //默认生效排列
|
||||
|
||||
Widget _getImage(String _image) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(),
|
||||
height: ScreenUtil().setWidth(38),
|
||||
width: ScreenUtil().setWidth(38),
|
||||
//child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
|
||||
child: Image.asset(_image,
|
||||
fit: BoxFit.cover, color: isLoading ? Theme.of(context).disabledColor : null));
|
||||
}
|
||||
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
Future _listSort({bool bShowToast = false}) {
|
||||
if (!isLoading && listLedXsxxGetList2.length > 0) {
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
|
||||
switch (_selectedValue) {
|
||||
default:
|
||||
if (_descending) {
|
||||
//按_selectedValue排序,降序
|
||||
listLedXsxxGetList2.sort((a, b) =>
|
||||
(b[mapWzxxDataText[_selectedValue]]).compareTo(a[mapWzxxDataText[_selectedValue]]));
|
||||
} else {
|
||||
//按_selectedValue排序,升序
|
||||
listLedXsxxGetList2.sort((a, b) =>
|
||||
(a[mapWzxxDataText[_selectedValue]]).compareTo(b[mapWzxxDataText[_selectedValue]]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
if (bShowToast) {
|
||||
Fluttertoast.showToast(
|
||||
msg: '按“${_selectedValue}”${_descending ? '降序' : '升序'}排列完成!',
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
);
|
||||
}
|
||||
isLoading = false;
|
||||
try_setState(); //避免如下异常报错
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget getDropdownButtonItemText(String item) {
|
||||
return Row(
|
||||
//crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment(0, 0.28),
|
||||
child: item == _selectedValue
|
||||
? _descending
|
||||
? _getImage('assets/images/descending.png')
|
||||
: _getImage('assets/images/ascending.png')
|
||||
// ? Icon(Icons.arrow_downward_outlined, size: 20)
|
||||
// : Icon(Icons.arrow_upward_outlined, size: 20)
|
||||
: SizedBox(),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3,
|
||||
),
|
||||
Container(
|
||||
//alignment: Alignment(0, -1),
|
||||
child: Text(item,
|
||||
style: isLoading
|
||||
? TextStyle(color: Theme.of(context).disabledColor)
|
||||
: (item == _selectedValue ? TextStyle(color: Colors.blue) : null)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget getDropdownButton() {
|
||||
//DropdownMenuItem项目文本list
|
||||
List<String> itemList = [
|
||||
'主键ID',
|
||||
'添加时间',
|
||||
'更新时间',
|
||||
'显示信息',
|
||||
];
|
||||
|
||||
//添加按'推送状态'排序
|
||||
if (hyshlx != 'led_xsxx') {
|
||||
itemList.removeLast();
|
||||
itemList.addAll(['推送状态', '主键ID']);
|
||||
}
|
||||
|
||||
//获取DropdownMenuItem项目组件list
|
||||
List<DropdownMenuItem<String>> _dropDownMenuItems =
|
||||
itemList.map<DropdownMenuItem<String>>((String item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: getDropdownButtonItemText(item),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: Container(
|
||||
alignment: Alignment(0.7, 0),
|
||||
width: 125,
|
||||
margin: EdgeInsets.only(bottom: 0),
|
||||
padding: EdgeInsets.only(left: 0, bottom: 0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(width: 0),
|
||||
//边框圆角设置
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.elliptical(2, 2), bottom: Radius.elliptical(2, 2)),
|
||||
),
|
||||
//DropdownButton默认有一条下划线,DropdownButtonHideUnderline去除下划线
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isDense: true,
|
||||
value: _selectedValue,
|
||||
items: _dropDownMenuItems,
|
||||
onChanged: (String selectedValue) {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedValue == selectedValue) {
|
||||
_descending = !_descending;
|
||||
} else {
|
||||
_descending = true;
|
||||
}
|
||||
_selectedValue = selectedValue;
|
||||
print('_selectedValue = $_selectedValue');
|
||||
|
||||
//按照用户选择的_selectedValue、_descending对listLedXsxxGetList2进行排序,并延时更新
|
||||
_listSort(bShowToast: true);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//https://blog.csdn.net/u014803467/article/details/103750018
|
||||
//Flutter 使用SliverChildBuilderDelegate获取ListView的第一个和最后一个可见Item序号
|
||||
// 秋名山交警X 2019-12-28 23:52:52
|
||||
class _SaltedValueKey extends ValueKey<Key> {
|
||||
const _SaltedValueKey(Key key)
|
||||
: assert(key != null),
|
||||
super(key);
|
||||
}
|
||||
|
||||
class MyChildrenDelegate extends SliverChildBuilderDelegate {
|
||||
MyChildrenDelegate(
|
||||
Widget Function(BuildContext, int) builder, {
|
||||
int childCount,
|
||||
bool addAutomaticKeepAlive = true,
|
||||
bool addRepaintBoundaries = true,
|
||||
}) : super(builder,
|
||||
childCount: childCount,
|
||||
addAutomaticKeepAlives: addAutomaticKeepAlive,
|
||||
addRepaintBoundaries: addRepaintBoundaries);
|
||||
|
||||
// Return a Widget for the given Exception
|
||||
Widget _createErrorWidget(dynamic exception, StackTrace stackTrace) {
|
||||
final FlutterErrorDetails details = FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stackTrace,
|
||||
library: 'widgets library',
|
||||
context: ErrorDescription('building'),
|
||||
);
|
||||
FlutterError.reportError(details);
|
||||
return ErrorWidget.builder(details);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, int index) {
|
||||
assert(builder != null);
|
||||
if (index < 0 || (childCount != null && index >= childCount)) return null;
|
||||
Widget child;
|
||||
try {
|
||||
child = builder(context, index);
|
||||
} catch (exception, stackTrace) {
|
||||
child = _createErrorWidget(exception, stackTrace);
|
||||
}
|
||||
if (child == null) return null;
|
||||
final Key key = child.key != null ? _SaltedValueKey(child.key) : null;
|
||||
if (addRepaintBoundaries) child = RepaintBoundary(child: child);
|
||||
if (addSemanticIndexes) {
|
||||
final int semanticIndex = semanticIndexCallback(child, index);
|
||||
if (semanticIndex != null)
|
||||
child = IndexedSemantics(index: semanticIndex + semanticIndexOffset, child: child);
|
||||
}
|
||||
if (addAutomaticKeepAlives) child = AutomaticKeepAlive(child: child);
|
||||
return KeyedSubtree(child: child, key: key);
|
||||
}
|
||||
|
||||
@override
|
||||
void didFinishLayout(int _firstIndex, int _lastIndex) {
|
||||
// TODO: implement didFinishLayout
|
||||
super.didFinishLayout(_firstIndex, _lastIndex);
|
||||
}
|
||||
|
||||
///监听 在可见的列表中 显示的第一个位置和最后一个位置
|
||||
@override
|
||||
double estimateMaxScrollOffset(
|
||||
int _firstIndex, int _lastIndex, double _leadingScrollOffset, double _trailingScrollOffset) {
|
||||
//违章信息Listview滚动广播
|
||||
eventBus.fire(WzxxDataScrollEvent(_firstIndex, _lastIndex));
|
||||
|
||||
return super.estimateMaxScrollOffset(
|
||||
_firstIndex, _lastIndex, _leadingScrollOffset, _trailingScrollOffset);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user