Load firestore flutter information

Asked

Viewed 48 times

1

Can anyone tell me where I’m wrong with this code?

import 'package:anime_app/models/home_page.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

class AnimeList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder(
          stream: Firestore.instance.collection('animes').snapshots(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (!snapshot.hasData) return const Text('Carregando...');

            return ListView.builder(
              itemCount: snapshot.data.documents.length,
              itemBuilder: (BuildContext context, int index) {
                DocumentSnapshot doc = snapshot.data.documents[index];

                return ListView(
                  children: [
                    Container(
                      width: 100,
                      height: 100,
                      color: Colors.black,
                      decoration: BoxDecoration(
                        image: DecorationImage(
                            image: NetworkImage(doc['link_img'])),
                      ),
                    ),
                  ],
                );
              },
            );
          }),
    );
  }
}
  • (Read in relaxed tone) I think you are wrong in the question... What is happening or not? What is the expected result? Do any errors? xD

1 answer

0


Welcome!

My dear, first of all, ensure that your code returns all the elements of the collection you want. After that you inject the elements into your list. There is a lot of data reading "permission" problem, which you can easily detect with a simple code:

void _onPressed() {
  firestoreInstance.collection("orders").get().then((querySnapshot) {
    querySnapshot.docs.forEach((result) {
      print(result.data());
    });
  });
}

Then I recommend you take a look at this component:

Cloud Firestore Plugin for Flutter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.