【发布时间】:2020-08-06 18:35:49
【问题描述】:
我想在我们发布新数据后获取数据。现在我需要重新打开应用程序以获取插入的数据。像图片一样,我在下面显示。在主页,详细信息来自响应 JSON。 主页有一个按钮转到添加数据页。在我单击按钮转到 添加数据页面 之后,在添加了 电子邮件、用户名 数据后,我使用 Navigator.of(context).pop( );.问题是数据没有更新,我需要重新打开应用才能看到新插入的数据。
这是我的主页代码:
Future getDetails() async {
http.Response response = await http.get(url);
var decodedData = json.decode(response.body);
setState(() {
email= decodedData['email'];
username= decodedData['username'];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Home page'),
),
body: SingleChildScrollView(
child: Column(
children: <Widget> [
new Row(
children: [
Text(' Name: '+ username, style: TextStyle(fontSize: 16), textAlign: TextAlign.left,),
Text(' Email : '+ email, style: TextStyle(fontSize: 16), textAlign: TextAlign.left,),
]
),
new Row(
children: [
SizedBox(
width: 350,
child: OutlineButton(
child: Text('ADD DATA'),
onPressed: () {Navigator.of(context).push(MaterialPageRoute(builder: (context) => AddPage()));},
)
)
]
),
]
),
)
);
}
这是我的添加数据页面代码:
Future<void> addDetails() async {
setState(() {
loading = true;
});
http.Response response = await http.post(url,
body: {
'username': usernameController.text,
'email': emailController.text,
}
);
setState(() {
loading = true;
Navigator.pop(context);
});
}
有谁知道如何解决这个问题?谢谢。
【问题讨论】:
标签: flutter