fix(flutter): 精简个人资料并修正保存文案
This commit is contained in:
1 parent
dc73f4e3bb
commit
b2a8bfa59f
4 files changed
+7
-48
No files matched your search
@@ -429,7 +429,7 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
String get like => '喜欢';
|
String get like => '喜欢';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get save => '收藏';
|
String get save => '保存';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get comments => '评论';
|
String get comments => '评论';
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@
|
|||||||
"mute": "静音",
|
"mute": "静音",
|
||||||
"unmute": "取消静音",
|
"unmute": "取消静音",
|
||||||
"like": "喜欢",
|
"like": "喜欢",
|
||||||
"save": "收藏",
|
"save": "保存",
|
||||||
"comments": "评论",
|
"comments": "评论",
|
||||||
"share": "分享",
|
"share": "分享",
|
||||||
"noComments": "还没有评论。",
|
"noComments": "还没有评论。",
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import 'account_profile_logic.dart';
|
|||||||
|
|
||||||
const _avatarSize = 64.0;
|
const _avatarSize = 64.0;
|
||||||
const _fieldGap = 14.0;
|
const _fieldGap = 14.0;
|
||||||
const _datePadWidth = 2;
|
|
||||||
|
|
||||||
/// 个人资料编辑页。
|
/// 个人资料编辑页。
|
||||||
class AccountProfilePage extends StatefulWidget {
|
class AccountProfilePage extends StatefulWidget {
|
||||||
@@ -37,7 +36,6 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
|||||||
late final AccountProfileLogic _logic;
|
late final AccountProfileLogic _logic;
|
||||||
final _nickname = TextEditingController();
|
final _nickname = TextEditingController();
|
||||||
var _gender = 'unknown';
|
var _gender = 'unknown';
|
||||||
String? _birthday;
|
|
||||||
bool _formReady = false;
|
bool _formReady = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -163,8 +161,6 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
|||||||
_nicknameField(l10n),
|
_nicknameField(l10n),
|
||||||
const SizedBox(height: _fieldGap),
|
const SizedBox(height: _fieldGap),
|
||||||
_genderField(l10n),
|
_genderField(l10n),
|
||||||
const SizedBox(height: _fieldGap),
|
|
||||||
_birthdayField(l10n),
|
|
||||||
if (_logic.error != null) _saveError(l10n),
|
if (_logic.error != null) _saveError(l10n),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_saveButton(l10n),
|
_saveButton(l10n),
|
||||||
@@ -200,26 +196,6 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _birthdayField(AppLocalizations l10n) => Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
OutlinedButton.icon(
|
|
||||||
key: const Key('account-birthday'),
|
|
||||||
onPressed: _pickBirthday,
|
|
||||||
icon: const Icon(Icons.cake_outlined),
|
|
||||||
label: Text(_birthday ?? l10n.accountSelectBirthday),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Text(
|
|
||||||
l10n.accountBirthdayHint,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: AppColors.muted,
|
|
||||||
fontSize: AppDimens.caption,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _saveError(AppLocalizations l10n) => Padding(
|
Widget _saveError(AppLocalizations l10n) => Padding(
|
||||||
padding: const EdgeInsets.only(top: 8),
|
padding: const EdgeInsets.only(top: 8),
|
||||||
child: Text(
|
child: Text(
|
||||||
@@ -307,24 +283,8 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> _pickBirthday() async {
|
|
||||||
final value = await showDatePicker(
|
|
||||||
context: context,
|
|
||||||
initialDate: DateTime(2000),
|
|
||||||
firstDate: DateTime(1900),
|
|
||||||
lastDate: DateTime.now(),
|
|
||||||
);
|
|
||||||
if (value != null && mounted) {
|
|
||||||
setState(() => _birthday = _formatDate(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _save() async {
|
Future<void> _save() async {
|
||||||
final ok = await _logic.save(
|
final ok = await _logic.save(nickname: _nickname.text, gender: _gender);
|
||||||
nickname: _nickname.text,
|
|
||||||
gender: _gender,
|
|
||||||
birthday: _birthday,
|
|
||||||
);
|
|
||||||
if (!ok || !mounted) return;
|
if (!ok || !mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text(AppLocalizations.of(context)!.accountSaved)),
|
SnackBar(content: Text(AppLocalizations.of(context)!.accountSaved)),
|
||||||
@@ -335,11 +295,6 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
|||||||
const {'male', 'female', 'unknown'}.contains(value) ? value : 'unknown';
|
const {'male', 'female', 'unknown'}.contains(value) ? value : 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatDate(DateTime value) =>
|
|
||||||
'${value.year.toString().padLeft(4, '0')}-'
|
|
||||||
'${value.month.toString().padLeft(_datePadWidth, '0')}-'
|
|
||||||
'${value.day.toString().padLeft(_datePadWidth, '0')}';
|
|
||||||
|
|
||||||
class _AccountCard extends StatelessWidget {
|
class _AccountCard extends StatelessWidget {
|
||||||
const _AccountCard({required this.child});
|
const _AccountCard({required this.child});
|
||||||
|
|
||||||
|
|||||||
@@ -28,15 +28,19 @@ void main() {
|
|||||||
AccountProfilePage(),
|
AccountProfilePage(),
|
||||||
repository: repository,
|
repository: repository,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
|
locale: const Locale('zh'),
|
||||||
);
|
);
|
||||||
|
|
||||||
final nickname = find.byKey(const Key('account-nickname'));
|
final nickname = find.byKey(const Key('account-nickname'));
|
||||||
|
expect(find.byKey(const Key('account-birthday')), findsNothing);
|
||||||
|
expect(find.text('保存'), findsOneWidget);
|
||||||
expect(tester.widget<TextField>(nickname).controller?.text, 'Nadia');
|
expect(tester.widget<TextField>(nickname).controller?.text, 'Nadia');
|
||||||
await tester.enterText(nickname, 'Nadia Baru');
|
await tester.enterText(nickname, 'Nadia Baru');
|
||||||
await tester.tap(find.byKey(const Key('account-profile-save')));
|
await tester.tap(find.byKey(const Key('account-profile-save')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(repository.lastUpdate?.nickname, 'Nadia Baru');
|
expect(repository.lastUpdate?.nickname, 'Nadia Baru');
|
||||||
|
expect(repository.lastUpdate?.birthday, isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('should_show_device_empty_state_when_list_is_empty', (
|
testWidgets('should_show_device_empty_state_when_list_is_empty', (
|
||||||
|
|||||||
Reference in new issue
Block a user