我已经尝试过这种不同的方法,但它就是行不通。我喜欢用户在文本字段中写入的输入文本在提交/上传后保留,因此当用户返回页面时,文本应该在那里并且用户可以手动清除它,不确定这里出了什么问题。提前致谢 。
class MondayScreen extends StatefulWidget {
static final String id = 'monday_screen';
@override
_MondayScreenState createState() => _MondayScreenState();
}
TextEditingController _oneController = TextEditingController();
class _MondayScreenState extends State<MondayScreen> {
String _alOne = '';
_submit() {
Post post = Post(
authorId: Provider.of<UserData>(context ,listen: false).currentUserId,
timestamp: Timestamp.fromDate(DateTime.now()),
alOne: _alOne,
);
DatabaseService.createPostMonday(post);
setState(() {
_oneController.text;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text(
'Monday Lunch',
style: TextStyle(color: Colors.white),
),
actions: <Widget>[
FlatButton(
child: Text(
'Spara',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.w600),
),
onPressed: _submit,
color: Colors.black,
)
],
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 60.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 30.0),
child: TextField(
controller: TextEditingController(),
style: TextStyle(fontSize: 18.0),
decoration: InputDecoration(
labelText: 'Alternativ',
),
onSubmitted: (input) => _alOne = input,
),
),