如何在flutter中的futureBuild中返回表单小部件



我有这段代码,因为我正在尝试编写一些代码来更新firestore中的数据。

@override
Widget build(BuildContext context) {
// Use the Todo to create the UI.
return Scaffold(
appBar: AppBar(
title: Text(mid.toString()),
),
body: FutureBuilder<Member?>(
future: readMember(mid),
builder: (context, snapshot) {
if (snapshot.hasData) {
final member = snapshot.data;

/// return a form

} else {
return const Center(child: CircularProgressIndicator());
}
},
),
);
}

如果快照有数据,我想返回这样的表格

Card(
child: Row(
children: <Widget>[
TextField(
controller: controllerName,
decoration: decoration('name'),
),
const SizedBox(height: 24),
TextField(
controller: controllerAge,
decoration: decoration('Age'),
keyboardType: TextInputType.number,
),
const SizedBox(height: 24),
ElevatedButton(
child: const Text('Create'),
onPressed: () {},
),
],
));

我的所有尝试都没有成功,我需要帮助。

检查其他状态,如错误或数据是否为空

builder: (context, snapshot) {
if (snapshot.hasError) {
return Text("Got Error");
}
if (snapshot.data == null) {
return Text("No data");
}
if (snapshot.hasData) {
final member = snapshot.data;
return Card( ///here form
child: Row(
children: <Widget>[],
));
} else {
return const Center(child: CircularProgressIndicator());
}
},

并在TextFiled上提供宽度以修复溢出,TextFiled和行正试图用获得无限。只需使用Expanded包装

Expanded(child: TextField(...)),

你可以找到更多关于未绑定高度&宽度

最新更新