123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import 'package:flutter/material.dart';
- import 'package:flutter_tracker/dio/login_dao.dart';
- import 'package:flutter_tracker/model/base_model.dart';
- import 'package:flutter_tracker/routes/routes.dart';
- import 'package:flutter_tracker/utils/app_util.dart';
- /// Description:
- /// Time : 2021年12月03日 Friday
- /// Author : liuyuqi.gov@msncn
- class RegisterPage extends StatefulWidget {
- const RegisterPage({Key? key}) : super(key: key);
- @override
- _RegisterPageState createState() => _RegisterPageState();
- }
- class _RegisterPageState extends State<RegisterPage> {
- //用户名密码控制器
- final TextEditingController _controllerUsn = TextEditingController();
- final TextEditingController _controllerPwd = TextEditingController();
- final TextEditingController _controllerRepwd = TextEditingController();
- final GlobalKey _formKey = GlobalKey<FormState>();
- String _userName = "";
- String _pwd = "";
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text("注册账号"),
- ),
- body: Padding(
- padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
- child: Form(
- autovalidateMode: AutovalidateMode.always, key: _formKey, //开启自动校验
- child: ListView(
- children: [
- TextFormField(
- autofocus: true,
- controller: _controllerUsn,
- decoration: const InputDecoration(
- labelText: "用户名",
- hintText: "请输入用户名",
- icon: Icon(Icons.person)),
- // 校验用户名
- validator: (v) {
- return v!.trim().isNotEmpty ? null : "用户名不能为空";
- },
- onChanged: (inputStr) {
- _userName = inputStr;
- },
- ),
- TextFormField(
- controller: _controllerPwd,
- decoration: const InputDecoration(
- labelText: "密码",
- hintText: "请输入密码",
- icon: Icon(Icons.lock)),
- obscureText: true,
- //校验密码
- validator: (v) {
- return v!.trim().length > 5 ? null : "密码不能少于6位";
- }),
- TextFormField(
- controller: _controllerRepwd,
- decoration: const InputDecoration(
- labelText: "确认密码",
- hintText: "确认登录密码",
- icon: Icon(Icons.lock)),
- obscureText: true,
- //校验密码
- validator: (v) {
- return v!.trim().length > 5 ? null : "密码不能少于6位";
- },
- onChanged: (inputStr) {
- _pwd = inputStr;
- },
- ),
- // 登录按钮
- Padding(
- padding: const EdgeInsets.only(top: 28.0),
- child: Row(
- children: <Widget>[
- Expanded(
- child: ElevatedButton(
- child: const Text("注册"),
- style: ButtonStyle(
- padding: MaterialStateProperty.all(
- const EdgeInsets.all(15.0),
- ),
- iconColor: MaterialStateProperty.all(
- Theme.of(context).primaryColor),
- foregroundColor:
- MaterialStateProperty.all(Colors.white),
- ),
- onPressed: () {
- register();
- },
- ),
- ),
- ],
- ),
- )
- ],
- ),
- ),
- ),
- );
- }
- //注册
- void register() async {
- BaseModel messageModel = await LoginDao.register(_userName, _pwd);
- if (messageModel != null) {
- if (messageModel.success) {
- Navigator.of(context).pushNamed(Routes.loginPage);
- }
- AppUtil.buildToast(messageModel.msg);
- } else {
- AppUtil.buildToast("注册失败,请检查网络");
- }
- }
- // // //保存用户信息
- // void saveUserInfo(UserModel userModel) async {
- // SharedPreferences prefs = await SharedPreferences.getInstance();
- // prefs.setString("token", userModel.token);
- // AppConfig.isUser = false;
- // AppConfig.token = userModel.token;
- // loadUserInfo(userModel.token);
- // }
- //
- // void loadUserInfo(String token) async {
- // UserEntity entity = await UserDao.fetch(token);
- // if (entity?.userInfoModel != null) {
- // DialogUtil.buildToast("登录成功~");
- // Navigator.pop(context);
- // // eventBus.fire(UserLoggedInEvent("sucuss"));
- // } else {
- // DialogUtil.buildToast(entity.msgModel.msg);
- // }
- // }
- }
|