refactor(account): 收敛账号页组件结构
This commit is contained in:
1 parent
da095115d4
commit
6fce24d9ec
5 files changed
+308
-247
No files matched your search
@@ -156,84 +156,93 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
|
||||
}
|
||||
|
||||
Widget _editableForm(AppLocalizations l10n) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return _AccountCard(
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
key: const Key('account-nickname'),
|
||||
controller: _nickname,
|
||||
maxLength: AccountProfileLogic.maxNicknameLength,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.accountNickname,
|
||||
errorText: _logic.fieldError == null
|
||||
? null
|
||||
: l10n.accountNicknameInvalid,
|
||||
),
|
||||
),
|
||||
_nicknameField(l10n),
|
||||
const SizedBox(height: _fieldGap),
|
||||
DropdownButtonFormField<String>(
|
||||
key: const Key('account-gender'),
|
||||
initialValue: _gender,
|
||||
decoration: InputDecoration(labelText: l10n.accountGender),
|
||||
items: [
|
||||
DropdownMenuItem(value: 'male', child: Text(l10n.accountMale)),
|
||||
DropdownMenuItem(
|
||||
value: 'female',
|
||||
child: Text(l10n.accountFemale),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'unknown',
|
||||
child: Text(l10n.accountUnknownGender),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value != null) setState(() => _gender = value);
|
||||
},
|
||||
),
|
||||
_genderField(l10n),
|
||||
const SizedBox(height: _fieldGap),
|
||||
OutlinedButton.icon(
|
||||
key: const Key('account-birthday'),
|
||||
onPressed: _pickBirthday,
|
||||
icon: const Icon(Icons.cake_outlined),
|
||||
label: Text(_birthday ?? l10n.accountSelectBirthday),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
l10n.accountBirthdayHint,
|
||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
||||
),
|
||||
),
|
||||
if (_logic.error != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
errorText(l10n, _logic.error, l10n.accountProfileSaveFailed),
|
||||
style: TextStyle(color: scheme.error, fontSize: 12),
|
||||
),
|
||||
],
|
||||
_birthdayField(l10n),
|
||||
if (_logic.error != null) _saveError(l10n),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: FilledButton(
|
||||
key: const Key('account-profile-save'),
|
||||
onPressed: _logic.saving ? null : _save,
|
||||
child: _logic.saving
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(l10n.save),
|
||||
),
|
||||
),
|
||||
_saveButton(l10n),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _nicknameField(AppLocalizations l10n) => TextField(
|
||||
key: const Key('account-nickname'),
|
||||
controller: _nickname,
|
||||
maxLength: AccountProfileLogic.maxNicknameLength,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.accountNickname,
|
||||
errorText: _logic.fieldError == null ? null : l10n.accountNicknameInvalid,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _genderField(AppLocalizations l10n) => DropdownButtonFormField<String>(
|
||||
key: const Key('account-gender'),
|
||||
initialValue: _gender,
|
||||
decoration: InputDecoration(labelText: l10n.accountGender),
|
||||
items: [
|
||||
DropdownMenuItem(value: 'male', child: Text(l10n.accountMale)),
|
||||
DropdownMenuItem(value: 'female', child: Text(l10n.accountFemale)),
|
||||
DropdownMenuItem(
|
||||
value: 'unknown',
|
||||
child: Text(l10n.accountUnknownGender),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value != null) setState(() => _gender = value);
|
||||
},
|
||||
);
|
||||
|
||||
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: 12),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _saveError(AppLocalizations l10n) => Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
errorText(l10n, _logic.error, l10n.accountProfileSaveFailed),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _saveButton(AppLocalizations l10n) => SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: FilledButton(
|
||||
key: const Key('account-profile-save'),
|
||||
onPressed: _logic.saving ? null : _save,
|
||||
child: _logic.saving
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(l10n.save),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _readOnlyCard(AccountProfile profile, AppLocalizations l10n) {
|
||||
return _AccountCard(
|
||||
child: Column(
|
||||
|
||||
Reference in new issue
Block a user