该按钮会生成一个唯一的时间戳,我希望将其自动填充到页面内表单中的表单域中。此字段值被推送到数据库。
new RaisedButton(
elevation: 5.0,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(10.0)),
onPressed: () {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
title: SelectableText(
DateTime.now().millisecondsSinceEpoch.toString(),
),
actions: <Widget>[
FlatButton(
child: Text('Done'),
textColor: Theme.Colors.loginGradientStart,
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
},
child: const Text(
'GENERATE\nTRACKING-No',
style: TextStyle(
fontSize: 20,
fontFamily: 'Spectral',
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal),
textAlign: TextAlign.center,
),
),
答案 0 :(得分:0)
设置TextField
文本。
void onButtonPressed(){
_controller.text = /* new value*/;
}
final _controller = TextEditingController();
// ...
TextFormField(controller: _controller)
// ...
void dispose() {
_controller.dispose();
super.dispose();
}