chooseWork.dart
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import 'package:flutter/material.dart';
import 'package:flutter_mes2/bean/PdaWeld.dart';
import 'package:flutter_mes2/https/http_utils.dart';
import 'package:flutter_mes2/utils/ToastUtil.dart';
import 'artifact.dart';
class chooseWork extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return _chooseWork();
}
}
class _chooseWork extends State<chooseWork>{
List<PdaWeld> mPdaList;
var value;
int index;
bool select = false;
List<DropdownMenuItem> getListData(){
List<DropdownMenuItem> items = new List();
List<PdaWeld> pdaWelds = mPdaList;
if(pdaWelds == null) {
return null;
}
for(PdaWeld pdaWeld in pdaWelds) {
DropdownMenuItem dropdownMenuItem1 = new DropdownMenuItem(
child: new Text(pdaWeld.name),
value: pdaWeld.id,
);
items.add(dropdownMenuItem1);
}
return items;
}
@override
void initState() {
// TODO: implement initState
Future.delayed( Duration.zero, () => setState(() {
_getPDAWeld();
}));
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text("选择工位"),
centerTitle: true, // 标题居中),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 40,
key: ValueKey('"process'),
width: 260,
margin: EdgeInsets.only(top: 10, bottom: 5),//根据需求自定义
padding: EdgeInsets.only(left: 10),//根据需求自定义
//设置边框,参数自定义
decoration: BoxDecoration(
border: Border.all(color: Colors.lightGreenAccent, width: 3),
//边框圆角设置
borderRadius: BorderRadius.all(Radius.circular(40.0)),
),
child: Center(
child:DropdownButton(
items: getListData(),
underline: Container(color: Colors.white),
hint:new Text('请选择工序'),//当没有默认值的时候可以设置的提示
value: value,//下拉菜单选择完之后显示给用户的值
onChanged: (T){//下拉菜单item点击之后的回调
setState(() {
value=T;
index = 0;
select = true;
for(PdaWeld pdaWeld in mPdaList) {
if(pdaWeld.id == value) {
return;
}
index++;
}
});
},
elevation: 24,//设置阴影的高度
style: new TextStyle(//设置文本框里面文字的样式
color: Colors.grey
),
isDense: true,//减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
iconSize: 30,//设置三角标icon的大小
),
),
),
Container(
height: 40,
margin: EdgeInsets.only(left:50, right: 50, top: 40),
width: double.infinity,
child: RaisedButton(
onPressed:() {
if(!select) {
ToastUtil.showText( "请先选择工位");
return;
}
Navigator.push(context, MaterialPageRoute(builder: (_) {
return new artifact(pdaWeld : mPdaList[index]);
}));
},
child: Text('确定',
style: TextStyle(
fontSize: 20,
color: Colors.white
),),
color: Colors.deepOrangeAccent,
textColor: Colors.white,
shape: StadiumBorder(),
),
),
],
),
),
);
}
Future _getPDAWeld() async {
HttpUtils.pdaWeld(context, {}, success: (result) {
var moreData = result['data'];
List<dynamic> json = moreData;
List<PdaWeld> pdaWelds = json.map((i) => PdaWeld.fromJson(i)).toList();
setState(() {
mPdaList = pdaWelds;
});
}, fail: (code) {
});
}
}