Flutter The error I received when firebase listing

176

In your MyDatabase class, you have infiyat as type String, but it is comming in as a double i.e "85.55". Either change the type in your database or your class.

Share:
176
Ceyhun Er
Author by

Ceyhun Er

Updated on November 19, 2022

Comments

  • Ceyhun Er
    Ceyhun Er over 1 year

    I've been investigating a problem for days. This is how I use Firebase Database. My goal is to list the contents of the firebase database. but every time I try, I get an error.

    -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"
    

    I want to list the contents of the database. but I get this error.

    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
    

    these are the codes I use

    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),),
                  ],
                )
              ],
            ),
          ],
        ),
       ),
      );
      }
     }
    

    I Thanks in advance to friends who can help.