mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Fix text field value not preserved after scrolling
This commit is contained in:
parent
5330fe81ae
commit
942f61d90d
1 changed files with 9 additions and 12 deletions
|
@ -66,7 +66,7 @@ class _AlbumViewerEditAppBarState extends State<AlbumViewerEditAppBar> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_editNameValue = widget.album.name;
|
||||
_controller = TextEditingController(text: widget.album.name);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -78,28 +78,25 @@ class _AlbumViewerEditAppBarState extends State<AlbumViewerEditAppBar> {
|
|||
background:
|
||||
_getAppBarCover(context, widget.account, widget.coverPreviewUrl),
|
||||
title: TextFormField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: L10n.of(context).nameInputHint,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value?.isNotEmpty == true) {
|
||||
validator: (_) {
|
||||
// use _controller.text here because the value might be wrong if
|
||||
// user scrolled the app bar off screen
|
||||
if (_controller.text.isNotEmpty == true) {
|
||||
return null;
|
||||
} else {
|
||||
return L10n.of(context).albumNameInputInvalidEmpty;
|
||||
}
|
||||
},
|
||||
onSaved: (value) {
|
||||
widget.onAlbumNameSaved?.call(value!);
|
||||
},
|
||||
onChanged: (value) {
|
||||
// need to save the value otherwise it'll return to the initial
|
||||
// after scrolling out of the view
|
||||
_editNameValue = value;
|
||||
onSaved: (_) {
|
||||
widget.onAlbumNameSaved?.call(_controller.text);
|
||||
},
|
||||
style: TextStyle(
|
||||
color: AppTheme.getPrimaryTextColor(context),
|
||||
),
|
||||
initialValue: _editNameValue,
|
||||
),
|
||||
),
|
||||
leading: IconButton(
|
||||
|
@ -112,7 +109,7 @@ class _AlbumViewerEditAppBarState extends State<AlbumViewerEditAppBar> {
|
|||
);
|
||||
}
|
||||
|
||||
late String _editNameValue;
|
||||
late TextEditingController _controller;
|
||||
}
|
||||
|
||||
Widget? _getAppBarCover(
|
||||
|
|
Loading…
Reference in a new issue