2021-09-29 23:57:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
2021-11-11 03:00:38 +00:00
|
|
|
import 'package:pikapika/basic/Common.dart';
|
|
|
|
import 'package:pikapika/basic/Method.dart';
|
|
|
|
import 'package:pikapika/screens/components/NetworkSetting.dart';
|
2022-03-19 04:12:27 +00:00
|
|
|
import 'package:pikapika/screens/components/RightClickPop.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
import 'components/ContentLoading.dart';
|
|
|
|
|
2021-10-26 11:04:23 +00:00
|
|
|
/// 注册页面
|
2021-09-29 23:57:09 +00:00
|
|
|
class RegisterScreen extends StatefulWidget {
|
2022-03-19 04:12:27 +00:00
|
|
|
const RegisterScreen({Key? key}) : super(key: key);
|
|
|
|
|
2021-09-29 23:57:09 +00:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _RegisterScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RegisterScreenState extends State<RegisterScreen> {
|
|
|
|
|
|
|
|
late bool _registering = false;
|
|
|
|
late bool _registerOver = false;
|
|
|
|
|
|
|
|
late String _email = "";
|
|
|
|
late String _name = "";
|
|
|
|
late String _password = "";
|
|
|
|
late String _gender = "bot";
|
|
|
|
late String _birthday = "2000-01-01";
|
|
|
|
late String _question1 = "问题1";
|
|
|
|
late String _answer1 = "回答1";
|
|
|
|
late String _question2 = "问题2";
|
|
|
|
late String _answer2 = "回答2";
|
|
|
|
late String _question3 = "问题3";
|
|
|
|
late String _answer3 = "回答3";
|
|
|
|
|
|
|
|
Future _register() async {
|
|
|
|
setState(() {
|
|
|
|
_registering = true;
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
var mustList = <String>[
|
|
|
|
_email,
|
|
|
|
_name,
|
|
|
|
_password,
|
|
|
|
_gender,
|
|
|
|
_birthday,
|
|
|
|
_question1,
|
|
|
|
_answer1,
|
|
|
|
_question2,
|
|
|
|
_answer2,
|
|
|
|
_question3,
|
|
|
|
_answer3,
|
|
|
|
];
|
|
|
|
for (var a in mustList) {
|
|
|
|
if (a.isEmpty) {
|
|
|
|
throw '请检查表单, 不允许留空';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await method.register(
|
|
|
|
_email,
|
|
|
|
_name,
|
|
|
|
_password,
|
|
|
|
_gender,
|
|
|
|
_birthday,
|
|
|
|
_question1,
|
|
|
|
_answer1,
|
|
|
|
_question2,
|
|
|
|
_answer2,
|
|
|
|
_question3,
|
|
|
|
_answer3,
|
|
|
|
);
|
|
|
|
await method.setUsername(_email);
|
|
|
|
await method.setPassword(_password);
|
|
|
|
await method.clearToken();
|
|
|
|
setState(() {
|
|
|
|
_registerOver = true;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2021-11-20 16:02:33 +00:00
|
|
|
String message = "$e";
|
|
|
|
if (message.contains("email is already exist")) {
|
|
|
|
message = "账号已存在";
|
|
|
|
}
|
|
|
|
alertDialog(context, "注册失败", message);
|
2021-09-29 23:57:09 +00:00
|
|
|
} finally {
|
|
|
|
setState(() {
|
|
|
|
_registering = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-25 14:57:30 +00:00
|
|
|
return rightClickPop(
|
|
|
|
child: buildScreen(context),
|
|
|
|
context: context,
|
|
|
|
canPop: true,
|
|
|
|
);
|
2022-03-19 04:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildScreen(BuildContext context) {
|
2021-09-29 23:57:09 +00:00
|
|
|
if (_registerOver) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-03-17 03:31:25 +00:00
|
|
|
title: const Text('注册成功'),
|
2021-09-29 23:57:09 +00:00
|
|
|
),
|
|
|
|
body: Center(
|
2022-03-19 04:12:27 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(child: Container()),
|
|
|
|
const Text('您已经注册成功, 请返回登录'),
|
|
|
|
Text('账号 : $_email'),
|
|
|
|
Text('昵称 : $_name'),
|
|
|
|
Expanded(child: Container()),
|
|
|
|
Expanded(child: Container()),
|
|
|
|
],
|
2021-09-29 23:57:09 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (_registering) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(),
|
2022-03-19 04:12:27 +00:00
|
|
|
body: const ContentLoading(label: '注册中'),
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return Scaffold(
|
2022-03-19 04:12:27 +00:00
|
|
|
appBar: AppBar(title: const Text('注册'), actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () => _register(), icon: const Icon(Icons.check),),
|
2021-09-29 23:57:09 +00:00
|
|
|
],),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
2022-03-19 04:12:27 +00:00
|
|
|
const Divider(),
|
2021-09-29 23:57:09 +00:00
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("账号 (不一定是邮箱/登录使用)"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_email == "" ? "未设置" : _email),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _email,
|
|
|
|
title: '账号',
|
|
|
|
hint: '请输入账号',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_email = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("密码 (8位以上)"),
|
2021-12-15 15:44:05 +00:00
|
|
|
subtitle: Text(_password == "" ? "未设置" : '\u2022' * 10),
|
2021-09-29 23:57:09 +00:00
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _password,
|
|
|
|
title: '密码',
|
|
|
|
hint: '请输入密码',
|
2021-12-15 06:46:22 +00:00
|
|
|
isPasswd: true,
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_password = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("昵称 (2-50字)"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_name == "" ? "未设置" : _name),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _name,
|
|
|
|
title: '昵称',
|
|
|
|
hint: '请输入昵称',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_name = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("性别"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_genderText(_gender)),
|
|
|
|
onTap: () async {
|
|
|
|
String? result = await showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return SimpleDialog(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text('选择您的性别'),
|
2021-09-29 23:57:09 +00:00
|
|
|
children: [
|
|
|
|
SimpleDialogOption(
|
2022-03-19 04:12:27 +00:00
|
|
|
child: const Text('扶她'),
|
2021-09-29 23:57:09 +00:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, 'bot');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SimpleDialogOption(
|
2022-03-19 04:12:27 +00:00
|
|
|
child: const Text('公'),
|
2021-09-29 23:57:09 +00:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, 'm');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SimpleDialogOption(
|
2022-03-19 04:12:27 +00:00
|
|
|
child: const Text('母'),
|
2021-09-29 23:57:09 +00:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, 'f');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (result != null) {
|
|
|
|
setState(() {
|
|
|
|
_gender = result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("生日"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_birthday),
|
|
|
|
onTap: () async {
|
|
|
|
DatePicker.showDatePicker(
|
|
|
|
context,
|
|
|
|
locale: LocaleType.zh,
|
|
|
|
currentTime: DateTime.parse(_birthday),
|
|
|
|
onConfirm: (date) {
|
|
|
|
setState(() {
|
|
|
|
_birthday = formatTimeToDate(date.toString());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-03-19 04:12:27 +00:00
|
|
|
const Divider(),
|
2021-09-29 23:57:09 +00:00
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("问题1"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_question1 == "" ? "未设置" : _question1),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _question1,
|
|
|
|
title: '问题1',
|
|
|
|
hint: '请输入问题1',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_question1 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("回答1"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_answer1 == "" ? "未设置" : _answer1),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _answer1,
|
|
|
|
title: '回答1',
|
|
|
|
hint: '请输入回答1',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_answer1 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("问题2"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_question2 == "" ? "未设置" : _question2),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _question2,
|
|
|
|
title: '问题2',
|
|
|
|
hint: '请输入问题2',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_question2 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("回答2"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_answer2 == "" ? "未设置" : _answer2),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _answer2,
|
|
|
|
title: '回答2',
|
|
|
|
hint: '请输入回答2',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_answer2 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("问题3"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_question3 == "" ? "未设置" : _question3),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _question3,
|
|
|
|
title: '问题3',
|
|
|
|
hint: '请输入问题3',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_question3 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("回答3"),
|
2021-09-29 23:57:09 +00:00
|
|
|
subtitle: Text(_answer3 == "" ? "未设置" : _answer3),
|
|
|
|
onTap: () async {
|
|
|
|
String? input = await displayTextInputDialog(
|
|
|
|
context,
|
2021-12-15 04:22:40 +00:00
|
|
|
src: _answer3,
|
|
|
|
title: '回答3',
|
|
|
|
hint: '请输入回答3',
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
if (input != null) {
|
|
|
|
setState(() {
|
|
|
|
_answer3 = input;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-03-19 04:12:27 +00:00
|
|
|
const Divider(),
|
|
|
|
const NetworkSetting(),
|
|
|
|
const Divider(),
|
2021-09-29 23:57:09 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String _genderText(String gender) {
|
|
|
|
switch (gender) {
|
|
|
|
case 'bot':
|
|
|
|
return "扶她";
|
|
|
|
case "m":
|
|
|
|
return "公";
|
|
|
|
case "f":
|
|
|
|
return "母";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|