Flutter 我在 firebase listing 时收到的错误
Flutter The error I received when firebase listing
几天来我一直在调查一个问题。
这就是我使用 Firebase 数据库的方式。
我的目标是列出 firebase 数据库的内容。
但每次尝试时,我都会出错。
-urunler
-elyapimi
--LB445dadwSDA5
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
--LbVuRaL2eslQ4deD-C7
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
我想列出数据库的内容。
但是我得到了这个错误。
E/flutter ( 9624): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled
Exception: type 'double' is not a subtype of type 'String'
E/OpenGLRenderer( 9624): SFEffectCache:clear(), mSize = 0
W/ManagedEGLContext( 9624): doTerminate failed: EGL count is 2 but
managed count is 1
这些是我使用的代码
import 'package:denemeflutter/database.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class YenilenCicek extends StatefulWidget{
@override
State<StatefulWidget> createState() => YenilenCicekState();
}
class YenilenCicekState extends State with TickerProviderStateMixin{
static const EndColor = Color.fromARGB(255, 150, 202, 230);
static const StartColor = Color.fromARGB(255, 64, 222, 194);
static const softmavi = Color.fromARGB(255, 142, 226, 210);
List<MyDatabase> list = [];
@override
void initState() {
super.initState();
DatabaseReference postRef =
FirebaseDatabase.instance.reference().child("urunler").child("elyapimi");
postRef.once().then((DataSnapshot snap)
{
var keys = snap.value.keys;
var data = snap.value;
list.clear();
for(var key in keys)
{
MyDatabase myDatabase = new MyDatabase
(
data[key]["ad"],
data[key]["imageurl"],
data[key]["infiyat"],
data[key]["fiyat"]);
list.add(myDatabase);
}
setState(() {
print("Lenght : $list.lenght");
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
height: 100,
width: double.maxFinite,
color: Colors.white,
),
Positioned(
child:Container(
padding: EdgeInsets.only(left: 170, top: 30),
height: 100.0,
decoration: BoxDecoration(
gradient: new LinearGradient(colors: [StartColor,EndColor]),
borderRadius: BorderRadius.only(bottomLeft:
Radius.elliptical(300, 10) , bottomRight: Radius.elliptical(300, 10)
) ,
),
child: null,
),
),
Positioned(
child: Container(
padding: EdgeInsets.only(top: 35, left: 0),
child: FlatButton(
padding: EdgeInsets.only(left: 0,right: 25),
onPressed: (){Navigator.pop(context);},
child: Icon(Icons.keyboard_arrow_left,color:
Colors.white,size: 50,)
),
),
),
Positioned(
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(bottom: 525),
child: Text("YENİLEN ÇİÇEKLER", style: TextStyle(color:
Colors.white, fontSize: 19),),
)
),
Container(
margin: EdgeInsets.only(top: 130),
child: list.length == 0 ? new Text("Bu Kategoride\nÜrün
Bulunmamaktadır.", textAlign: TextAlign.center,) : new
ListView.builder(
itemCount: list.length,
itemBuilder: (_,index){
return ListUI(list[index].title, list[index].imageurl,
list[index].promoprice, list[index].price);
},
),
)
],
),
);
}
Widget ListUI(String ad,String imageurl,String infiyat,String fiyat,)
{
return new Card(
elevation: 10.0,
margin: EdgeInsets.all(15.0),
child: new Container(
padding: new EdgeInsets.all(14.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Image.network("$imageurl"),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("$ad", style: TextStyle(color: Color.fromARGB(255, 64,
222, 194), fontSize: 18, ),textAlign: TextAlign.center,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("$infiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
Text("$fiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
],
)
],
),
],
),
),
);
}
}
在此先感谢可以提供帮助的朋友。
在您的 MyDatabase class 中,您将 infiyat 作为字符串类型,但它以双精度形式出现,即“85.55”。更改数据库或 class.
中的类型
几天来我一直在调查一个问题。 这就是我使用 Firebase 数据库的方式。 我的目标是列出 firebase 数据库的内容。 但每次尝试时,我都会出错。
-urunler
-elyapimi
--LB445dadwSDA5
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
--LbVuRaL2eslQ4deD-C7
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
我想列出数据库的内容。 但是我得到了这个错误。
E/flutter ( 9624): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled
Exception: type 'double' is not a subtype of type 'String'
E/OpenGLRenderer( 9624): SFEffectCache:clear(), mSize = 0
W/ManagedEGLContext( 9624): doTerminate failed: EGL count is 2 but
managed count is 1
这些是我使用的代码
import 'package:denemeflutter/database.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class YenilenCicek extends StatefulWidget{
@override
State<StatefulWidget> createState() => YenilenCicekState();
}
class YenilenCicekState extends State with TickerProviderStateMixin{
static const EndColor = Color.fromARGB(255, 150, 202, 230);
static const StartColor = Color.fromARGB(255, 64, 222, 194);
static const softmavi = Color.fromARGB(255, 142, 226, 210);
List<MyDatabase> list = [];
@override
void initState() {
super.initState();
DatabaseReference postRef =
FirebaseDatabase.instance.reference().child("urunler").child("elyapimi");
postRef.once().then((DataSnapshot snap)
{
var keys = snap.value.keys;
var data = snap.value;
list.clear();
for(var key in keys)
{
MyDatabase myDatabase = new MyDatabase
(
data[key]["ad"],
data[key]["imageurl"],
data[key]["infiyat"],
data[key]["fiyat"]);
list.add(myDatabase);
}
setState(() {
print("Lenght : $list.lenght");
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
height: 100,
width: double.maxFinite,
color: Colors.white,
),
Positioned(
child:Container(
padding: EdgeInsets.only(left: 170, top: 30),
height: 100.0,
decoration: BoxDecoration(
gradient: new LinearGradient(colors: [StartColor,EndColor]),
borderRadius: BorderRadius.only(bottomLeft:
Radius.elliptical(300, 10) , bottomRight: Radius.elliptical(300, 10)
) ,
),
child: null,
),
),
Positioned(
child: Container(
padding: EdgeInsets.only(top: 35, left: 0),
child: FlatButton(
padding: EdgeInsets.only(left: 0,right: 25),
onPressed: (){Navigator.pop(context);},
child: Icon(Icons.keyboard_arrow_left,color:
Colors.white,size: 50,)
),
),
),
Positioned(
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(bottom: 525),
child: Text("YENİLEN ÇİÇEKLER", style: TextStyle(color:
Colors.white, fontSize: 19),),
)
),
Container(
margin: EdgeInsets.only(top: 130),
child: list.length == 0 ? new Text("Bu Kategoride\nÜrün
Bulunmamaktadır.", textAlign: TextAlign.center,) : new
ListView.builder(
itemCount: list.length,
itemBuilder: (_,index){
return ListUI(list[index].title, list[index].imageurl,
list[index].promoprice, list[index].price);
},
),
)
],
),
);
}
Widget ListUI(String ad,String imageurl,String infiyat,String fiyat,)
{
return new Card(
elevation: 10.0,
margin: EdgeInsets.all(15.0),
child: new Container(
padding: new EdgeInsets.all(14.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Image.network("$imageurl"),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("$ad", style: TextStyle(color: Color.fromARGB(255, 64,
222, 194), fontSize: 18, ),textAlign: TextAlign.center,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("$infiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
Text("$fiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
],
)
],
),
],
),
),
);
}
}
在此先感谢可以提供帮助的朋友。
在您的 MyDatabase class 中,您将 infiyat 作为字符串类型,但它以双精度形式出现,即“85.55”。更改数据库或 class.
中的类型