MyDrawer.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. Navigator.pop(context);
  171. }
  172. },
  173. child: Text(ConstantString.query),
  174. style: ButtonStyle(
  175. backgroundColor:
  176. MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
  177. foregroundColor:
  178. MaterialStateProperty.all<Color>(Colors.white),
  179. minimumSize: MaterialStateProperty.all(Size(80, 40)),
  180. padding: MaterialStateProperty.all(EdgeInsets.zero)),
  181. ),
  182. SizedBox(
  183. width: 20,
  184. ),
  185. // new GSYFlexButton(
  186. // text: ConstantString.query,
  187. // color: Color(0xFF4875EC),
  188. // textColor: GSYColors.textWhite,
  189. // fontSize: 14,
  190. // onPress:()=>Navigator.pop(context),
  191. // ),
  192. ],
  193. )
  194. ],
  195. ),
  196. ),
  197. );
  198. }
  199. String _device = '', _username = '';
  200. dynamic satus = null, isEnabled =null;
  201. Widget dropDownButtonsColumn(
  202. List<DropMenuItem> list, String hint) {
  203. return Container(
  204. height: 40,
  205. //gives the height of the dropdown button
  206. width: MediaQuery.of(context).size.width,
  207. //gives the width of the dropdown button
  208. decoration: BoxDecoration(
  209. border: new Border.all(
  210. color: Colors.grey, //边框颜色
  211. width: 1.0, //边框粗细
  212. ),
  213. borderRadius:
  214. const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
  215. ),
  216. // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
  217. child: Theme(
  218. data: Theme.of(context).copyWith(
  219. // canvasColor: Colors.white, // background color for the dropdown items
  220. buttonTheme: ButtonTheme.of(context).copyWith(
  221. alignedDropdown:
  222. true, //If false (the default), then the dropdown's menu will be wider than its button.
  223. )),
  224. child: DropdownButtonHideUnderline(
  225. // to hide the default underline of the dropdown button
  226. child: DropdownButton<String>(
  227. iconEnabledColor: Color(0xFF595959),
  228. // icon color of the dropdown button
  229. items: list.map((dropMenuItem) {
  230. return DropdownMenuItem<String>(
  231. value: dropMenuItem.label,
  232. child: Text(
  233. dropMenuItem.label,
  234. style: TextStyle(fontSize: 15),
  235. ),
  236. );
  237. }).toList(),
  238. hint: Text(
  239. hint,
  240. style: TextStyle(fontSize: 15),
  241. ),
  242. // setting hint
  243. onChanged: (String? value) {
  244. key = value;
  245. setState(() {
  246. list.forEach((element) {
  247. if(value==element.label){
  248. satus= element.value; // saving the selected value
  249. }
  250. });
  251. });
  252. },
  253. value: key,
  254. // value: sexMenuItems.label, // displaying the selected value
  255. ),
  256. )),
  257. );
  258. }
  259. Widget dropDownButtons(
  260. List<DropMenuItem> list, String hint) {
  261. return Container(
  262. height: 40,
  263. //gives the height of the dropdown button
  264. width: MediaQuery.of(context).size.width,
  265. //gives the width of the dropdown button
  266. decoration: BoxDecoration(
  267. border: new Border.all(
  268. color: Colors.grey, //边框颜色
  269. width: 1.0, //边框粗细
  270. ),
  271. borderRadius:
  272. const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
  273. ),
  274. // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
  275. child: Theme(
  276. data: Theme.of(context).copyWith(
  277. // canvasColor: Colors.white, // background color for the dropdown items
  278. buttonTheme: ButtonTheme.of(context).copyWith(
  279. alignedDropdown:
  280. true, //If false (the default), then the dropdown's menu will be wider than its button.
  281. )),
  282. child: DropdownButtonHideUnderline(
  283. // to hide the default underline of the dropdown button
  284. child: DropdownButton<String>(
  285. iconEnabledColor: Color(0xFF595959),
  286. // icon color of the dropdown button
  287. items: list.map((dropMenuItem) {
  288. return DropdownMenuItem<String>(
  289. value: dropMenuItem.label,
  290. child: Text(
  291. dropMenuItem.label,
  292. style: TextStyle(fontSize: 15),
  293. ),
  294. );
  295. }).toList(),
  296. hint: Text(
  297. hint,
  298. style: TextStyle(fontSize: 15),
  299. ),
  300. // setting hint
  301. onChanged: (String? value) {
  302. key2=value;
  303. setState(() {
  304. list.forEach((element) {
  305. if(value==element.label){
  306. isEnabled= element.value; // saving the selected value
  307. }
  308. });
  309. });
  310. },
  311. value: key2,
  312. // value: sexMenuItems.label, // displaying the selected value
  313. ),
  314. )),
  315. );
  316. }
  317. }
  318. abstract class OnClickListener {
  319. void onConfirm();
  320. }