login_page.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_green/dao/user_dao.dart';
  3. import 'package:flutter_green/routes/routes.dart';
  4. /// 登录页面
  5. class LoginPage extends StatefulWidget {
  6. @override
  7. _LoginPageState createState() => _LoginPageState();
  8. }
  9. class _LoginPageState extends State<LoginPage> {
  10. TextEditingController _usernameContrller = TextEditingController();
  11. TextEditingController _passwordContrller = TextEditingController();
  12. @override
  13. Widget build(BuildContext context) {
  14. return Scaffold(
  15. body: Container(
  16. padding: EdgeInsets.only(left: 20, right: 20),
  17. child: Column(
  18. children: [
  19. SizedBox(
  20. height: 20,
  21. ),
  22. Image.asset(
  23. "assets/images/leaf.jpg",
  24. width: 200,
  25. ),
  26. Text("登录页面"),
  27. TextFormField(
  28. controller: _usernameContrller,
  29. decoration:
  30. InputDecoration(hintText: "用户名", icon: Icon(Icons.person)),
  31. ),
  32. TextFormField(
  33. decoration: InputDecoration(
  34. icon: Icon(Icons.lock), hintText: "密码"),
  35. controller: _passwordContrller,
  36. ),
  37. SizedBox(
  38. height: 20,
  39. ),
  40. TextButton(
  41. style: ButtonStyle(
  42. backgroundColor: MaterialStateProperty.all(Colors.blue),
  43. minimumSize: MaterialStateProperty.all(Size(200, 40))),
  44. onPressed: () {
  45. login();
  46. },
  47. child: Text(
  48. "登录",
  49. style: TextStyle(color: Colors.white),
  50. ))
  51. ],
  52. ),
  53. ),
  54. );
  55. }
  56. login() {
  57. var user = UserDao.login(_usernameContrller.text, _passwordContrller.text);
  58. // if(user.success)
  59. Navigator.pushNamed(context, Routes.homePage);
  60. }
  61. }