1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| /* * 输入框 * */
import 'package:flutter/material.dart';
class CustomDialog extends StatefulWidget { Function dismissCallback; // 取消回调 Function okCallback; // 确认回调 bool isNeedTag; // 外部传入的参数,控制显示slide还是input
CustomDialog({ Key key, this.dismissCallback, this.okCallback, this.isNeedTag, }) : super(key: key); @override _CustomDialogState createState() => _CustomDialogState(); }
class _CustomDialogState extends State<CustomDialog> { String commitStr; double slideValue = 0.0;
/* * 取消按钮点击事件 * */ _dismissDialog() { if (widget.dismissCallback != null) { widget.dismissCallback(); } Navigator.of(context).pop(); }
/* * 确定按钮点击事件 * */ _okCallback(String txt) { if (widget.okCallback != null) { widget.okCallback(txt); } Navigator.of(context).pop(); }
@override Widget build(BuildContext context) { return Material( type: MaterialType.transparency, child: Center( child: SizedBox( width: 240, height: 240, child: Container( decoration: BoxDecoration( color: Colors.cyanAccent, borderRadius: BorderRadius.vertical( top: Radius.circular(120.0), ), ), child: Column( children: <Widget>[ widget.isNeedTag == true ? _topWidget() : _topWidget1(), Spacer(), _bottomWidget(), ], ), ), ), ), ); }
/* * 上方输入UI * */ Widget _topWidget() { return Container( margin: EdgeInsets.only(top: 100), child: Container( child: TextField( onSubmitted: (e) { setState(() { commitStr = e; }); }, decoration: InputDecoration( border: InputBorder.none, hintText: "请输入字符", ), ), ), ); }
/* * 上方输入UI-1 * */ Widget _topWidget1() { return Container( margin: EdgeInsets.only(top: 100), child: Slider( value: slideValue, max: 100.0, min: 0.0, activeColor: Colors.blue, onChanged: (double val) { setState(() { slideValue = val; commitStr = val.toString(); }); }, ), ); }
/* * 底部选择widget * */ Widget _bottomWidget() { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[ InkWell( onTap: () { _okCallback(commitStr); }, child: Container( height: 50, width: 120, color: Colors.yellow[800], child: Center( child: Text( '确定', style: TextStyle(color: Colors.white), ), ), ), ), InkWell( onTap: () { _dismissDialog(); }, child: Container( height: 50, width: 120, color: Colors.red[800], child: Center( child: Text( '取消', style: TextStyle(color: Colors.white), ), ), ), ), ], ); } }
|