Home > Software design >  Why i cant display the image in flutter dart?
Why i cant display the image in flutter dart?

Time:12-14

I cannot display the image, but all of the data is display for example name

    return FutureBuilder<DocumentSnapshot>(
      future: result.doc(foodId).get(),
      builder: ((context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          Map<String, dynamic> data =
              snapshot.data!.data() as Map<String, dynamic>;
          return Text('Name:'  
              '${data['name']}'  
              "\n"
                  'Description:'  
              '${data['description']}'  
              "\n"
                  'Energy:'  
              ' '  
              '${data['energy']}'  
              '${data['image']}');
        }

CodePudding user response:

you can use this for displaying network image

return FutureBuilder<DocumentSnapshot>(
      future: result.doc(foodId).get(),
      builder: ((context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          Map<String, dynamic> data =
              snapshot.data!.data() as Map<String, dynamic>;
          return Image.network(data['image']);
        }

CodePudding user response:

You can not display image from the text widget, you need to use the image widget for that

return FutureBuilder<DocumentSnapshot>(
    future: result.doc(foodId).get(),
    builder: ((context, snapshot) {
    if (snapshot.connectionState == ConnectionState.done) {
    Map<String, dynamic> data =
    snapshot.data!.data() as Map<String, dynamic>;
    return Column(
      children: [
        Text('Name:'  
        '${data['name']}'  
        "\n"
        'Description:'  
        '${data['description']}'  
        "\n"
        'Energy:'  
        ' '  
        '${data['energy']}'  
        '${data['image']}'),
        Image.network('${data['image']}'),
      ],
    );
    }
  • Related