有人可以向我解释如何使用FutureBuilder内部的ListView.Builder中的itemCount。
目前,我的FirebaseCloud Store只有一个Document,而我的应用返回的是文档的无限列表,
我尝试使用final PressedState pressController = Get.put(PressedState ());
return MaterialButton(
onPressed: () {
pressController.changeStatus();
},
child:
pressController.pressedBool
? Container(...) : Container(...)),
但是,得到错误:itemCount: snapshot.data.documents.length,
编辑,该文件只能显示一次,如果与UID相关的文件不止一个,则仅显示一次。
这是我的代码
Class 'DocumentSnapshot' has no instance getter 'documents'. Receiver: Instance of 'DocumentSnapshot' Tried calling: documents
答案 0 :(得分:1)
您需要这样的长度。
itemCount: snapshot.data.data().length,
答案 1 :(得分:1)
您必须这样做:
extern crate futures;
extern crate tokio;
extern crate websocket;
use websocket::Message;
use websocket::result::WebSocketError;
use websocket::{ClientBuilder, OwnedMessage};
use websocket::header::{Headers, Authorization, Basic};
use websocket::futures::{Future, Stream, Sink};
use tokio_core::reactor::Core;
const CONNECTION: &'static str = "wss://some.remote.host.example.org:443/";
let mut core = Core::new()?;
let client = ClientBuilder::new(CONNECTION)?
.async_connect_secure(None)
.and_then(|(msg, _)| match msg {
Some(OwnedMessage::Text(response_txt)) => Ok(response_txt),
_ => Err(WebSocketError::ProtocolError(UNSUPPORTED_MSG_ERR)),
});
let response_message = core.run(client)?;
由于您只检索一个文档,因此在执行以下操作:
itemCount : 1
由于文档ID始终是唯一的,因此以上内容将始终检索一个文档。
答案 2 :(得分:0)
if (snapshot.hasData) {
print('okkk');
print(manuais.data()['nome']);
return Container(
padding: EdgeInsets.all(16),
child: ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot manuais = snapshot.data;
return Card(
color: Colors.grey[250],
child: Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
new Image.asset(
'Images/pdflogo.png',
width: 32,
),
Center(
child: Text(
(manuais.data()['nome'].toString()),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 16),
),
),
ButtonBar(
children: <Widget>[
FlatButton(
child: const Text(
'Compartilhar / Download'),
onPressed: () async {
var request = await HttpClient()
.getUrl(Uri.parse(manuais
.data()['documento']));
var response =
await request.close();
Uint8List bytes =
await consolidateHttpClientResponseBytes(
response);
await Share.file(
'ESYS AMLOG',
'Manual.pdf',
bytes,
'image/jpg') ...(all your brackets go here)
}