1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import 'package:flutter/material.dart';
- import 'package:gobang/service/user_dao.dart';
- /// Description: login page
- /// Time : 02/20/2024 Tuesday
- /// Author : liuyuqi.gov@msn.cn
- class LoginPage extends StatefulWidget {
- const LoginPage({Key? key}) : super(key: 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: 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("登录"),
- ),
- ]),
- );
- }
- /// login
- void login() async {
- if (Form.of(context).validate()) {
- await UserDao.login(userNameController.text, passwordController.text);
- } else {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(
- content: Text("用户名或密码错误"),
- ),
- );
- }
- }
- }
|