skip to Main Content

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

2

Answers


  1. 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']),
          ],
        );
        }
    
    Login or Signup to reply.
  2. You can use this for displaying a 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']);
            }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search