Flutter firebase实时颤振选项卡中的数据显示不正确
我在从选项卡栏视图中的firebase实时数据库获取数据时遇到问题。从实时数据库颤振在选项卡视图中显示的数据。。但最后一个选项卡数据在所有选项卡中显示相同。所有选项卡栏视图数据都不同,但它在所有选项卡中显示一个选项卡的数据。我认为它用我们在上一个标签上得到的数据覆盖了以前的数据Flutter firebase实时颤振选项卡中的数据显示不正确,flutter,android-studio,tabbar,Flutter,Android Studio,Tabbar,我在从选项卡栏视图中的firebase实时数据库获取数据时遇到问题。从实时数据库颤振在选项卡视图中显示的数据。。但最后一个选项卡数据在所有选项卡中显示相同。所有选项卡栏视图数据都不同,但它在所有选项卡中显示一个选项卡的数据。我认为它用我们在上一个标签上得到的数据覆盖了以前的数据 loadsubcategories(){ ref=FirebaseDatabase.instance; ref.reference().child('Categories').child(id).child(“子类别
loadsubcategories(){
ref=FirebaseDatabase.instance;
ref.reference().child('Categories').child(id).child(“子类别”)
//.onValue
//.听((事件){
//var snapshot=event.snapshot;
.一次
.then((数据快照快照){
如果(snapshot.value!=null){
var keys=snapshot.value.keys;
var值=snapshot.value;
//listtab=新列表();
listtab.clear();
for(变量键入键){
打印(键);
TabNews data=TabNews(
值[键][“子类别”],
0,
值[键]['id'],
);
listtab.add(数据);
}
}否则{
印刷品(“chal Chutti kr”);
}
//设置状态(){
//
// });
设置状态(){
//_controller=TabController(长度:listtab.length,初始索引:0);
//_controller.addListener(_handleabselection);
});
}
);
}
tabbarviewdata(字符串子类别ID){
打印(“fajasl”+id);
cardref=FirebaseDatabase.instance;
cardref.reference().child('Categories').child(id).child('Subcategories').child(subcategorid).child(“个性”)
//.onValue
//.听((事件){
//var snapshot=event.snapshot;
.一次
.then((数据快照快照){
如果(snapshot.value!=null){
var keys=snapshot.value.keys;
var值=snapshot.value;
//cardlist=新列表();
cardlist.clear();
for(变量键入键){
//打印(键);
卡片列表数据=卡片列表(
值[键]['image'],
值[键]['name'],
值[键]['designation'],
值[键]['subscribeCount'],
"",
假,,
值[键]['id'],
);
卡片列表。添加(数据);
//印刷品(数据名称);
}
}
否则{
打印(“无数据”);
}
}
);
返回
ListView.builder(
物品计数:1,
itemBuilder:(上下文,i){
返回列(
儿童:[
对于(int i=0;iloadsubcategories() {
ref = FirebaseDatabase.instance;
ref.reference().child('Categories').child(id).child("Subcategories")
// .onValue
// .listen((event) {
// var snapshot = event.snapshot;
.once()
.then((DataSnapshot snapshot){
if(snapshot.value != null){
var keys = snapshot.value.keys;
var value = snapshot.value;
//listtab = new List();
listtab.clear();
for (var key in keys) {
print(key);
TabNews data = TabNews(
value[key]['subcategory'],
0,
value[key]['id'],
);
listtab.add(data);
}
} else {
print("chal Chutti kr");
}
// setState(() {
//
// });
setState(() {
// _controller = TabController( length: listtab.length, initialIndex: 0);
// _controller.addListener(_handleTabSelection);
});
}
);
}
tabbarviewdata(String subcategoryid) {
print("fajasl"+id);
cardref = FirebaseDatabase.instance;
cardref.reference().child('Categories').child(id).child("Subcategories").child(subcategoryid).child("Personalities")
// .onValue
// .listen((event) {
// var snapshot = event.snapshot;
.once()
.then((DataSnapshot snapshot){
if(snapshot.value != null){
var keys = snapshot.value.keys;
var value = snapshot.value;
// cardlist= new List();
cardlist.clear();
for (var key in keys) {
// print(key);
CardList data = CardList(
value[key]['image'],
value[key]['name'],
value[key]['designation'],
value[key]['subscribeCount'],
"",
false,
value[key]['id'],
);
cardlist.add(data);
// print(data.designation);
}
}
else {
print("No Data");
}
}
);
return
ListView.builder(
itemCount: 1,
itemBuilder: (context, i) {
return Column(
children: [
for (int i = 0; i < cardlist.length; i++)
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 70,
right: MediaQuery.of(context).size.width / 30),
child: GestureDetector(
onTap: () {
dialogDisplay(context, i);
// displaysnaplist(context, i);
},
child: Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
elevation: 0,
child: Row(
//mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(
top: ScreenUtil().setHeight(40),
left: ScreenUtil().setHeight(40),
bottom: ScreenUtil().setHeight(40),
),
child: Container(
height: ScreenUtil().setHeight(250),
width: ScreenUtil().setHeight(250),
child: Text(""),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
// scale: 20,
image: NetworkImage(
cardlist[i].image,
),
fit: BoxFit.cover,
// fit: BoxFit.fitWidth
),
),
),
),
SizedBox(
width: ScreenUtil().setWidth(50),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery
.of(context)
.size
.height /
28),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
cardlist[i].name,
style: TextStyle(
decoration: TextDecoration.none,
fontFamily: 'roboto',
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
SizedBox(
height:
MediaQuery
.of(context)
.size
.height /
120,
),
Text(
cardlist[i].designation,
style: TextStyle(
decoration: TextDecoration.none,
fontFamily: 'roboto',
fontSize: 10,
color: Colors.blue,
),
),
SizedBox(
height:
MediaQuery
.of(context)
.size
.height /
120,
),
Row(
children: [
Text(
cardlist[i].subscribeCount.toString(),
style: TextStyle(
decoration: TextDecoration.none,
fontFamily: 'roboto',
color: Colors.grey[700],
fontSize: 10,
),
),
SizedBox(
width: MediaQuery
.of(context)
.size
.width /
100,
),
Text(
'Subscribed',
style: TextStyle(
decoration: TextDecoration.none,
fontFamily: 'roboto',
color: Colors.grey[700],
fontSize: 10),
),
],
),
],
),
),
),
Padding(
padding: EdgeInsets.only(
top: ScreenUtil().setHeight(120),
right: ScreenUtil().setHeight(50),
),
child: Column(
children: [
Visibility(
visible: cardlist[i].show ?? true,
child: RaisedButton(
elevation: 0,
// minWidth: 100,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10.0),
),
color: Color(0xffF8D4D3),
child: Text(
cardlist[i].newstype,
style: TextStyle(
color: Color(0xffB53B38),
fontSize: 10),
),
onPressed: () {
dialogDisplay(context, i);
}),
),
],
),
)
],
),
),
),
),
),
],
);
});
// }
// );
}