145 lines
3.7 KiB
Dart
145 lines
3.7 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 EmailSignupBody extends StatefulWidget {
|
|
const EmailSignupBody({super.key});
|
|
|
|
@override
|
|
State<EmailSignupBody> createState() => _EmailSignupBodyState();
|
|
}
|
|
|
|
class _EmailSignupBodyState extends State<EmailSignupBody> {
|
|
bool _isProgressShow = false;
|
|
bool _isHttpSend = false;
|
|
|
|
final TextEditingController emailController = TextEditingController();
|
|
final TextEditingController codeController = TextEditingController();
|
|
|
|
final Map<String, bool> _isError = {
|
|
'email': false,
|
|
'code': false,
|
|
};
|
|
|
|
void _isInputError(String type, bool error) {
|
|
setState(() {
|
|
_isError[type] = error;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
const SizedBox(
|
|
width: double.infinity,
|
|
height: 100,
|
|
),
|
|
if (_isProgressShow)
|
|
const CircularProgressIndicator(
|
|
color: kSecondaryColor,
|
|
strokeWidth: 6.0,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 250,
|
|
child: SignTextField(
|
|
controller: emailController,
|
|
color: kSecondaryColor,
|
|
type: 'email',
|
|
labelText: '邮箱',
|
|
isError: _isInputError,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: double.infinity,
|
|
height: kDefaultPadding,
|
|
),
|
|
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),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: double.infinity,
|
|
height: kDefaultPadding,
|
|
),
|
|
elevatedButton(
|
|
onPressed: confirm,
|
|
text: '确定',
|
|
color: kSecondaryColor,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void confirm() async {
|
|
if (_isError['email']! || _isError['code']!) {
|
|
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() {
|
|
emailController.dispose();
|
|
codeController.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|