如何在按钮单击时创建新的小部件?例如,我有这个代码:
child: MaterialButton(
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 42.0),
child: Text(
"LOGIN",
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontFamily: "WorkSansBold"),
),
),
onPressed: () {
var url = 'https://jsonplaceholder.typicode.com/users';
http.get(url).then((response) {
print("Response status: ${response.statusCode}");
print("Response body: ${response.body}");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => new SecondScreen()),
);
});
},
)
在这里,我想用JSON中的数据创建一个新屏幕 . 为简单起见,假设我需要为JSON响应中的所有 name 和数字创建新的 Text() 小部件 . 像电话簿这样的东西 .
在这个例子中, SecondScreen 小部件应该包含什么?