showLineModal.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'util/models.dart';
  4. // ignore: must_be_immutable
  5. class ShowLineModal extends Dialog {
  6. List<CompanyOfLineList> lineList = [];
  7. final childCallback;
  8. ShowLineModal(
  9. {Key key, @required this.lineList, @required this.childCallback})
  10. : super(key: key);
  11. String lineId = '-1';
  12. @override
  13. Widget build(BuildContext context) {
  14. return new Material(
  15. //创建透明层
  16. type: MaterialType.transparency, //透明类型
  17. child: new Center(
  18. //保证控件居中效果
  19. child: Container(
  20. width: ScreenUtil.getInstance().setWidth(600),
  21. height: ScreenUtil.getInstance().setHeight(345),
  22. decoration: BoxDecoration(
  23. color: Colors.white,
  24. borderRadius: BorderRadius.all(Radius.circular(8))),
  25. child: new Container(
  26. child: new Column(
  27. children: <Widget>[
  28. Container(
  29. height: ScreenUtil.getInstance().setHeight(255),
  30. decoration: BoxDecoration(
  31. border: Border(
  32. bottom: BorderSide(
  33. width: 1,
  34. color: Color.fromRGBO(151, 151, 151, 0.27)))),
  35. child: LineWidget(
  36. lineList: lineList,
  37. callback: (val) {
  38. lineId = val.toString();
  39. },
  40. )),
  41. Expanded(
  42. flex: 1,
  43. child: Container(
  44. child: Row(
  45. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  46. children: <Widget>[
  47. Expanded(
  48. flex: 1,
  49. child: InkWell(
  50. child: Container(
  51. decoration: BoxDecoration(
  52. border: Border(
  53. right: BorderSide(
  54. width: 1,
  55. color: Color.fromRGBO(
  56. 151, 151, 151, 0.27))),
  57. ),
  58. child: Center(
  59. child: Text(
  60. '取消',
  61. style: TextStyle(
  62. fontSize: ScreenUtil.getInstance()
  63. .setSp(32),
  64. color:
  65. Color.fromRGBO(64, 98, 254, 1)),
  66. ),
  67. )),
  68. onTap: () {
  69. Navigator.pop(context);
  70. },
  71. )),
  72. Expanded(
  73. flex: 1,
  74. child: InkWell(
  75. child: Container(
  76. decoration: BoxDecoration(
  77. border: Border(
  78. right: BorderSide(
  79. width: 1,
  80. color: Color.fromRGBO(
  81. 151, 151, 151, 0.27))),
  82. ),
  83. child: Center(
  84. child: Text(
  85. '确定',
  86. style: TextStyle(
  87. fontSize: ScreenUtil.getInstance()
  88. .setSp(32),
  89. color:
  90. Color.fromRGBO(64, 98, 254, 1)),
  91. ),
  92. )),
  93. onTap: () {
  94. Navigator.pop(context);
  95. childCallback(lineId);
  96. },
  97. )),
  98. ],
  99. ),
  100. ))
  101. ],
  102. ),
  103. ),
  104. ),
  105. ),
  106. );
  107. }
  108. }
  109. class LineWidget extends StatefulWidget {
  110. final List<CompanyOfLineList> lineList;
  111. final callback;
  112. LineWidget({Key key, this.lineList, this.callback}) : super(key: key);
  113. _LineWidgetState createState() => _LineWidgetState();
  114. }
  115. class _LineWidgetState extends State<LineWidget> {
  116. @override
  117. Widget build(BuildContext context) {
  118. return Column(
  119. children: <Widget>[
  120. Container(
  121. height: ScreenUtil.getInstance().setHeight(60),
  122. child:Center(
  123. child: Text('请选择线路'),
  124. ),
  125. ),
  126. Expanded(
  127. flex: 1,
  128. child: ListView.builder(
  129. itemCount: widget.lineList.length,
  130. itemBuilder: (BuildContext context, int index) {
  131. return InkWell(
  132. child: Container(
  133. height: ScreenUtil.getInstance().setHeight(100),
  134. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  135. child: Row(
  136. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  137. children: <Widget>[
  138. Text(
  139. widget.lineList[index].lineName,
  140. style: TextStyle(
  141. fontSize: ScreenUtil.getInstance().setSp(35)),
  142. ),
  143. Icon(Icons.check,color: widget.lineList[index].checkedStatus?Colors.black:Colors.white,)
  144. ],
  145. ),
  146. ),
  147. onTap: (){
  148. setState(() {
  149. for(int i=0;i<widget.lineList.length;i++){
  150. if(i==index){
  151. widget.lineList[i].checkedStatus = true;
  152. widget.callback(widget.lineList[i].lineId);
  153. }else{
  154. widget.lineList[i].checkedStatus = false;
  155. }
  156. }
  157. });
  158. },
  159. );
  160. },
  161. ),
  162. )
  163. ],
  164. );
  165. }
  166. }