hyzp_ybqx-Commit001:代码刚转换好,编译通过
This commit is contained in:
@@ -0,0 +1,595 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/screen_util.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:hyzp_ybqx/components/commonFun.dart';
|
||||
import 'package:hyzp_ybqx/components/customDialogF.dart';
|
||||
import 'package:hyzp_ybqx/services/EventBus.dart';
|
||||
import 'package:hyzp_ybqx/widget/customRadioWidget.dart';
|
||||
import '../../../components/doJSON.dart';
|
||||
import '../../../components/dioFun.dart';
|
||||
import '../../../components/hyxx_data_handle.dart';
|
||||
import 'dart:io';
|
||||
import '../../../components/customDialogH.dart';
|
||||
import '../../../components/customDialogJ.dart';
|
||||
|
||||
class SbbjContent extends StatefulWidget {
|
||||
//SbbjContent({Key key, this.title, this.mapData}) : super(key: key);
|
||||
SbbjContent({
|
||||
@required this.title,
|
||||
@required this.index,
|
||||
@required this.hyshlx,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
String title;
|
||||
int index = -1;
|
||||
String hyshlx;
|
||||
|
||||
_SbbjPageState createState() => _SbbjPageState();
|
||||
}
|
||||
|
||||
class _SbbjPageState extends State<SbbjContent> {
|
||||
Map _mapGetSbbjGetDataText = {
|
||||
"id": "主键ID",
|
||||
"bjlx": "设备类型",
|
||||
"content": "报警内容",
|
||||
"dwip": "点位IP",
|
||||
"sbip": "设备IP",
|
||||
"addtime": "添加时间",
|
||||
"workflow": "处理状态"
|
||||
};
|
||||
|
||||
Map _mapGetSbbjGetData = {
|
||||
"id": 1177,
|
||||
"bjlx": "风扇",
|
||||
"content": "串口COM1获取风扇异常数据",
|
||||
"dwip": "172.16.3.1",
|
||||
"sbip": "192.168.1.10",
|
||||
"addtime": "2021-02-07 23:56:45",
|
||||
"workflow": 999
|
||||
};
|
||||
|
||||
List<TextEditingController> _listController = [];
|
||||
int listLen = 0;
|
||||
String nums = '';
|
||||
int _selectedRadio = 0;
|
||||
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
listLen = listSbbjGetList2.length;
|
||||
getListFlields();
|
||||
}
|
||||
|
||||
//监听登录页面销毁的事件
|
||||
dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
getListFlields() async {
|
||||
//获取指定id的sbbj记录数据返回 _mapGetSbbjGetData。由于 sbbj 信息需要进行查核处理,所以要重新读取最新的记录数据
|
||||
_mapGetSbbjGetData =
|
||||
await getLedXsxxGetData(id: listSbbjGetList2[widget.index]['id'], theSbgllx: widget.hyshlx);
|
||||
print('_mapGetSbbjGetData = ${_mapGetSbbjGetData}');
|
||||
|
||||
//_mapGetSbbjGetData = listSbbjGetList2[widget.index];
|
||||
_listController = List.generate(_mapGetSbbjGetData.length, (index) {
|
||||
String key = _mapGetSbbjGetData.keys.elementAt(index);
|
||||
|
||||
String strContent = _mapGetSbbjGetData[key].toString();
|
||||
//时间戳转换
|
||||
if (strContent.isNotEmpty && 'addtime' == key) {
|
||||
strContent = getDate(strContent);
|
||||
}
|
||||
//workflow转换
|
||||
if (strContent.isNotEmpty && 'workflow' == key) {
|
||||
strContent = strContent == '999' ? '已处理' : '待处理';
|
||||
}
|
||||
var controller = TextEditingController(text: strContent);
|
||||
|
||||
controller.selection = TextSelection.fromPosition(
|
||||
TextPosition(affinity: TextAffinity.downstream, offset: '${controller.text}'.length),
|
||||
);
|
||||
return controller;
|
||||
});
|
||||
getPreBtn_NextBtn();
|
||||
nums = '${(widget.index + 1).toString()} / $listLen';
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget getTrail(String key, int index, double widthTrail) {
|
||||
if (0 == _listController.length) {
|
||||
return Container(width: widthTrail);
|
||||
}
|
||||
|
||||
//print('key = $key');
|
||||
if ('avatar' == key) {
|
||||
imagePath = _listController[index].text;
|
||||
return getAvatar(width: widthTrail);
|
||||
} else {
|
||||
return Container(
|
||||
alignment: Alignment(-1, 0),
|
||||
//widthTrail = 400报错,360刚能显示,300换行,260
|
||||
width: widthTrail,
|
||||
//解决信息显示不全问题
|
||||
child: Text(_listController[index].text,
|
||||
style: TextStyle(fontSize: 16), textAlign: TextAlign.left),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget getTrail0(String key, int index, double widthTrail) {
|
||||
if (0 == _listController.length) {
|
||||
return Container(width: widthTrail);
|
||||
}
|
||||
|
||||
//print('key = $key');
|
||||
if ('avatar' == key) {
|
||||
imagePath = _listController[index].text;
|
||||
return getAvatar(width: widthTrail);
|
||||
} else {
|
||||
return Container(
|
||||
alignment: Alignment(1, 0),
|
||||
//widthTrail = 400报错,360刚能显示,300换行,260
|
||||
width: widthTrail,
|
||||
child: TextField(
|
||||
//textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
//hintText: '請輸入字段信息',
|
||||
border: InputBorder.none, //TextField去掉下划线
|
||||
contentPadding: EdgeInsets.only(right: 0),
|
||||
),
|
||||
controller: _listController[index],
|
||||
enabled: 'content' == key ? true : false,
|
||||
//解决报警信息显示不全问题,但软键盘会弹出,很难控制键盘弹出问题
|
||||
//利用控制器初始化文本
|
||||
onChanged: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> doContacts() async {
|
||||
bFlash = false;
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return customDialogH(
|
||||
title: "请选择头像修改操作",
|
||||
content: "头像修改",
|
||||
index: 0,
|
||||
);
|
||||
},
|
||||
).then((value) {
|
||||
imagePath = value;
|
||||
print('Page2_Contacts bFlash = $bFlash');
|
||||
if (imagePath.isNotEmpty) {
|
||||
_image = Image.file(File(imagePath), fit: BoxFit.cover);
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Image.file(this._image);
|
||||
String imagePath = '';
|
||||
Image _image;
|
||||
|
||||
Widget getAvatar({double width = 260.0}) {
|
||||
if (imagePath.isEmpty) {
|
||||
_image = Image.asset('assets/images/user.png', fit: BoxFit.cover);
|
||||
} else {
|
||||
String head = imagePath.substring(0, 4).trim().toLowerCase();
|
||||
if ('http' == head) {
|
||||
_image = Image.network(imagePath, fit: BoxFit.cover);
|
||||
}
|
||||
}
|
||||
return Container(
|
||||
alignment: Alignment(-1, 0),
|
||||
width: width,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
doContacts();
|
||||
},
|
||||
child: Container(
|
||||
width: 40,
|
||||
child: _image,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//添加、修改、删除联系人对话框
|
||||
doContacts2(String key, int index) async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CustomDialogJ(
|
||||
theKey: key,
|
||||
index: index,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static onNullFun() {}
|
||||
|
||||
Widget _getListTile(String key, int index, double widthTrail,
|
||||
{onTapFun = onNullFun, onLongPressFun = onNullFun, size = 16.0}) {
|
||||
//print('key = $key, index = $index');
|
||||
return ListTile(
|
||||
//leading: new Icon(Icons.phone),
|
||||
title: Text((index + 1).toString() + ". " + '${_mapGetSbbjGetDataText[key]} :',
|
||||
style: TextStyle(fontSize: 16)),
|
||||
trailing: getTrail(key, index, widthTrail),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
|
||||
enabled: true,
|
||||
onTap: () async {
|
||||
// print('第 $index 项被点击了');
|
||||
// await doContacts2(key, index);
|
||||
// if ('avatar' == key) {
|
||||
// print('选择图片或拍照');
|
||||
// await doContacts();
|
||||
// }
|
||||
},
|
||||
onLongPress: () {},
|
||||
);
|
||||
}
|
||||
|
||||
TextEditingController _controller = TextEditingController.fromValue(TextEditingValue(
|
||||
text: '已做简单处理。低级故障,不影响系统运行',
|
||||
// 保持光标在最后
|
||||
selection: TextSelection.fromPosition(
|
||||
TextPosition(affinity: TextAffinity.downstream, offset: '已处理'.length))));
|
||||
|
||||
//7、得到核查处理意见组件
|
||||
Widget getClyj(int index, bool _bCheck) {
|
||||
if (_bCheck) {
|
||||
_controller.text = '';
|
||||
} else {
|
||||
_controller.text = (0 == _selectedRadio ? '已做简单处理。低级故障,不影响系统运行' : '已核查,属于误报');
|
||||
}
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: double.infinity, //宽度尽可能大
|
||||
//minHeight: _listTileHeight, //最小高度
|
||||
maxHeight: _heigth, //最大高度
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
Text('处理意见:',
|
||||
style: TextStyle(
|
||||
fontSize: _fontSize,
|
||||
color: _bCheck
|
||||
? Colors.grey
|
||||
: 0 == _selectedRadio
|
||||
? Colors.red
|
||||
: Colors.green)),
|
||||
Container(
|
||||
alignment: Alignment(-1, 0),
|
||||
height: _heigth,
|
||||
//widthTrail = 400报错,360刚能显示,300换行,260
|
||||
width: 240,
|
||||
child: TextField(
|
||||
//textAlign: TextAlign.right,
|
||||
//style: TextStyle(fontSize: _fontSize, color: cpysList[getIndexOfCpysList(colorText: topTabs_map['cpysText_List'][i])].cpysFont),
|
||||
//style: TextStyle(fontSize: _fontSize, color: cpysList[getIndexOfCpysList(colorText: myCpys)].cpysFont),
|
||||
style: TextStyle(fontSize: _fontSize),
|
||||
textAlign: TextAlign.left,
|
||||
decoration: InputDecoration(
|
||||
hintText: _bCheck ? '' : '請輸入审核意见',
|
||||
//border: InputBorder.none, //TextField去掉下划线
|
||||
//contentPadding: EdgeInsets.only(right: 0),
|
||||
//contentPadding: EdgeInsets.symmetric(vertical: _textFieldHeight),
|
||||
contentPadding: EdgeInsets.only(left: 4, right: 4), //这行代码是关键,设置这个之后,居中
|
||||
//contentPadding: EdgeInsets.zero, //这行代码是关键,设置这个之后,居中
|
||||
border: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey[600]),
|
||||
//borderSide: BorderSide.none,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
controller: _controller,
|
||||
maxLines: 1,
|
||||
minLines: 1,
|
||||
//maxLengthEnforced: false,
|
||||
//maxLength: 10,
|
||||
enabled: !_bCheck,
|
||||
//利用控制器初始化文本
|
||||
onChanged: (value) {
|
||||
_controller.text = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double _heigth = 30;
|
||||
double _fontSize = 16;
|
||||
double _marginLeft = 15;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool bCheck = _mapGetSbbjGetData['workflow'] == 999; //已处理
|
||||
return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text("设备报警信息详情($nums)"),
|
||||
// centerTitle: true,
|
||||
// ),
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
|
||||
// 设置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.center,
|
||||
children: [
|
||||
getIconAndTextButton(
|
||||
iconColor: Colors.white,
|
||||
iconData: Icons.chevron_left_outlined,
|
||||
onPress: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Text("设备报警信息详情($nums)",
|
||||
style: TextStyle(color: Colors.white, fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
SizedBox(width: 50),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
//https://www.it1352.com/2028416.html
|
||||
//用Map而不是List的Flutter ListView.builder(Flutter listview with Map instead of List)
|
||||
//使用ListView.separated设置分割线ListView.separated(
|
||||
//child: ListView.separated( //这种方式不能设置每项高度,每页只能有7项
|
||||
child: ListView.builder(
|
||||
//这种方式可以通过itemExtent设置每项高度,每页可以有9项
|
||||
//separatorBuilder: (BuildContext context, int index) => index %2 ==0? Divider(color: Colors.green) : Divider(color: Colors.red),//index为偶数,创建绿色分割线;index为奇数,则创建红色分割线
|
||||
//separatorBuilder: (BuildContext context, int index) => Divider(),
|
||||
//itemExtent: 57.0, //列表项高度。56越界、57刚好。还是自动计算最好
|
||||
itemCount: _mapGetSbbjGetData.length,
|
||||
itemBuilder: (BuildContext context, index) {
|
||||
String key = _mapGetSbbjGetData.keys.elementAt(index);
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
_getListTile(key, index, 200.0),
|
||||
Divider(
|
||||
height: 1.0,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
//7、得到核查处理意见组件
|
||||
Divider(height: 1.0, color: Colors.blue),
|
||||
SizedBox(height: 15),
|
||||
getClyj(widget.index, bCheck),
|
||||
SizedBox(height: 10),
|
||||
//8、处理结果
|
||||
Container(
|
||||
height: _heigth,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(width: _marginLeft),
|
||||
Text('处理结果:',
|
||||
style: TextStyle(
|
||||
fontSize: _fontSize,
|
||||
color: bCheck
|
||||
? Colors.grey
|
||||
: 0 == _selectedRadio
|
||||
? Colors.red
|
||||
: Colors.green)),
|
||||
CustomRadioWidget(
|
||||
value: 0,
|
||||
title: "已处理",
|
||||
fontSize: _fontSize,
|
||||
width: 120,
|
||||
groupValue: _selectedRadio,
|
||||
onChanged: bCheck
|
||||
? null
|
||||
: (int value) {
|
||||
_selectedRadio = value;
|
||||
//黑烟初审数据审核Radio选项改变广播
|
||||
//eventBus.fire(HycsDataAuditRadioEvent('黑烟初审数据审核Radio选项已改变', _selectedRadio));
|
||||
_controller.text = '已做简单处理。低级故障,不影响系统运行';
|
||||
setState(() {});
|
||||
print('selectedRadio = ${_selectedRadio.toString()}');
|
||||
},
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
CustomRadioWidget(
|
||||
value: 1,
|
||||
title: "误报",
|
||||
fontSize: _fontSize,
|
||||
width: 100,
|
||||
groupValue: _selectedRadio,
|
||||
onChanged: bCheck
|
||||
? null
|
||||
: (int value) {
|
||||
_selectedRadio = value;
|
||||
//黑烟初审数据审核Radio选项改变广播
|
||||
//eventBus.fire(HycsDataAuditRadioEvent('黑烟初审数据审核Radio选项已改变', _selectedRadio));
|
||||
_controller.text = '已核查,属于误报';
|
||||
setState(() {});
|
||||
print('selectedRadio = ${_selectedRadio.toString()}');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Divider(height: 1.0, color: Colors.blue),
|
||||
SizedBox(height: 15),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
getBtnSizeX(
|
||||
text: "处理",
|
||||
onPressedFun: bCheck
|
||||
? null
|
||||
: () async {
|
||||
int ret = -1;
|
||||
print('等待处理确认');
|
||||
await Navigator.of(context)
|
||||
.push(
|
||||
PageRouteBuilder(
|
||||
opaque: false,
|
||||
pageBuilder: (context, animation, secondaryAnimation) =>
|
||||
CustomDialogF(title: '处理确认', content: '是否进行设备报警信息核查处理?'),
|
||||
),
|
||||
)
|
||||
.then((value) async {
|
||||
print('value = $value');
|
||||
if (value) {
|
||||
print('用户已确认,开始处理报警信息核查处理!');
|
||||
// sbglContentFirstAudit 整型返回值:更新的结果,1表示成功,0表示无更新,false表示失败
|
||||
ret = await sbglContentAudit(
|
||||
sbgllx: widget.hyshlx,
|
||||
sbglID: _mapGetSbbjGetData['id'],
|
||||
shuoming: _controller.text,
|
||||
title: 0 == _selectedRadio ? '已处理' : '误报',
|
||||
);
|
||||
|
||||
if (1 == ret) {
|
||||
eventBus.fire(SbglDataUpdateEvent(
|
||||
'${mapHyshlx[widget.hyshlx]['text']}数据已更新'));
|
||||
print('${mapHyshlx[widget.hyshlx]['text']}结果已成功上传服务器。');
|
||||
}
|
||||
} else {
|
||||
print('用户取消了报警信息核查处理');
|
||||
}
|
||||
});
|
||||
Navigator.pop(context, ret);
|
||||
}),
|
||||
//getBtnSizeX(text: "删除", onPressedFun: () async {}),
|
||||
preBtn,
|
||||
nextBtn,
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//解决第一次进入报错问题。因为getPreBtn_NextBtn()还未执行,preBtn和nextBtn为空
|
||||
Widget preBtn = Container(
|
||||
color: Colors.white12, //onPressedFun为null时无效
|
||||
width: 70.0,
|
||||
height: 35.0,
|
||||
child: RaisedButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
textColor: Colors.black,
|
||||
child: Text('上一条'),
|
||||
onPressed: null,
|
||||
),
|
||||
);
|
||||
|
||||
Widget nextBtn = Container(
|
||||
color: Colors.white12, //onPressedFun为null时无效
|
||||
width: 70.0,
|
||||
height: 35.0,
|
||||
child: RaisedButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
textColor: Colors.black,
|
||||
child: Text('下一条'),
|
||||
onPressed: null,
|
||||
),
|
||||
);
|
||||
|
||||
getPreBtn_NextBtn() {
|
||||
preBtn = getBtnSizeX(
|
||||
text: "上一条",
|
||||
onPressedFun: null,
|
||||
);
|
||||
nextBtn = getBtnSizeX(
|
||||
text: "下一条",
|
||||
onPressedFun: null,
|
||||
);
|
||||
|
||||
if (widget.index > 0 && listLen > 0) {
|
||||
preBtn = getBtnSizeX(
|
||||
text: "上一条",
|
||||
onPressedFun: () async {
|
||||
if (widget.index > 0) {
|
||||
widget.index--;
|
||||
getListFlields();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.index < (listLen - 1) && listLen > 0) {
|
||||
nextBtn = getBtnSizeX(
|
||||
text: "下一条",
|
||||
onPressedFun: () async {
|
||||
if (widget.index < listLen - 1) {
|
||||
widget.index++;
|
||||
getListFlields();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,799 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
import 'sbbj_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';
|
||||
|
||||
//sbbj是本项目中“设备报警”的统一缩写
|
||||
class SbbjGetList extends StatefulWidget {
|
||||
//hyshlx为黑烟审核类型,处理sbbj信息。mapHyshlx[hyshlx]获取为各种类型的设置数据
|
||||
SbbjGetList({this.hyshlx = 'sbbj', Key key}) : super(key: key);
|
||||
String hyshlx;
|
||||
|
||||
_SbbjPageState createState() => _SbbjPageState();
|
||||
}
|
||||
|
||||
class _SbbjPageState extends State<SbbjGetList> {
|
||||
//try_setState(); //避免异常报错
|
||||
try_setState() {
|
||||
try {
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
print('setState(() {})异常:${e}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose(); //销毁控制器
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
hyshlx = widget.hyshlx;
|
||||
iPage = 0;
|
||||
listSbbjGetList2.clear();
|
||||
|
||||
///从接口 mapHyshlx[hyshlx]['api'] 获取第 iPage 页的列表数据,返回 list
|
||||
getPageList().then((value) {
|
||||
listSbbjGetList2 = value;
|
||||
//按照用户选择的_selectedValue、_descending对listSbbjGetList2进行排序,并延时更新
|
||||
_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<SbglDataUpdateEvent>().listen((event) async {
|
||||
print(event.str);
|
||||
iPage = 0;
|
||||
listSbbjGetList2.clear();
|
||||
|
||||
///从接口 mapHyshlx[hyshlx]['api'] 获取第 iPage 页的列表数据,返回 list
|
||||
getPageList().then((value) {
|
||||
listSbbjGetList2 = value;
|
||||
//按照用户选择的_selectedValue、_descending对listSbbjGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
firstIndex = 0;
|
||||
lastIndex = 7;
|
||||
});
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
// List listSbbjGetList2 = [
|
||||
// {
|
||||
// "id": 1196,
|
||||
// "bjlx": "风扇",
|
||||
// "content": "串口COM1获取风扇异常数据",
|
||||
// "dwip": "172.16.3.12",
|
||||
// "sbip": "192.168.1.10",
|
||||
// "addtime": "2021-02-16 09:50:30",
|
||||
// "workflow": 999
|
||||
// },
|
||||
// ];
|
||||
|
||||
Widget _getListTile(BuildContext context, indexRecord) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
//leading: new Icon(Icons.phone),
|
||||
title: Text(
|
||||
"${(indexRecord + 1).toString()}. " +
|
||||
getDate(listSbbjGetList2[indexRecord]['addtime']) +
|
||||
',',
|
||||
style: TextStyle(fontSize: 14)),
|
||||
subtitle: Text(
|
||||
getDwmc(listSbbjGetList2[indexRecord]['dwip']) +
|
||||
',' +
|
||||
(listSbbjGetList2[indexRecord]['workflow'] == 999 ? '已处理' : '待处理'),
|
||||
style: TextStyle(fontSize: 14)),
|
||||
trailing: Container(
|
||||
width: 160,
|
||||
child: Text(
|
||||
'${listSbbjGetList2[indexRecord]['bjlx']}, 报警:${listSbbjGetList2[indexRecord]['content']}' +
|
||||
', 设备IP:${listSbbjGetList2[indexRecord]['sbip']}' +
|
||||
'ID:${listSbbjGetList2[indexRecord]['id'].toString()}',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
//textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
|
||||
enabled: true,
|
||||
onTap: () async {
|
||||
int ret = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SbbjContent(
|
||||
title: '设备报警信息',
|
||||
index: indexRecord,
|
||||
hyshlx: widget.hyshlx,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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, color: Colors.white),
|
||||
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.hyshlx == 'fhycx' ? TextStyle(fontSize: 14) : 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 = listSbbjGetList2.length;
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// List list = await getPageList();
|
||||
// if (list.length > 0) {
|
||||
// listSbbjGetList2.addAll(list); //加载累加
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// Future.delayed(const Duration(milliseconds: 1000), () async {
|
||||
// if (listSbbjGetList2.length > oldItems) {
|
||||
// eventBus.fire(WzxxDataAuditEvent('${mapHyshlx[hyshlx]['text']}数据已更新'));
|
||||
// Fluttertoast.showToast(
|
||||
// msg: '新增 ${listSbbjGetList2.length - oldItems} 条数据下载完成!',
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.CENTER,
|
||||
// );
|
||||
//
|
||||
// //按照用户选择的_selectedValue、_descending对listSbbjGetList2进行排序,并延时更新
|
||||
// _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 < listSbbjGetList2.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 = listSbbjGetList2.length - itemOnPage - 2;
|
||||
// lastIndex = listSbbjGetList2.length;
|
||||
// isLoading = false;
|
||||
// try_setState();
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// : null,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // here the desired height
|
||||
child: AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
centerTitle: true,
|
||||
//leading: Text(''),
|
||||
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),
|
||||
// ),
|
||||
),
|
||||
),
|
||||
//1、第1行组件,工具按钮
|
||||
title: Padding(
|
||||
padding: EdgeInsets.only(left: 0, right: 0),
|
||||
child: Row(
|
||||
//mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
//1.1、返回按钮
|
||||
getIconAndTextButton(
|
||||
iconColor: Colors.white,
|
||||
iconData: Icons.chevron_left_outlined,
|
||||
onPress: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
//1.2、title 显示控制
|
||||
Expanded(
|
||||
child: Text("${mapHyshlx[hyshlx]['text']}",
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: Colors.white, fontSize: 20)),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
],
|
||||
),
|
||||
),
|
||||
//1.3、尾部工具按钮组
|
||||
actions: <Widget>[
|
||||
//getDropdownButton(),
|
||||
getIconButton(
|
||||
iconData: Icons.cloud_download,
|
||||
onPressed: !isLoading
|
||||
? () async {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
//print("I Pressed the Iconbutton");
|
||||
int oldItems = listSbbjGetList2.length;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
List list = await getPageList();
|
||||
if (list.length > 0) {
|
||||
listSbbjGetList2.addAll(list); //加载累加
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 1000), () async {
|
||||
if (listSbbjGetList2.length > oldItems) {
|
||||
eventBus.fire(WzxxDataAuditEvent('${mapHyshlx[hyshlx]['text']}数据已更新'));
|
||||
Fluttertoast.showToast(
|
||||
msg: '新增 ${listSbbjGetList2.length - oldItems} 条数据下载完成!',
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
);
|
||||
|
||||
//按照用户选择的_selectedValue、_descending对listSbbjGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
//_controller.jumpTo(1); // _controller.position 能够有效刷新,人眼可察觉的滚动
|
||||
_controller.jumpTo(0.001); // _controller.position 完美解决有效刷新,而且人眼不可见察觉滚动
|
||||
//第二次跳转必须延时,否则 _controller.position 不能有效刷新
|
||||
Future.delayed(Duration(milliseconds: 500), () {
|
||||
_controller.jumpTo(_controller.position.minScrollExtent);
|
||||
});
|
||||
}
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
});
|
||||
}
|
||||
: null,
|
||||
),
|
||||
SizedBox(width: ScreenUtil().setWidth(32)),
|
||||
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,
|
||||
),
|
||||
SizedBox(width: ScreenUtil().setWidth(32)),
|
||||
getIconButton(
|
||||
iconData: Icons.vertical_align_bottom_outlined,
|
||||
onPressed: (!isLoading && (lastIndex < listSbbjGetList2.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 = listSbbjGetList2.length - itemOnPage - 2;
|
||||
lastIndex = listSbbjGetList2.length;
|
||||
isLoading = false;
|
||||
try_setState();
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
SizedBox(width: ScreenUtil().setWidth(32)),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Column(children: [
|
||||
//2、第2行排序按钮
|
||||
Container(
|
||||
height: ScreenUtil().setHeight(142),
|
||||
decoration: new BoxDecoration(border: new Border.all(color: Colors.red)),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(width: ScreenUtil().setWidth(50)),
|
||||
Text('排序', style: TextStyle(fontSize: 18)),
|
||||
Expanded(child: SizedBox.shrink()),
|
||||
getDropdownButton(),
|
||||
SizedBox(width: ScreenUtil().setWidth(20)),
|
||||
],
|
||||
),
|
||||
),
|
||||
(0 == listSbbjGetList2.length)
|
||||
? getMoreWidget(color: Colors.black38)
|
||||
: Expanded(
|
||||
child: EasyRefresh(
|
||||
child: ListView.custom(
|
||||
//itemExtent: 75.0, //列表项高度
|
||||
controller: _controller,
|
||||
cacheExtent: 1.0, // 只有设置了1.0 才能够准确的标记 position 位置
|
||||
childrenDelegate: MyChildrenDelegate(
|
||||
_getListTile,
|
||||
childCount: listSbbjGetList2.length,
|
||||
),
|
||||
),
|
||||
onRefresh: () async {
|
||||
// await Future.delayed(const Duration(seconds: 1), () async {
|
||||
// iPage = 0;
|
||||
// //await getWzxxGetList();
|
||||
// listSbbjGetList2 = 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) {
|
||||
listSbbjGetList2.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 = '添加时间';
|
||||
bool _descending = true; //默认生效排列
|
||||
|
||||
Widget _getImage(String _image) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(),
|
||||
height: ScreenUtil().setWidth(48),
|
||||
width: ScreenUtil().setWidth(48),
|
||||
//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对listSbbjGetList2进行排序,并延时更新
|
||||
Future _listSort({bool bShowToast = false}) {
|
||||
if (!isLoading && listSbbjGetList2.length > 0) {
|
||||
isLoading = true;
|
||||
try_setState();
|
||||
|
||||
switch (_selectedValue) {
|
||||
default:
|
||||
if (_descending) {
|
||||
//按_selectedValue排序,降序
|
||||
listSbbjGetList2.sort((a, b) =>
|
||||
(b[mapWzxxDataText[_selectedValue]]).compareTo(a[mapWzxxDataText[_selectedValue]]));
|
||||
} else {
|
||||
//按_selectedValue排序,升序
|
||||
listSbbjGetList2.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 Padding(
|
||||
padding: EdgeInsets.only(bottom: ScreenUtil().setHeight(3)),
|
||||
child: Row(
|
||||
//crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment(0, 0),
|
||||
padding: EdgeInsets.only(top: ScreenUtil().setHeight(10)),
|
||||
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: ScreenUtil().setWidth(10),
|
||||
),
|
||||
Container(
|
||||
//alignment: Alignment(0, -1),
|
||||
child: Text(item,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: isLoading
|
||||
? Theme.of(context).disabledColor
|
||||
: item == _selectedValue
|
||||
? Colors.blue
|
||||
: null)),
|
||||
// style: isLoading
|
||||
// ? TextStyle(color: Theme.of(context).disabledColor)
|
||||
// : (item == _selectedValue ? TextStyle(color: Colors.blue) : null)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// List listSbbjGetList2 = [
|
||||
// {
|
||||
// "id": 1196,
|
||||
// "bjlx": "风扇",
|
||||
// "content": "串口COM1获取风扇异常数据",
|
||||
// "dwip": "172.16.3.12",
|
||||
// "sbip": "192.168.1.10",
|
||||
// "addtime": "2021-02-16 09:50:30",
|
||||
// "workflow": 999
|
||||
// },
|
||||
// ];
|
||||
|
||||
Widget getDropdownButton() {
|
||||
//DropdownMenuItem项目文本list
|
||||
List<String> itemList = [
|
||||
'添加时间',
|
||||
'主键ID',
|
||||
'设备类型',
|
||||
'报警内容',
|
||||
'点位IP',
|
||||
'设备IP',
|
||||
'处理状态',
|
||||
];
|
||||
|
||||
//添加按'推送状态'排序
|
||||
if (hyshlx != 'sbbj') {
|
||||
// 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: 0, bottom: 0),
|
||||
child: Container(
|
||||
alignment: Alignment(0, 0),
|
||||
width: 135,
|
||||
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>(
|
||||
iconSize: ScreenUtil().setHeight(100),
|
||||
//itemHeight: ScreenUtil().setHeight(372),
|
||||
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');
|
||||
|
||||
//按抓拍次数排序,降序
|
||||
// listSbbjGetList2.sort((a, b) => (b["yjxx_id"].split(',').length.toString())
|
||||
// .compareTo(a["yjxx_id"].split(',').length.toString()));
|
||||
|
||||
//按照用户选择的_selectedValue、_descending对listSbbjGetList2进行排序,并延时更新
|
||||
_listSort();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//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