| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- import 'package:deus_app/common/style/gsy_style.dart';
- import 'package:deus_app/common/utils/ConstantString.dart';
- import 'package:deus_app/model/drop_menu_item.dart';
- import 'package:flutter/material.dart';
- class MyDrawer extends StatefulWidget {
- final _CallBack callback;
- const MyDrawer({super.key, required this.callback});
- @override
- State createState() {
- return _myDrawer();
- }
- }
- DropMenuItem on = DropMenuItem('在线', 0);
- DropMenuItem off = DropMenuItem('离线', 1);
- DropMenuItem not = DropMenuItem('未激活', 2);
- List<DropMenuItem> sexMenuItems = [on, off, not];
- DropMenuItem enable = DropMenuItem('启用', 1);
- DropMenuItem disable = DropMenuItem('禁用', 0);
- List<DropMenuItem> sexMenuItems2 = [enable, disable];
- String? key,key2;
- typedef _CallBack = void Function(String device, String name,dynamic stase,dynamic isEnabled);
- class _myDrawer extends State<MyDrawer> {
- @override
- Widget build(BuildContext context) {
- return Drawer(
- child: MediaQuery.removePadding(
- context: context,
- //移除抽屉菜单顶部默认留白
- removeTop: true,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.only(top: 65.0, left: 10, right: 10),
- child: Row(children: [
- Expanded(
- flex: 2,
- child: Text(
- '设备名称',
- style: TextStyle(
- color: Colors.black,
- fontSize: GSYConstant.minTextSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- child: Container(
- height: 40,
- child: TextField(
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- style: TextStyle(fontSize: 14),
- onChanged: (value) {
- setState(() {
- _device = value;
- });
- },
- ),
- ),
- flex: 7,
- ),
- ]),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
- child: Row(children: [
- Expanded(
- flex: 2,
- child: Text(
- '展示名称',
- style: TextStyle(
- color: Colors.black,
- fontSize: GSYConstant.minTextSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- child: Container(
- height: 40,
- child: TextField(
- decoration: InputDecoration(border: OutlineInputBorder()),
- style: TextStyle(fontSize: 14),
- onChanged: (value) {
- setState(() {
- _username = value;
- });
- },
- ),
- ),
- flex: 7,
- ),
- ]),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
- child: Row(children: [
- Expanded(
- flex: 2,
- child: Text(
- '设备状态',
- style: TextStyle(
- color: Colors.black,
- fontSize: GSYConstant.minTextSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- flex: 7,
- child: Container(
- child:
- dropDownButtonsColumn(sexMenuItems, '请选择设备状态'),
- ),
- ),
- ]),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 20.0, left: 10, right: 10),
- child: Row(children: [
- Expanded(
- flex: 2,
- child: Text(
- '启用状态',
- style: TextStyle(
- color: Colors.black,
- fontSize: GSYConstant.minTextSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- flex: 7,
- child: Container(
- child: dropDownButtons(
- sexMenuItems2, '请选择启用状态'),
- ),
- ),
- ]),
- ),
- SizedBox(
- height: 60,
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.end,
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- TextButton(
- onPressed: () {
- Navigator.pop(context);
- },
- child: Text(ConstantString.cancel),
- style: ButtonStyle(
- backgroundColor:
- MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
- foregroundColor:
- MaterialStateProperty.all<Color>(Colors.white),
- minimumSize: MaterialStateProperty.all(Size(80, 40)),
- padding: MaterialStateProperty.all(EdgeInsets.zero)),
- ),
- SizedBox(
- width: 20,
- ),
- TextButton(
- onPressed: () {
- if (widget.callback != null) {
- widget.callback(_device,_username,satus,isEnabled);
- }
- },
- child: Text(ConstantString.query),
- style: ButtonStyle(
- backgroundColor:
- MaterialStateProperty.all<Color>(Color(0xFF4875EC)),
- foregroundColor:
- MaterialStateProperty.all<Color>(Colors.white),
- minimumSize: MaterialStateProperty.all(Size(80, 40)),
- padding: MaterialStateProperty.all(EdgeInsets.zero)),
- ),
- SizedBox(
- width: 20,
- ),
- // new GSYFlexButton(
- // text: ConstantString.query,
- // color: Color(0xFF4875EC),
- // textColor: GSYColors.textWhite,
- // fontSize: 14,
- // onPress:()=>Navigator.pop(context),
- // ),
- ],
- )
- ],
- ),
- ),
- );
- }
- String _device = '', _username = '';
- dynamic satus = null, isEnabled =null;
- Widget dropDownButtonsColumn(
- List<DropMenuItem> list, String hint) {
- return Container(
- height: 40,
- //gives the height of the dropdown button
- width: MediaQuery.of(context).size.width,
- //gives the width of the dropdown button
- decoration: BoxDecoration(
- border: new Border.all(
- color: Colors.grey, //边框颜色
- width: 1.0, //边框粗细
- ),
- borderRadius:
- const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
- ),
- // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
- child: Theme(
- data: Theme.of(context).copyWith(
- // canvasColor: Colors.white, // background color for the dropdown items
- buttonTheme: ButtonTheme.of(context).copyWith(
- alignedDropdown:
- true, //If false (the default), then the dropdown's menu will be wider than its button.
- )),
- child: DropdownButtonHideUnderline(
- // to hide the default underline of the dropdown button
- child: DropdownButton<String>(
- iconEnabledColor: Color(0xFF595959),
- // icon color of the dropdown button
- items: list.map((dropMenuItem) {
- return DropdownMenuItem<String>(
- value: dropMenuItem.label,
- child: Text(
- dropMenuItem.label,
- style: TextStyle(fontSize: 15),
- ),
- );
- }).toList(),
- hint: Text(
- hint,
- style: TextStyle(fontSize: 15),
- ),
- // setting hint
- onChanged: (String? value) {
- key = value;
- setState(() {
- list.forEach((element) {
- if(value==element.label){
- satus= element.value; // saving the selected value
- }
- });
- });
- },
- value: key,
- // value: sexMenuItems.label, // displaying the selected value
- ),
- )),
- );
- }
- Widget dropDownButtons(
- List<DropMenuItem> list, String hint) {
- return Container(
- height: 40,
- //gives the height of the dropdown button
- width: MediaQuery.of(context).size.width,
- //gives the width of the dropdown button
- decoration: BoxDecoration(
- border: new Border.all(
- color: Colors.grey, //边框颜色
- width: 1.0, //边框粗细
- ),
- borderRadius:
- const BorderRadius.all(const Radius.circular(4.0)), //边框的弧度
- ),
- // padding: const EdgeInsets.symmetric(horizontal: 13), //you can include padding to control the menu items
- child: Theme(
- data: Theme.of(context).copyWith(
- // canvasColor: Colors.white, // background color for the dropdown items
- buttonTheme: ButtonTheme.of(context).copyWith(
- alignedDropdown:
- true, //If false (the default), then the dropdown's menu will be wider than its button.
- )),
- child: DropdownButtonHideUnderline(
- // to hide the default underline of the dropdown button
- child: DropdownButton<String>(
- iconEnabledColor: Color(0xFF595959),
- // icon color of the dropdown button
- items: list.map((dropMenuItem) {
- return DropdownMenuItem<String>(
- value: dropMenuItem.label,
- child: Text(
- dropMenuItem.label,
- style: TextStyle(fontSize: 15),
- ),
- );
- }).toList(),
- hint: Text(
- hint,
- style: TextStyle(fontSize: 15),
- ),
- // setting hint
- onChanged: (String? value) {
- key2=value;
- setState(() {
- list.forEach((element) {
- if(value==element.label){
- isEnabled= element.value; // saving the selected value
- }
- });
- });
- },
- value: key2,
- // value: sexMenuItems.label, // displaying the selected value
- ),
- )),
- );
- }
- }
- abstract class OnClickListener {
- void onConfirm();
- }
|