chooseWork.dart 4.5 KB

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) {

    });
  }
}