Flutter get data from firebase and show on ui using Stream Builder

Flutter get data from firebase and show on ui using Stream Builder:



class LabelRepository{
Stream<List<Labels>> listOfLabels() {
  return reference      .snapshots()
      .map((event) => event.documents)
      .map((event) => event.map((e) => Labels.fromMap(e.data)).toList());
}//////////////////////////////////////////////////////////////////////////////////////

Expanded(
  child: StreamBuilder(
    stream: LabelRepository().listOfLabels(),    builder: (BuildContext context, snapshot) {
      if (!snapshot.hasData) {
        return CircularProgressIndicator();      }
      return Scrollbar(
        child: ListView.builder(
            shrinkWrap: true,            scrollDirection: Axis.vertical,            itemCount: snapshot.data.length,            itemBuilder: (BuildContext context, int index) {
              var color = 0xFFF+snapshot.data[index].color;              return Row(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.all(8.0),                    child: Container(
                      padding: EdgeInsets.all(18.0),                      height: 40,                      decoration: BoxDecoration(
                          shape: BoxShape.circle,                          color: Colors.green),                      child: Text(" "),                    ),                  ),                  Expanded(
                    child: ListTile(
                      title: Text(
                        snapshot.data[index].title,                        style: TextStyle(
                            color: Colors.black, fontSize: 14),                      ),                      onTap: () {
                        Navigator.pop(context);                      },

Comments

  1. Thanks for such useful information, It is true that now if you want to grow your business you will surely need the mobile application of your business. But for that purpose everyone needs best Flutter app development company in Toronto.

    ReplyDelete
  2. I just want to thank you for sharing your information and your site or blog this is a simple but nice article I have ever seen i like it i learn something today.

    flutter entwicklung

    ReplyDelete

Post a Comment