简体   繁体   中英

Why i cant display the image in flutter dart?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM