pikapika/lib/screens/ModifyPasswordScreen.dart

143 lines
4.0 KiB
Dart
Raw Normal View History

2022-02-25 06:31:25 +00:00
import 'package:flutter/material.dart';
import 'package:pikapika/basic/Method.dart';
import 'package:pikapika/screens/components/ContentLoading.dart';
import '../basic/Common.dart';
2022-03-19 04:12:27 +00:00
import 'components/RightClickPop.dart';
2022-02-25 06:31:25 +00:00
class ModifyPasswordScreen extends StatefulWidget {
2022-03-19 04:12:27 +00:00
const ModifyPasswordScreen({Key? key}) : super(key: key);
2022-02-25 06:31:25 +00:00
@override
State<StatefulWidget> createState() => _ModifyPasswordScreenState();
}
class _ModifyPasswordScreenState extends State<ModifyPasswordScreen> {
late bool _loading = false;
late String _oldPassword = "";
late String _newPassword = "";
late String _newPasswordRep = "";
@override
2022-03-19 04:12:27 +00:00
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) {
2022-02-25 06:31:25 +00:00
return Scaffold(
appBar: AppBar(
2022-03-19 04:12:27 +00:00
title: const Text("修改密码"),
2022-02-25 06:31:25 +00:00
),
body: _loading
? Stack(
children: [
2022-03-19 04:12:27 +00:00
const ContentLoading(label: "请稍后"),
2022-02-25 06:31:25 +00:00
WillPopScope(
child: Container(),
onWillPop: () async {
return false;
},
),
],
)
: _buildForm(),
);
}
Widget _buildForm() {
return ListView(
children: [
const Divider(),
ListTile(
2022-03-19 04:12:27 +00:00
title: const Text("旧密码"),
2022-02-25 06:31:25 +00:00
subtitle: Text(_oldPassword == "" ? "未填写" : '\u2022' * 10),
onTap: () async {
String? input = await displayTextInputDialog(
context,
src: _oldPassword,
title: '旧密码',
hint: '请输入旧密码',
isPasswd: true,
);
if (input != null) {
setState(() {
_oldPassword = input;
});
}
},
),
const Divider(),
ListTile(
2022-03-19 04:12:27 +00:00
title: const Text("新密码"),
2022-02-25 06:31:25 +00:00
subtitle: Text(_newPassword == "" ? "未填写" : '\u2022' * 10),
onTap: () async {
String? input = await displayTextInputDialog(
context,
src: _newPassword,
title: '新密码',
hint: '请输入新密码',
isPasswd: true,
);
if (input != null) {
setState(() {
_newPassword = input;
});
}
},
),
const Divider(),
ListTile(
2022-03-19 04:12:27 +00:00
title: const Text("重复输入新密码"),
2022-02-25 06:31:25 +00:00
subtitle: Text(_newPasswordRep == "" ? "未填写" : '\u2022' * 10),
onTap: () async {
String? input = await displayTextInputDialog(
context,
src: _newPasswordRep,
title: '重复输入新密码',
hint: '请重复输入新密码',
isPasswd: true,
);
if (input != null) {
setState(() {
_newPasswordRep = input;
});
}
},
),
const Divider(),
Container(
2022-03-19 04:12:27 +00:00
margin: const EdgeInsets.all(10),
2022-02-25 06:31:25 +00:00
child: MaterialButton(
textColor: Colors.white,
color: Theme.of(context).appBarTheme.backgroundColor,
onPressed: () async {
if (_newPasswordRep != _newPassword) {
defaultToast(context, "新密码不匹配");
return;
}
setState(() {
_loading = true;
});
try {
await method.updatePassword(_oldPassword, _newPassword);
defaultToast(context, "修改成功");
Navigator.of(context).pop();
} catch (e) {
defaultToast(context, "失败 : $e");
setState(() {
_loading = false;
});
}
},
2022-03-19 04:12:27 +00:00
child: const Text("确认"),
2022-02-25 06:31:25 +00:00
),
),
],
);
}
}