login_page.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. /// Description: 登录界面
  3. /// Time : 05/01/2023 Monday
  4. /// Author : liuyuqi.gov@msn.cn
  5. class LoginPage extends StatefulWidget {
  6. LoginPage({Key? key}) : super(key: key);
  7. @override
  8. _LoginPageState createState() => _LoginPageState();
  9. }
  10. class _LoginPageState extends State<LoginPage> {
  11. TextEditingController userNameController = TextEditingController();
  12. TextEditingController passwordController = TextEditingController();
  13. @override
  14. Widget build(BuildContext context) {
  15. return Scaffold(
  16. appBar: AppBar(
  17. title: Text("登录"),
  18. centerTitle: true,
  19. ),
  20. body: Container(
  21. padding: EdgeInsets.all(20),
  22. child: Column(
  23. mainAxisAlignment: MainAxisAlignment.center,
  24. children: [
  25. TextFormField(
  26. controller: userNameController,
  27. decoration: InputDecoration(
  28. labelText: "用户名",
  29. hintText: "请输入用户名",
  30. prefixIcon: Icon(Icons.person),
  31. ),
  32. ),
  33. TextFormField(
  34. controller: passwordController,
  35. decoration: InputDecoration(
  36. labelText: "密码",
  37. hintText: "请输入密码",
  38. prefixIcon: Icon(Icons.lock),
  39. ),
  40. validator: (value) {
  41. if (value == null || value.isEmpty) {
  42. return "密码不能为空";
  43. }
  44. return null;
  45. },
  46. ),
  47. SizedBox(height: 20),
  48. ElevatedButton(
  49. onPressed: () {
  50. print("用户名:${userNameController.text}");
  51. print("密码:${passwordController.text}");
  52. },
  53. child: Text("登录"),
  54. ),
  55. ],
  56. ),
  57. ),
  58. );
  59. }
  60. void login() async {
  61. // if form.validate()验证表单
  62. }
  63. }