|
@@ -0,0 +1,84 @@
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter_google_map/dao/user_dao.dart';
|
|
|
+import 'package:flutter_google_map/models/user_model.dart';
|
|
|
+
|
|
|
+/// Description: login page
|
|
|
+/// Time : 07/09/2023 Sunday
|
|
|
+/// Author : liuyuqi.gov@msn.cn
|
|
|
+class LoginPage extends StatefulWidget {
|
|
|
+ const LoginPage({super.key});
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<LoginPage> createState() => _LoginPageState();
|
|
|
+}
|
|
|
+
|
|
|
+class _LoginPageState extends State<LoginPage> {
|
|
|
+ TextEditingController userNameController = TextEditingController();
|
|
|
+ TextEditingController passwordController = TextEditingController();
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return Scaffold(
|
|
|
+ body: Center(
|
|
|
+ child: SizedBox(
|
|
|
+ width: 400,
|
|
|
+ height: 400,
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ TextFormField(
|
|
|
+ controller: userNameController,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ hintText: "请输入用户名",
|
|
|
+ ),
|
|
|
+ validator: (v) {
|
|
|
+ if (v == null) {
|
|
|
+ return "用户名不能为空";
|
|
|
+ } else {
|
|
|
+ return v.trim().isNotEmpty ? null : "用户名不能为空";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ TextFormField(
|
|
|
+ controller: passwordController,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ hintText: "请输入密码",
|
|
|
+ ),
|
|
|
+ obscureText: true,
|
|
|
+ validator: (v) {
|
|
|
+ if (v == null) {
|
|
|
+ return "密码不能为空";
|
|
|
+ } else {
|
|
|
+ return v.trim().length > 6 ? null : "密码不能少于6位";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ElevatedButton(
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
+ "/",
|
|
|
+ (Route<dynamic> route) => false,
|
|
|
+ );
|
|
|
+ },
|
|
|
+ child: const Text("登录"),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ void login() async {
|
|
|
+ UserDao userDao = UserDao();
|
|
|
+ // form validate user and pwd then login
|
|
|
+ if (Form.of(context).validate()) {
|
|
|
+ UserModel user =
|
|
|
+ await userDao.login(userNameController.text, passwordController.text);
|
|
|
+ } else {
|
|
|
+ ScaffoldMessenger.of(context).showSnackBar(
|
|
|
+ const SnackBar(
|
|
|
+ content: Text("用户名或密码错误"),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|