-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Description
The question title is very self explanatory, after the user type in the textfield and dismiss the keyboard, the content of the TextField is cleared.
I tried do transform the screen in a Stateful widget, but the problem persists.
Bellow is my code, the log that appears when the keyboard is dismissed and the Flutter Doctor.
The error itself
My Code
[Stateful backclass default ommited]
class _EditNoteScreenState extends State<EditNoteScreen>{
_EditNoteScreenState(String day, String title, String note){
this.day = day;
this.title = title;
this.note = note;
}
String day, title, note;
@override
Widget build(BuildContext context) {
var noteController = TextEditingController();
var titleController = TextEditingController();
titleController.text = ( title == " ") ? null : title;
noteController.text = (note == " ") ? null : note;
var noteNode = FocusNode();
var titleNode = FocusNode();
_saveNote() {
DBProvider.db.addNote(day, titleController.text, noteController.text);
print("DAY " + day);
Navigator.pop(context);
}
return Scaffold(
body:SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top:20.0, left:8.0),
child: Column(
children: <Widget>[
Container(
margin: const EdgeInsets.only(top: 18, left: 18, right: 18),
child: TextField(
controller: titleController,
focusNode: titleNode,
autofocus: true,
onEditingComplete: () {
FocusScope.of(context).requestFocus(noteNode);
},
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
decoration: InputDecoration(border: InputBorder.none, hintText: "Título"),
),
),
Container(
margin: new EdgeInsets.only(left: 18, right: 8),
child: TextField(
controller: noteController,
focusNode: noteNode,
maxLines: 10,
style: TextStyle(fontSize: 18),
decoration: InputDecoration(border: InputBorder.none, hintText: "Corpo da nota"),
),
),
Padding(
padding: const EdgeInsets.only(right: 16.0, top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Flexible(
child: RaisedButton.icon(
color: primary_yellow,
onPressed: () {
_saveNote();
},
label: Text("Registrar Nota"),
icon: Icon(
Icons.edit,
color: pretty_black,
),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30)),
),
),
],
),
)
],
),
),
));
}
}
Logs
[+7694 ms] W/IInputConnectionWrapper( 3164): getTextBeforeCursor on inactive InputConnection
[ +1 ms] W/IInputConnectionWrapper( 3164): getSelectedText on inactive InputConnection
[ +1 ms] W/IInputConnectionWrapper( 3164): getTextAfterCursor on inactive InputConnection
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [versão 10.0.17763.529], locale pt-BR)
• Flutter version 1.2.1 at C:\res\flutter
• Framework revision 8661d8aecd (3 months ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390fa4
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\muril\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[√] Android Studio (version 3.4)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 35.1.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[√] Connected device (1 available)
• Moto G 5S • 0036529019 • android-arm • Android 8.1.0 (API 27)
• No issues found!
Metadata
Metadata
Assignees
Labels
No labels
