165 lines
4.4 KiB
Dart
165 lines
4.4 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
import 'package:cherry_toast/cherry_toast.dart';
|
||
|
|
||
|
import 'common_widgets.dart';
|
||
|
import 'package:together_mobile/common/constants.dart';
|
||
|
import 'package:together_mobile/request/signin_signup.dart';
|
||
|
|
||
|
class SignupBody extends StatefulWidget {
|
||
|
const SignupBody({super.key});
|
||
|
|
||
|
@override
|
||
|
State<SignupBody> createState() => _SignupBodyState();
|
||
|
}
|
||
|
|
||
|
class _SignupBodyState extends State<SignupBody> {
|
||
|
bool _isProgressShow = false;
|
||
|
bool _isHttpSend = false;
|
||
|
|
||
|
final TextEditingController usernameController = TextEditingController();
|
||
|
final TextEditingController passwordController = TextEditingController();
|
||
|
final TextEditingController phoneEmailController = TextEditingController();
|
||
|
final TextEditingController codeController = TextEditingController();
|
||
|
|
||
|
final Map<String, bool> _isError = {
|
||
|
'username': false,
|
||
|
'password1': false,
|
||
|
'password2': false,
|
||
|
};
|
||
|
|
||
|
void _isInputError(String type, bool error) {
|
||
|
setState(() {
|
||
|
_isError[type] = error;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||
|
children: [
|
||
|
Stack(
|
||
|
alignment: Alignment.center,
|
||
|
children: [
|
||
|
const SizedBox(
|
||
|
width: double.infinity,
|
||
|
),
|
||
|
if (_isProgressShow)
|
||
|
const CircularProgressIndicator(
|
||
|
color: kSecondaryColor,
|
||
|
strokeWidth: 6.0,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 250,
|
||
|
child: SignTextField(
|
||
|
color: kSecondaryColor,
|
||
|
labelText: '用户名',
|
||
|
type: 'username',
|
||
|
controller: usernameController,
|
||
|
isError: _isInputError,
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 250,
|
||
|
child: SignTextField(
|
||
|
color: kSecondaryColor,
|
||
|
obscureText: true,
|
||
|
labelText: '密码',
|
||
|
type: 'password1',
|
||
|
controller: passwordController,
|
||
|
isError: _isInputError,
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 250,
|
||
|
child: SignTextField(
|
||
|
controller: phoneEmailController,
|
||
|
color: kSecondaryColor,
|
||
|
type: 'email',
|
||
|
labelText: '邮箱',
|
||
|
isError: _isInputError,
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 250,
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
SizedBox(
|
||
|
width: 120,
|
||
|
child: SignTextField(
|
||
|
controller: codeController,
|
||
|
color: kSecondaryColor,
|
||
|
type: 'code',
|
||
|
labelText: '验证码',
|
||
|
isError: _isInputError,
|
||
|
),
|
||
|
),
|
||
|
TextButton(
|
||
|
onPressed: () {},
|
||
|
style: TextButton.styleFrom(
|
||
|
foregroundColor: kSecondaryColor,
|
||
|
// tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||
|
),
|
||
|
child: const Text(
|
||
|
'获取验证码',
|
||
|
style: TextStyle(color: kSecondaryColor, fontSize: 15.0),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
elevatedButton(
|
||
|
onPressed: () {
|
||
|
confirm(context);
|
||
|
},
|
||
|
text: '确定',
|
||
|
color: kSecondaryColor,
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
void confirm(BuildContext context) async {
|
||
|
if (_isError['username']! ||
|
||
|
_isError['password1']! ||
|
||
|
_isError['password2']!) {
|
||
|
CherryToast.error(
|
||
|
title: const Text('账号或密码不符合规范'),
|
||
|
toastDuration: const Duration(seconds: 2),
|
||
|
animationDuration: const Duration(seconds: 1),
|
||
|
).show(context);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
setState(() {
|
||
|
if (!_isProgressShow) _isProgressShow = true;
|
||
|
});
|
||
|
|
||
|
Map<String, dynamic>? result;
|
||
|
|
||
|
if (_isProgressShow && !_isHttpSend) {
|
||
|
_isHttpSend = true;
|
||
|
result = await signup();
|
||
|
}
|
||
|
setState(() {
|
||
|
if (result!['code'] == 10000) {
|
||
|
_isHttpSend = false;
|
||
|
_isProgressShow = false;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
usernameController.dispose();
|
||
|
passwordController.dispose();
|
||
|
super.dispose();
|
||
|
}
|
||
|
}
|