bug fix : empty string being saved everytime file info is closed without editing caption

This commit is contained in:
ashilkn 2022-11-05 17:13:05 +05:30
parent 27c660771f
commit e5125254b2

View file

@ -16,7 +16,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
int currentLength = 0; int currentLength = 0;
final _textController = TextEditingController(); final _textController = TextEditingController();
final _focusNode = FocusNode(); final _focusNode = FocusNode();
String editedCaption = ""; String? editedCaption;
@override @override
void initState() { void initState() {
@ -27,12 +27,15 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
editedCaption = caption; editedCaption = caption;
} }
}); });
editedCaption = widget.file.caption;
super.initState(); super.initState();
} }
@override @override
void dispose() { void dispose() {
editFileCaption(null, widget.file, editedCaption); if (editedCaption != null) {
editFileCaption(null, widget.file, editedCaption);
}
_textController.dispose(); _textController.dispose();
_focusNode.removeListener(() {}); _focusNode.removeListener(() {});
super.dispose(); super.dispose();
@ -45,7 +48,9 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
final caption = widget.file.caption; final caption = widget.file.caption;
return TextField( return TextField(
onEditingComplete: () { onEditingComplete: () {
editFileCaption(context, widget.file, editedCaption); if (editedCaption != null) {
editFileCaption(context, widget.file, editedCaption);
}
_focusNode.unfocus(); _focusNode.unfocus();
}, },
controller: _textController, controller: _textController,