firebase,无法在数组中显示地图的记录到视图中
我将快照的结果传递到地图中。 从第一个角度来看,我在listView.builder中显示每个集合的每个文档。 每个记录都显示在卡中。 如果用户正在执行ONTAP,我想将上一个视图的详细信息显示为新视图。 但是,现在,我找不到如何在列表中显示每个记录。 在地图中,我有两个字段。 item_name =>字符串和itemchecked =>细绳 项目检查值在这里确定用户是否已选中该框。如果是,这意味着用户已经在列表中购买了产品。
在下面,您会找到我的代码。非常感谢您的帮助。值得赞赏。
body: Column(
children: [
Container(
height: MediaQuery.of(context).size.height /1.4,
width: MediaQuery.of(context).size.width,
child:StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser.uid)
.collection('lists')
.snapshots(),
builder: (context, snapshot){
QuerySnapshot data = snapshot.requireData;
return ListView.builder(
itemCount: data.size,
itemBuilder: (context, index){
Map item = data.docs[index].data();
final allrecords = item['allItems'];
/* print('items');
print (item);
print ('nbRecord');
print(item['allItems'].length.toString());*/
print('mon test');
print(item['allItems']);
print(allrecords);
return InkWell(
child: Card(
child: ListTile(
leading: Icon(Icons.skip_next_rounded),
title:Text((item['listName'])),
subtitle: Text(item['allItems'].length.toString())),
),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailScreen_CheckList_V3(item),));
import 'package:flutter/material.dart';
import 'package:gtd_official_sharped_focused/Constante/Const.dart';
import 'package:gtd_official_sharped_focused/Views/Lists/checklist_V3/ElementOfAListCompletedProgressIndicator.dart';
var itemChecked;
class DetailScreen_CheckList_V3 extends StatefulWidget {
final Map listName;
const DetailScreen_CheckList_V3(Map this.listName, {
Key key}) : super(key: key);
// DetailScreen_CheckList_V3({Key key,this.listName);
@override
_DetailScreen_CheckList_V3State createState() => _DetailScreen_CheckList_V3State(listName);
}
class _DetailScreen_CheckList_V3State extends State<DetailScreen_CheckList_V3> {
Map listName;
_DetailScreen_CheckList_V3State(
this.listName
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar (
title: Text('Your list items'),
leading:
InkWell(
child:
Icon(Icons.fast_rewind_outlined),
onTap: (){
Navigator.pop(context);
},),
),
body:
Padding(
padding: EdgeInsets.symmetric(horizontal: 0.0, vertical: 8.0),
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 36.0, vertical: 0.0),
height: 120,
child:Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
// Element_of_List_Badge(
// color: _color,
//codePoint: _task.codePoint,
//id: _hero.codePointId,
// ),
Container(
margin: EdgeInsets.only(bottom: 10.0, top:24.0),
child: Hero(
tag: 'List Name',
//tag: _hero.remainingTaskId,
child: Text(
"N# of Items",
style: Theme.of(context)
.textTheme
.body1
?.copyWith(color: Colors.grey[500]),
),
),
),
Container(
height: 100,
child: ListView(
children:[
Hero(
tag: 'List Name', //_hero.titleId,
child: Text(listName['allItems'].toString(),
style: Theme.of(context)
.textTheme
.title
?.copyWith(color: Colors.black54)),
),
ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: leadingIconMinSize,
minHeight: leadingIconMinSize,
maxWidth: leadingIconMaxSize,
maxHeight: leadingIconMaxSize,
),
child: IconButton(
icon: itemChecked == "true" ? Icon(
Icons.check_box,
color: Colors.blue,) :
Icon(Icons.check_box_outline_blank,
color: Colors.grey,),
onPressed: () {
setState(() {
if (itemChecked == 'true') {
itemChecked = 'false';
}
else {
itemChecked = 'true';
}
});
//TODO coder pour que case à cocher devienne pleine
}), //InkWell(child: Icon(Icons.check_box_outline_blank),
)
)]),
),
Spacer(),
/* ListView(
children: [
_getAllItems(),
],
),*/
Hero(
tag: 'hello66',
// tag: _hero.progressId,
child: ElementOfAListCompletedProgressIndicator(
color: Colors.red,
//progress: model.getTaskCompletionPercent(_task),
),
)
/* Hero(
tag: 'List Name', //_hero.titleId,
child: Text(listName,//_task.name,
style: Theme.of(context)
.textTheme
.title
?.copyWith(color: Colors.black54)),
),*/
],
),
)),
],
),
),
);
}
/* Widget _getAllItems() {
var snapshot = FirebaseFirestore.instance
.collection('currentUser')
.doc('uid')
.collection('lists')
.doc(listName)
.get();
//return snapshot;
}*/
}
I am passing the result of a snapshot into a map.
On the first view, I am displaying in a ListView.builder each document of a collection.
Each record is displayed into a Card.
If the user is doing an onTap, I want to display the details of the previous view into a new view.
But, right now, I can not find how do display each record into a list.
In the map, I have two fields. item_Name => String and itemChecked => String
itemChecked value is here to identify if the user have checked the box or not. If yes, that means that the user have bought the product in the list.
Below, you will find my code. Many thanks for your help. It is appreciated.
body: Column(
children: [
Container(
height: MediaQuery.of(context).size.height /1.4,
width: MediaQuery.of(context).size.width,
child:StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser.uid)
.collection('lists')
.snapshots(),
builder: (context, snapshot){
QuerySnapshot data = snapshot.requireData;
return ListView.builder(
itemCount: data.size,
itemBuilder: (context, index){
Map item = data.docs[index].data();
final allrecords = item['allItems'];
/* print('items');
print (item);
print ('nbRecord');
print(item['allItems'].length.toString());*/
print('mon test');
print(item['allItems']);
print(allrecords);
return InkWell(
child: Card(
child: ListTile(
leading: Icon(Icons.skip_next_rounded),
title:Text((item['listName'])),
subtitle: Text(item['allItems'].length.toString())),
),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailScreen_CheckList_V3(item),));
import 'package:flutter/material.dart';
import 'package:gtd_official_sharped_focused/Constante/Const.dart';
import 'package:gtd_official_sharped_focused/Views/Lists/checklist_V3/ElementOfAListCompletedProgressIndicator.dart';
var itemChecked;
class DetailScreen_CheckList_V3 extends StatefulWidget {
final Map listName;
const DetailScreen_CheckList_V3(Map this.listName, {
Key key}) : super(key: key);
// DetailScreen_CheckList_V3({Key key,this.listName);
@override
_DetailScreen_CheckList_V3State createState() => _DetailScreen_CheckList_V3State(listName);
}
class _DetailScreen_CheckList_V3State extends State<DetailScreen_CheckList_V3> {
Map listName;
_DetailScreen_CheckList_V3State(
this.listName
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar (
title: Text('Your list items'),
leading:
InkWell(
child:
Icon(Icons.fast_rewind_outlined),
onTap: (){
Navigator.pop(context);
},),
),
body:
Padding(
padding: EdgeInsets.symmetric(horizontal: 0.0, vertical: 8.0),
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 36.0, vertical: 0.0),
height: 120,
child:Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
// Element_of_List_Badge(
// color: _color,
//codePoint: _task.codePoint,
//id: _hero.codePointId,
// ),
Container(
margin: EdgeInsets.only(bottom: 10.0, top:24.0),
child: Hero(
tag: 'List Name',
//tag: _hero.remainingTaskId,
child: Text(
"N# of Items",
style: Theme.of(context)
.textTheme
.body1
?.copyWith(color: Colors.grey[500]),
),
),
),
Container(
height: 100,
child: ListView(
children:[
Hero(
tag: 'List Name', //_hero.titleId,
child: Text(listName['allItems'].toString(),
style: Theme.of(context)
.textTheme
.title
?.copyWith(color: Colors.black54)),
),
ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: leadingIconMinSize,
minHeight: leadingIconMinSize,
maxWidth: leadingIconMaxSize,
maxHeight: leadingIconMaxSize,
),
child: IconButton(
icon: itemChecked == "true" ? Icon(
Icons.check_box,
color: Colors.blue,) :
Icon(Icons.check_box_outline_blank,
color: Colors.grey,),
onPressed: () {
setState(() {
if (itemChecked == 'true') {
itemChecked = 'false';
}
else {
itemChecked = 'true';
}
});
//TODO coder pour que case à cocher devienne pleine
}), //InkWell(child: Icon(Icons.check_box_outline_blank),
)
)]),
),
Spacer(),
/* ListView(
children: [
_getAllItems(),
],
),*/
Hero(
tag: 'hello66',
// tag: _hero.progressId,
child: ElementOfAListCompletedProgressIndicator(
color: Colors.red,
//progress: model.getTaskCompletionPercent(_task),
),
)
/* Hero(
tag: 'List Name', //_hero.titleId,
child: Text(listName,//_task.name,
style: Theme.of(context)
.textTheme
.title
?.copyWith(color: Colors.black54)),
),*/
],
),
)),
],
),
),
);
}
/* Widget _getAllItems() {
var snapshot = FirebaseFirestore.instance
.collection('currentUser')
.doc('uid')
.collection('lists')
.doc(listName)
.get();
//return snapshot;
}*/
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能对别人有用,这是解决方案
It might be usefull to someone else, here is the solution