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 | // 这个地方我们因该使用 stl 记得改回来 class HYHomeScreen extends StatefulWidget { @override _HYHomeScreenState createState() => _HYHomeScreenState(); } class _HYHomeScreenState extends State<HYHomeScreen> { @override Widget build(BuildContext context) { // 验证使用的Key final _formKey = GlobalKey<FormState>(); final nameController = TextEditingController(); final passwordController = TextEditingController(); return Scaffold( appBar: HYHomeAppBar(context), body: HYHomeContent(), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( content: Stack( overflow: Overflow.visible, children: <Widget>[ Positioned( right: -40.px, top: -40.px, child: Container( margin: EdgeInsets.only(left: 400.px), child: InkResponse( onTap: () { Navigator.of(context).pop(); }, child: CircleAvatar( child: Icon(Icons.close), backgroundColor: Colors.red, ), ), ), ), Container( width: 200.px, // color: Colors.red, child: Form( key: _formKey, child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ Padding( padding: EdgeInsets.all(8.px), child: TextFormField( decoration: InputDecoration( labelText: "username", icon: Padding( padding: EdgeInsets.only(top: 15.px), child: Icon(Icons.supervised_user_circle), ) ), controller: nameController, validator: (value) { if( value.isEmpty ) { return "请输入用户名"; } return null; }, ), ), Padding( padding: EdgeInsets.all(8.px), child: TextFormField( decoration: InputDecoration( labelText: "password", icon: Padding( padding: EdgeInsets.only(top: 15.px), child: Icon(Icons.lock), ) ), controller: passwordController, validator: (value) { if( value.isEmpty ) { return "请输入密码"; } return null; }, ), ), Padding( padding: EdgeInsets.only(top: 15.px), child: RaisedButton( child: Text("登录"), onPressed: () { if (_formKey.currentState.validate()) { _formKey.currentState.save(); print("name : ${nameController.text}"); nameController.text = ""; print("password: ${passwordController.text}"); passwordController.text = ""; // const timeout = const Duration(seconds: 1); // Timer.periodic(timeout, (timer){ //// print(timer); // Navigator.of(context).pop(); // }); } }, ), ) ], ), ), ) ], ) ); } ); }, ), ); } @override void dispose() { // TODO: implement dispose super.dispose(); } } |
