MyDrawer.dart 11 KB

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