MyDrawer.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import 'package:deus_app/common/style/gsy_style.dart';
  2. import 'package:deus_app/common/utils/ConstantString.dart';
  3. import 'package:deus_app/model/drop_menu_item.dart';
  4. import 'package:flutter/material.dart';
  5. class MyDrawer extends StatefulWidget {
  6. final _CallBack callback;
  7. const MyDrawer({super.key, required this.callback});
  8. @override
  9. State createState() {
  10. return _myDrawer();
  11. }
  12. }
  13. DropMenuItem on = DropMenuItem('在线', 0);
  14. DropMenuItem off = DropMenuItem('离线', 1);
  15. DropMenuItem not = DropMenuItem('未激活', 2);
  16. List<DropMenuItem> sexMenuItems = [on, off, not];
  17. DropMenuItem enable = DropMenuItem('启用', 1);
  18. DropMenuItem disable = DropMenuItem('禁用', 0);
  19. List<DropMenuItem> sexMenuItems2 = [enable, disable];
  20. String? key,key2;
  21. typedef _CallBack = void Function(String device, String name,dynamic stase,dynamic isEnabled);
  22. class _myDrawer extends State<MyDrawer> {
  23. @override
  24. Widget build(BuildContext context) {
  25. return Drawer(
  26. child: MediaQuery.removePadding(
  27. context: context,
  28. //移除抽屉菜单顶部默认留白
  29. removeTop: true,
  30. child: Column(
  31. crossAxisAlignment: CrossAxisAlignment.start,
  32. children: <Widget>[
  33. Padding(
  34. padding: const EdgeInsets.only(top: 65.0, left: 10, right: 10),
  35. child: Row(children: [
  36. Expanded(
  37. flex: 2,
  38. child: Text(
  39. '设备名称',
  40. style: TextStyle(
  41. color: Colors.black,
  42. fontSize: GSYConstant.minTextSize,
  43. fontWeight: FontWeight.bold,
  44. ),
  45. ),
  46. ),
  47. Expanded(
  48. child: Container(
  49. height: 40,
  50. child: TextField(
  51. decoration: InputDecoration(
  52. border: OutlineInputBorder(),
  53. ),
  54. style: TextStyle(fontSize: 14),
  55. onChanged: (value) {
  56. setState(() {
  57. _device = value;
  58. });
  59. },
  60. ),
  61. ),
  62. flex: 7,
  63. ),
  64. ]),
  65. ),
  66. Padding(
  67. padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
  68. child: Row(children: [
  69. Expanded(
  70. flex: 2,
  71. child: Text(
  72. '展示名称',
  73. style: TextStyle(
  74. color: Colors.black,
  75. fontSize: GSYConstant.minTextSize,
  76. fontWeight: FontWeight.bold,
  77. ),
  78. ),
  79. ),
  80. Expanded(
  81. child: Container(
  82. height: 40,
  83. child: TextField(
  84. decoration: InputDecoration(border: OutlineInputBorder()),
  85. style: TextStyle(fontSize: 14),
  86. onChanged: (value) {
  87. setState(() {
  88. _username = value;
  89. });
  90. },
  91. ),
  92. ),
  93. flex: 7,
  94. ),
  95. ]),
  96. ),
  97. Padding(
  98. padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
  99. child: Row(children: [
  100. Expanded(
  101. flex: 2,
  102. child: Text(
  103. '设备状态',
  104. style: TextStyle(
  105. color: Colors.black,
  106. fontSize: GSYConstant.minTextSize,
  107. fontWeight: FontWeight.bold,
  108. ),
  109. ),
  110. ),
  111. Expanded(
  112. flex: 7,
  113. child: Container(
  114. child:
  115. dropDownButtonsColumn(sexMenuItems, '请选择设备状态'),
  116. ),
  117. ),
  118. ]),
  119. ),
  120. Padding(
  121. padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
  122. child: Row(children: [
  123. Expanded(
  124. flex: 2,
  125. child: Text(
  126. '启用状态',
  127. style: TextStyle(
  128. color: Colors.black,
  129. fontSize: GSYConstant.minTextSize,
  130. fontWeight: FontWeight.bold,
  131. ),
  132. ),
  133. ),
  134. Expanded(
  135. flex: 7,
  136. child: Container(
  137. child: dropDownButtons(
  138. sexMenuItems2, '请选择启用状态'),
  139. ),
  140. ),
  141. ]),
  142. ),
  143. SizedBox(
  144. height: 60,
  145. ),
  146. Row(
  147. crossAxisAlignment: CrossAxisAlignment.end,
  148. mainAxisAlignment: MainAxisAlignment.end,
  149. children: [
  150. TextButton(
  151. onPressed: () {
  152. Navigator.pop(context);
  153. },
  154. child: Text(ConstantString.cancel),
  155. style: ButtonStyle(
  156. backgroundColor:
  157. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  158. foregroundColor:
  159. MaterialStateProperty.all<Color>(Colors.white),
  160. minimumSize: MaterialStateProperty.all(Size(80, 40)),
  161. padding: MaterialStateProperty.all(EdgeInsets.zero)),
  162. ),
  163. SizedBox(
  164. width: 20,
  165. ),
  166. TextButton(
  167. onPressed: () {
  168. if (widget.callback != null) {
  169. widget.callback(_device,_username,satus,isEnabled);
  170. }
  171. },
  172. child: Text(ConstantString.query),
  173. style: ButtonStyle(
  174. backgroundColor:
  175. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  176. foregroundColor:
  177. MaterialStateProperty.all<Color>(Colors.white),
  178. minimumSize: MaterialStateProperty.all(Size(80, 40)),
  179. padding: MaterialStateProperty.all(EdgeInsets.zero)),
  180. ),
  181. SizedBox(
  182. width: 20,
  183. ),
  184. // new GSYFlexButton(
  185. // text: ConstantString.query,
  186. // color: Color(0xFF4875EC),
  187. // textColor: GSYColors.textWhite,
  188. // fontSize: 14,
  189. // onPress:()=>Navigator.pop(context),
  190. // ),
  191. ],
  192. )
  193. ],
  194. ),
  195. ),
  196. );
  197. }
  198. String _device = '', _username = '';
  199. dynamic satus = null, isEnabled =null;
  200. Widget dropDownButtonsColumn(
  201. List<DropMenuItem> list, String hint) {
  202. return Container(
  203. height: 40,
  204. //gives the height of the dropdown button
  205. width: MediaQuery.of(context).size.width,
  206. //gives the width of the dropdown button
  207. decoration: BoxDecoration(
  208. border: new Border.all(
  209. color: Colors.grey, //边框颜色
  210. width: 1.0, //边框粗细
  211. ),
  212. borderRadius:
  213. const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
  214. ),
  215. // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
  216. child: Theme(
  217. data: Theme.of(context).copyWith(
  218. // canvasColor: Colors.white, // background color for the dropdown items
  219. buttonTheme: ButtonTheme.of(context).copyWith(
  220. alignedDropdown:
  221. true, //If false (the default), then the dropdown's menu will be wider than its button.
  222. )),
  223. child: DropdownButtonHideUnderline(
  224. // to hide the default underline of the dropdown button
  225. child: DropdownButton<String>(
  226. iconEnabledColor: Color(0xFF595959),
  227. // icon color of the dropdown button
  228. items: list.map((dropMenuItem) {
  229. return DropdownMenuItem<String>(
  230. value: dropMenuItem.label,
  231. child: Text(
  232. dropMenuItem.label,
  233. style: TextStyle(fontSize: 15),
  234. ),
  235. );
  236. }).toList(),
  237. hint: Text(
  238. hint,
  239. style: TextStyle(fontSize: 15),
  240. ),
  241. // setting hint
  242. onChanged: (String? value) {
  243. key = value;
  244. setState(() {
  245. list.forEach((element) {
  246. if(value==element.label){
  247. satus= element.value; // saving the selected value
  248. }
  249. });
  250. });
  251. },
  252. value: key,
  253. // value: sexMenuItems.label, // displaying the selected value
  254. ),
  255. )),
  256. );
  257. }
  258. Widget dropDownButtons(
  259. List<DropMenuItem> list, String hint) {
  260. return Container(
  261. height: 40,
  262. //gives the height of the dropdown button
  263. width: MediaQuery.of(context).size.width,
  264. //gives the width of the dropdown button
  265. decoration: BoxDecoration(
  266. border: new Border.all(
  267. color: Colors.grey, //边框颜色
  268. width: 1.0, //边框粗细
  269. ),
  270. borderRadius:
  271. const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
  272. ),
  273. // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
  274. child: Theme(
  275. data: Theme.of(context).copyWith(
  276. // canvasColor: Colors.white, // background color for the dropdown items
  277. buttonTheme: ButtonTheme.of(context).copyWith(
  278. alignedDropdown:
  279. true, //If false (the default), then the dropdown's menu will be wider than its button.
  280. )),
  281. child: DropdownButtonHideUnderline(
  282. // to hide the default underline of the dropdown button
  283. child: DropdownButton<String>(
  284. iconEnabledColor: Color(0xFF595959),
  285. // icon color of the dropdown button
  286. items: list.map((dropMenuItem) {
  287. return DropdownMenuItem<String>(
  288. value: dropMenuItem.label,
  289. child: Text(
  290. dropMenuItem.label,
  291. style: TextStyle(fontSize: 15),
  292. ),
  293. );
  294. }).toList(),
  295. hint: Text(
  296. hint,
  297. style: TextStyle(fontSize: 15),
  298. ),
  299. // setting hint
  300. onChanged: (String? value) {
  301. key2=value;
  302. setState(() {
  303. list.forEach((element) {
  304. if(value==element.label){
  305. isEnabled= element.value; // saving the selected value
  306. }
  307. });
  308. });
  309. },
  310. value: key2,
  311. // value: sexMenuItems.label, // displaying the selected value
  312. ),
  313. )),
  314. );
  315. }
  316. }
  317. abstract class OnClickListener {
  318. void onConfirm();
  319. }