128 lines
3.2 KiB
Dart
128 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cherry_toast/cherry_toast.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'common_widgets.dart';
|
|
import 'package:together_mobile/common/constants.dart';
|
|
import 'package:together_mobile/request/signin_signup.dart';
|
|
|
|
class UsernameSigninBody extends StatefulWidget {
|
|
const UsernameSigninBody({super.key});
|
|
|
|
@override
|
|
State<UsernameSigninBody> createState() => _UsernameSigninBodyState();
|
|
}
|
|
|
|
class _UsernameSigninBodyState extends State<UsernameSigninBody> {
|
|
final bool _isProgressShow = false;
|
|
final bool _isHttpSend = false;
|
|
|
|
final TextEditingController usernameController = TextEditingController();
|
|
final TextEditingController passwordController = TextEditingController();
|
|
|
|
final Map<String, bool> _isError = {
|
|
'username': false,
|
|
'password': 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: kPrimaryColor,
|
|
strokeWidth: 6.0,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 250,
|
|
child: SignTextField(
|
|
labelText: '用户名',
|
|
type: 'username',
|
|
controller: usernameController,
|
|
isError: _isInputError,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: double.infinity,
|
|
height: kDefaultPadding,
|
|
),
|
|
SizedBox(
|
|
width: 250,
|
|
child: SignTextField(
|
|
obscureText: true,
|
|
labelText: '密码',
|
|
type: 'password',
|
|
controller: passwordController,
|
|
isError: _isInputError,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: kDefaultPadding,
|
|
width: double.infinity,
|
|
),
|
|
elevatedButton(
|
|
onPressed: () {
|
|
confirm(context);
|
|
},
|
|
text: '确定',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void confirm(BuildContext context) async {
|
|
// if (_isError['username']! || _isError['password']!) {
|
|
// 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;
|
|
// }
|
|
// });
|
|
|
|
context.go('/chat');
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
usernameController.dispose();
|
|
passwordController.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|