Unable to get data from Firestore using Flutter

118

I would suggest sticking to the way it's done in the docs, especially if you are new to firestore.

Not only will this actually work but it will also be more efficient and easier when handling changes.

Here is your code modified, hope this works for you:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    CollectionReference canUSupport = FirebaseFirestore.instance.collection('CanUSupport');
    var foundations = [
      {
        'Name': 'Sanshil Foundation for Welfare',
        'Requirements': ['Chairs (6)', 'Tables (234)'],
      },
      {
        'Name': 'Ram Kala Sadan Trust',
        'Requirements': ['Chairs (5)', 'Tables (7)', 'Pencils (7899)'],
      },
    ];
    var call = [
      {
        'Name': 'Sanshil Foundation for Welfare',
        'Number': '098733 29733',
      },
      {
        'Name': 'Ram Kala Sadan Trust',
        'Number': "072918 25705",
      },
    ];

    var location = [
      'https://www.google.com/maps/place/Sanshil+foundation/@28.4251672,77.0588316,17z/data=!4m8!1m2!2m1!1ssanshil+foundation+project+bagiya!3m4!1s0x390d188208cdac35:0xba90a7675ebc860d!8m2!3d28.4253544!4d77.0630471',
      'https://www.google.co.in/maps/place/Smile+Foundation/@28.5578955,77.1731021,13z/data=!4m8!1m2!2m1!1sSmile+foundation!3m4!1s0x390ce270271eadef:0xb8e42773f9d463ab!8m2!3d28.5578955!4d77.208121',
    ];
    var images = [
      'assets/logos/Sanshil-Logo.png',
      'assets/logos/bagiya logo.jpg',
    ];

    var site = [
      {
        'Name': 'Sanshil Foundation for Welfare',
        'site': 'https://sanshil.com/',
      },
      {
        'Name': 'Ram Kala Sadan Trust',
        'site': 'https://www.ramkalasadan.org/',
      }
    ];
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
    return new MaterialApp(
      color: Colors.yellow,
      home: DefaultTabController(
        length: 3,
        child: new Scaffold(
          appBar: AppBar(
            title: Text(
              'CanUSupport',
              style: TextStyle(
                  fontSize: 30, color: Color.fromRGBO(1, 1, 1, 1), fontFamily: 'Pt_Mono'),
            ),
            backgroundColor: Color(0xffDB9D12),
          ),
          body: TabBarView(
            children: [
              new Scaffold(
                backgroundColor: Color(0xffDB9D12),
                body: StreamBuilder<QuerySnapshot>(
                  stream: canUSupport.snapshots(),
                  builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
                    if (snapshot.hasError) {
                      return Text('Something went wrong');
                    }

                    if (snapshot.connectionState == ConnectionState.waiting) {
                      return Center(child: CircularProgressIndicator());
                    }

                    return ListView.builder(
                        itemCount: snapshot.data.size,
                        itemBuilder: (context, index) {
                          return Container(
                            margin: EdgeInsets.all(16),
                            child: Stack(
                              children: <Widget>[
                                Card(
                                  elevation: 12,
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(30),
                                  ),
                                  color: Colors.white,
                                  child: Container(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 24.0, vertical: 18),
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.circular(30),
                                      gradient: LinearGradient(colors: [
                                        Color.fromRGBO(204, 204, 204, 1),
                                        Color.fromRGBO(179, 179, 179, 1),
                                        Color.fromRGBO(140, 140, 140, 1),
                                      ]),
                                    ),
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: <Widget>[
                                        Container(
                                          padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
                                          child: CircleAvatar(
                                              radius: 45,
                                              backgroundImage: AssetImage(images[index])),
                                        ),
                                        Expanded(
                                          child: Column(
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            mainAxisSize: MainAxisSize.min,
                                            children: <Widget>[
                                              Text(
                                                snapshot.data.docs[index].data()['Name'],
                                                style: Theme.of(context)
                                                    .textTheme
                                                    .headline5
                                                    .copyWith(color: Colors.white),
                                              ),
                                              Column(
                                                children: <Widget>[
                                                  for (var item in foundations[index]
                                                  ['Requirements'])
                                                    Text('• ' + item)
                                                ],
                                              )
                                            ],
                                          ),
                                        ),
                                        Column(children: [
                                          ClipOval(
                                            child: Material(
                                              color: Colors.white, // button color
                                              child: InkWell(
                                                splashColor:
                                                Color(0xFFbc8510), // inkwell color
                                                child: SizedBox(
                                                    width: 56,
                                                    height: 56,
                                                    child: Icon(Icons.call)),
                                                onTap: () {
                                                  _launchUrlcall(call[index]['Number']);
                                                },
                                              ),
                                            ),
                                          ),
                                          Padding(
                                            padding: EdgeInsets.all(5.0),
                                          ),
                                          ClipOval(
                                            child: Material(
                                              color: Colors.white, // button color
                                              child: InkWell(
                                                splashColor:
                                                Color(0xFFbc8510), // inkwell color
                                                child: SizedBox(
                                                    width: 56,
                                                    height: 56,
                                                    child: Icon(Icons.map)),
                                                onTap: () {
                                                  _launchMapsUrl(
                                                    location[index],
                                                  );
                                                },
                                              ),
                                            ),
                                          ),
                                          Padding(
                                            padding: EdgeInsets.all(5.0),
                                          ),
                                          ClipOval(
                                            child: Material(
                                              color: Colors.white, // button color
                                              child: InkWell(
                                                splashColor:
                                                Color(0xFFbc8510), // inkwell color
                                                child: SizedBox(
                                                    width: 56,
                                                    height: 56,
                                                    child: Icon(Icons.web_sharp)),
                                                onTap: () {
                                                  _launchUrlweb(site[index]['site']);
                                                },
                                              ),
                                            ),
                                          ),
                                        ]),
                                      ],
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          );
                        });
                  },
                ),
              ),
              new Container(
                child: login_caller(),
              ),
              new Container(
                padding: EdgeInsets.symmetric(
                  horizontal: 10.0,
                  vertical: 100.0,
                ),
                height: double.infinity,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [
                      Color(0xFFf7dca1),
                      Color(0xFFf1c15b),
                      Color(0xFFeba714),
                      Color(0xFFbc8510),
                    ],
                    stops: [0.1, 0.4, 0.7, 0.9],
                  ),
                ),
                child: SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        'About us',
                        style: TextStyle(
                            color: Colors.white,
                            fontFamily: 'OpenSans',
                            fontSize: 30,
                            fontWeight: FontWeight.bold),
                      ),
                      Padding(padding: EdgeInsets.symmetric(vertical: 10.0)),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: <Widget>[
                          GestureDetector(
                            onTap: () {
                              _launchURLsite();
                            },
                            child: Container(
                              height: 60.0,
                              width: 60.0,
                              child: InkWell(
                                splashColor: Color(0xFFbc8510),
                              ),
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                    color: Colors.black26,
                                    offset: Offset(0, 2),
                                    blurRadius: 6.0,
                                  ),
                                ],
                                image: DecorationImage(
                                  image: NetworkImage(
                                      'https://www.googlewatchblog.de/wp-content/uploads/google-logo-perfekt.jpg'),
                                ),
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              _launchURLface();
                            },
                            child: Container(
                              height: 60.0,
                              width: 60.0,
                              child: InkWell(
                                splashColor: Color(0xFFbc8510),
                              ),
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                    color: Colors.black26,
                                    offset: Offset(0, 2),
                                    blurRadius: 6.0,
                                  ),
                                ],
                                image: DecorationImage(
                                  image: NetworkImage(
                                      'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTWHNqSKP0g_42wo-gQv1azrnztIYv1RbZKnQ&usqp=CAU'),
                                ),
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              _launchURLinsta();
                            },
                            child: Container(
                              height: 60.0,
                              width: 60.0,
                              child: InkWell(
                                splashColor: Color(0xFFbc8510),
                              ),
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                    color: Colors.black26,
                                    offset: Offset(0, 2),
                                    blurRadius: 6.0,
                                  ),
                                ],
                                image: DecorationImage(
                                  image: NetworkImage(
                                      'https://www.pollutionprobe.org/wp-content/uploads/insta-logo-300x300.png'),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Padding(padding: EdgeInsets.symmetric(vertical: 10.0)),
                      Text(
                        'Divij Dhiraaj',
                        style: TextStyle(
                            color: Colors.white,
                            fontFamily: 'OpenSans',
                            fontSize: 30,
                            fontWeight: FontWeight.bold),
                        textAlign: TextAlign.left,
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(
                          horizontal: 20.0,
                          vertical: 15.0,
                        ),
                        child: Text(
                          'Hi! My name is Divij Dhiraaj and I\'m the co-founder of CanUsupport. I’m a Seventeen year old student studying the The Shri Ram School , Aravali. \n \n When Aryan first approached me with the idea of building a platform to connect the less- known NGOs who are in dire need of funds, I resonated with his though process for that is same stumbling block me and my family encounter when trying to donate. Most potential donors are only aware of the well established NGOs , not knowing that there might just be a smaller NGO in their area ,working towards community well-fare, lacking funds and donations. \n \n While creating this site , that was our goal: to connect the less-established NGOs with donors so that the effect of their donations is maximised.',
                          style: TextStyle(
                              color: Colors.white,
                              fontFamily: 'OpenSans',
                              fontSize: 16,
                              fontWeight: FontWeight.bold),
                          textAlign: TextAlign.left,
                        ),
                      ),
                      Text(
                        'Aryan Jalota',
                        style: TextStyle(
                            color: Colors.white,
                            fontFamily: 'OpenSans',
                            fontSize: 30,
                            fontWeight: FontWeight.bold),
                        textAlign: TextAlign.left,
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(
                          horizontal: 20.0,
                          vertical: 15.0,
                        ),
                        child: Text(
                          'Hi! I\’m Aryan Jalota and I’m the founder of CanUSupport. I\’m a seventeen year old student currently studying in the Shri Ram School, Aravali. \n \n My family and I have been active contributors to many NGOs, but there was one challenge we faced the most when it came to donating – what should we donate? For instance, the first thing which comes to our mind will be stationary and notebooks for NGOs and learning centres; however, NGOs receive these donations in bulk from various people, and the societal impact that donors want to make is minimised. \n \n Therefore, I decided to create a platform over the summer which can directly connect various NGOs and learning centres to the local community. This way, donors can directly donate according to the requirements of the NGOs, ultimately maximising the impact on the society.',
                          style: TextStyle(
                              color: Colors.white,
                              fontFamily: 'OpenSans',
                              fontSize: 16,
                              fontWeight: FontWeight.bold),
                          textAlign: TextAlign.left,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          bottomNavigationBar: new TabBar(
            tabs: [
              Tab(
                icon: new Icon(Icons.home),
              ),
              Tab(
                icon: new Icon(Icons.perm_identity),
              ),
              Tab(
                icon: new Icon(Icons.settings),
              )
            ],
            labelColor: Colors.yellow,
            unselectedLabelColor: Colors.black,
            indicatorSize: TabBarIndicatorSize.label,
            indicatorPadding: EdgeInsets.all(5.0),
            indicatorColor: Colors.red,
          ),
          backgroundColor: Color(0xff707070),
        ),
      ),
    );
  }

  _launchURLsite() async {
    const url = 'https://canusupport.com/';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  _launchURLinsta() async {
    const url = 'https://www.instagram.com/canusupport/';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  _launchUrlcall(String url) async {
    if (await canLaunch(url)) {
      launch(url);
    } else {
      throw "Could not launch $url";
    }
  }

  _launchMapsUrl(String loca) async {
    final url = loca;
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  _launchUrlmail(String url) async {
    if (await canLaunch(url)) {
      launch(url);
    } else {
      throw "Could not launch $url";
    }
  }

  _launchURLface() async {
    const url = 'https://www.facebook.com/canusupport/';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

  _launchUrlweb(String url) async {
    if (await canLaunch(url)) {
      launch(url);
    } else {
      throw "Could not launch $url";
    }
  }
}
Share:
118
Recondit
Author by

Recondit

Updated on December 07, 2022

Comments

  • Recondit
    Recondit over 1 year

    I am trying to retrieve some data from cloud Firestore using flutter. I used the circularprogress indicator to show that it is still getting data , but it keeps on going as if it is not receiveing any data. I am new to flutter so I have no clue why this is happening and I've tried everything (probably it has something to do with setting state but I am not really clear with that concept)

    I am not getting any error , but the app isn't getting the info from the Firestore database. Sharing the full code

    Full Code

    import 'package:cloud_firestore/cloud_firestore.dart';
    import 'package:firebase_core/firebase_core.dart';
    import 'package:flutter/material.dart';
    import 'package:url_launcher/url_launcher.dart';
    
    
    
    import 'login_caller.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
    // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
    // This widget is the home page of your application. It is stateful, meaning
    // that it has a State object (defined below) that contains fields that affect
    // how it looks.
    
    // This class is the configuration for the state. It holds the values (in this
    // case the title) provided by the parent (in this case the App widget) and
    // used by the build method of the State. Fields in a Widget subclass are
    // always marked "final".
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        Future getdata() async{
          final firestore =FirebaseFirestore.instance;
          await Firebase.initializeApp();
          QuerySnapshot snapshot =await firestore.collection('CanUSupport').get();
          return await snapshot.docs;
        }
        var document = [];
        var foundations = [
          {
            'Name': 'Sanshil Foundation for Welfare',
            'Requirements': ['Chairs (6)', 'Tables (234)'],
          },
          {
            'Name': 'Ram Kala Sadan Trust',
            'Requirements': ['Chairs (5)', 'Tables (7)', 'Pencils (7899)'],
          },
        ];
        var call = [
          {
            'Name': 'Sanshil Foundation for Welfare',
            'Number': '098733 29733',
          },
          {
            'Name': 'Ram Kala Sadan Trust',
            'Number': "072918 25705",
          },
        ];
    
        var location = [
          'https://www.google.com/maps/place/Sanshil+foundation/@28.4251672,77.0588316,17z/data=!4m8!1m2!2m1!1ssanshil+foundation+project+bagiya!3m4!1s0x390d188208cdac35:0xba90a7675ebc860d!8m2!3d28.4253544!4d77.0630471',
          'https://www.google.co.in/maps/place/Smile+Foundation/@28.5578955,77.1731021,13z/data=!4m8!1m2!2m1!1sSmile+foundation!3m4!1s0x390ce270271eadef:0xb8e42773f9d463ab!8m2!3d28.5578955!4d77.208121',
        ];
        var images = [
          'assets/logos/Sanshil-Logo.png',
          'assets/logos/bagiya logo.jpg',
        ];
    
        var site = [
          {
            'Name': 'Sanshil Foundation for Welfare',
            'site': 'https://sanshil.com/',
          },
          {
            'Name': 'Ram Kala Sadan Trust',
            'site': 'https://www.ramkalasadan.org/',
          }
        ];
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
        return new MaterialApp(
          color: Colors.yellow,
          home: DefaultTabController(
            length: 3,
            child: new Scaffold(
              appBar: AppBar(
                title: Text(
                  'CanUSupport',
                  style: TextStyle(
                      fontSize: 30,
                      color: Color.fromRGBO(1, 1, 1, 1),
                      fontFamily: 'Pt_Mono'),
                ),
                backgroundColor: Color(0xffDB9D12),
              ),
              body: TabBarView(
                children: [
                  new Scaffold(
                    backgroundColor: Color(0xffDB9D12),
                    body: FutureBuilder(
                      future: getdata(),
    
    
                      builder: (context,snapshot){
                        if(!snapshot.hasData) {
                          return Center(child : CircularProgressIndicator());
                        }
                        else {
    
    
    
                          return ListView.builder(
                              itemCount: snapshot.data.length,
                              itemBuilder: (context, index) {
                                return Container(
                                  margin: EdgeInsets.all(16),
                                  child: Stack(
                                    children: <Widget>[
                                      Card(
                                        elevation: 12,
                                        shape: RoundedRectangleBorder(
                                          borderRadius: BorderRadius.circular(30),
                                        ),
                                        color: Colors.white,
                                        child: Container(
                                          padding: const EdgeInsets.symmetric(
                                              horizontal: 24.0, vertical: 18),
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.circular(30),
                                            gradient: LinearGradient(colors: [
                                              Color.fromRGBO(204, 204, 204, 1),
                                              Color.fromRGBO(179, 179, 179, 1),
                                              Color.fromRGBO(140, 140, 140, 1),
                                            ]),
                                          ),
                                          child: Row(
                                            mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                            children: <Widget>[
                                              Container(
                                                padding:
                                                EdgeInsets.fromLTRB(0, 0, 10, 0),
                                                child: CircleAvatar(
                                                    radius: 45,
                                                    backgroundImage:
                                                    AssetImage(images[index])),
                                              ),
                                              Expanded(
                                                child: Column(
                                                  crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                                  mainAxisSize: MainAxisSize.min,
                                                  children: <Widget>[
                                                    Text(
                                                      snapshot.data[index].data['Name'],
                                                      style: Theme.of(context)
                                                          .textTheme
                                                          .headline5
                                                          .copyWith(
                                                          color: Colors.white),
                                                    ),
                                                    Column(
                                                      children: <Widget>[
                                                        for (var item
                                                        in foundations[index]
                                                        ['Requirements'])
                                                          Text('• ' + item)
                                                      ],
                                                    )
                                                  ],
                                                ),
                                              ),
                                              Column(children: [
                                                ClipOval(
                                                  child: Material(
                                                    color: Colors.white, // button color
                                                    child: InkWell(
                                                      splashColor: Color(
                                                          0xFFbc8510), // inkwell color
                                                      child: SizedBox(
                                                          width: 56,
                                                          height: 56,
                                                          child: Icon(Icons.call)),
                                                      onTap: () {
                                                        _launchUrlcall(
                                                            call[index]['Number']);
                                                      },
                                                    ),
                                                  ),
                                                ),
                                                Padding(
                                                  padding: EdgeInsets.all(5.0),
                                                ),
                                                ClipOval(
                                                  child: Material(
                                                    color: Colors.white, // button color
                                                    child: InkWell(
                                                      splashColor: Color(
                                                          0xFFbc8510), // inkwell color
                                                      child: SizedBox(
                                                          width: 56,
                                                          height: 56,
                                                          child: Icon(Icons.map)),
                                                      onTap: () {
                                                        _launchMapsUrl(
                                                          location[index],
                                                        );
                                                      },
                                                    ),
                                                  ),
                                                ),
                                                Padding(
                                                  padding: EdgeInsets.all(5.0),
                                                ),
                                                ClipOval(
                                                  child: Material(
                                                    color: Colors.white, // button color
                                                    child: InkWell(
                                                      splashColor: Color(
                                                          0xFFbc8510), // inkwell color
                                                      child: SizedBox(
                                                          width: 56,
                                                          height: 56,
                                                          child: Icon(Icons.web_sharp)),
                                                      onTap: () {
                                                        _launchUrlweb(
                                                            site[index]['site']);
                                                      },
                                                    ),
                                                  ),
                                                ),
                                              ]),
                                            ],
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                );
                              });
                        }
    
                      }
                      ,
    
                    ),
                  ),
                  new Container(
                    child: login_caller(),
                  ),
                  new Container(
                    padding: EdgeInsets.symmetric(
                      horizontal: 10.0,
                      vertical: 100.0,
                    ),
                    height: double.infinity,
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [
                          Color(0xFFf7dca1),
                          Color(0xFFf1c15b),
                          Color(0xFFeba714),
                          Color(0xFFbc8510),
                        ],
                        stops: [0.1, 0.4, 0.7, 0.9],
                      ),
                    ),
                    child: SingleChildScrollView(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            'About us',
                            style: TextStyle(
                                color: Colors.white,
                                fontFamily: 'OpenSans',
                                fontSize: 30,
                                fontWeight: FontWeight.bold),
                          ),
                          Padding(padding: EdgeInsets.symmetric(vertical: 10.0)),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: <Widget>[
                              GestureDetector(
                                onTap: () {
                                  _launchURLsite();
                                },
                                child: Container(
                                  height: 60.0,
                                  width: 60.0,
                                  child: InkWell(
                                    splashColor: Color(0xFFbc8510),
                                  ),
                                  decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    color: Colors.white,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black26,
                                        offset: Offset(0, 2),
                                        blurRadius: 6.0,
                                      ),
                                    ],
                                    image: DecorationImage(
                                      image: NetworkImage(
                                          'https://www.googlewatchblog.de/wp-content/uploads/google-logo-perfekt.jpg'),
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () {
                                  _launchURLface();
                                },
                                child: Container(
                                  height: 60.0,
                                  width: 60.0,
                                  child: InkWell(
                                    splashColor: Color(0xFFbc8510),
                                  ),
                                  decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    color: Colors.white,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black26,
                                        offset: Offset(0, 2),
                                        blurRadius: 6.0,
                                      ),
                                    ],
                                    image: DecorationImage(
                                      image: NetworkImage(
                                          'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTWHNqSKP0g_42wo-gQv1azrnztIYv1RbZKnQ&usqp=CAU'),
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () {
                                  _launchURLinsta();
                                },
                                child: Container(
                                  height: 60.0,
                                  width: 60.0,
                                  child: InkWell(
                                    splashColor: Color(0xFFbc8510),
                                  ),
                                  decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    color: Colors.white,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black26,
                                        offset: Offset(0, 2),
                                        blurRadius: 6.0,
                                      ),
                                    ],
                                    image: DecorationImage(
                                      image: NetworkImage(
                                          'https://www.pollutionprobe.org/wp-content/uploads/insta-logo-300x300.png'),
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                          Padding(padding: EdgeInsets.symmetric(vertical: 10.0)),
                          Text(
                            'Divij Dhiraaj',
                            style: TextStyle(
                                color: Colors.white,
                                fontFamily: 'OpenSans',
                                fontSize: 30,
                                fontWeight: FontWeight.bold),
                            textAlign: TextAlign.left,
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(
                              horizontal: 20.0,
                              vertical: 15.0,
                            ),
                            child: Text(
                              'Hi! My name is Divij Dhiraaj and I\'m the co-founder of CanUsupport. I’m a Seventeen year old student studying the The Shri Ram School , Aravali. \n \n When Aryan first approached me with the idea of building a platform to connect the less- known NGOs who are in dire need of funds, I resonated with his though process for that is same stumbling block me and my family encounter when trying to donate. Most potential donors are only aware of the well established NGOs , not knowing that there might just be a smaller NGO in their area ,working towards community well-fare, lacking funds and donations. \n \n While creating this site , that was our goal: to connect the less-established NGOs with donors so that the effect of their donations is maximised.',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontFamily: 'OpenSans',
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold),
                              textAlign: TextAlign.left,
                            ),
                          ),
                          Text(
                            'Aryan Jalota',
                            style: TextStyle(
                                color: Colors.white,
                                fontFamily: 'OpenSans',
                                fontSize: 30,
                                fontWeight: FontWeight.bold),
                            textAlign: TextAlign.left,
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(
                              horizontal: 20.0,
                              vertical: 15.0,
                            ),
                            child: Text(
                              'Hi! I\’m Aryan Jalota and I’m the founder of CanUSupport. I\’m a seventeen year old student currently studying in the Shri Ram School, Aravali. \n \n My family and I have been active contributors to many NGOs, but there was one challenge we faced the most when it came to donating – what should we donate? For instance, the first thing which comes to our mind will be stationary and notebooks for NGOs and learning centres; however, NGOs receive these donations in bulk from various people, and the societal impact that donors want to make is minimised. \n \n Therefore, I decided to create a platform over the summer which can directly connect various NGOs and learning centres to the local community. This way, donors can directly donate according to the requirements of the NGOs, ultimately maximising the impact on the society.',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontFamily: 'OpenSans',
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold),
                              textAlign: TextAlign.left,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              bottomNavigationBar: new TabBar(
                tabs: [
                  Tab(
                    icon: new Icon(Icons.home),
                  ),
                  Tab(
                    icon: new Icon(Icons.perm_identity),
                  ),
                  Tab(
                    icon: new Icon(Icons.settings),
                  )
                ],
                labelColor: Colors.yellow,
                unselectedLabelColor: Colors.black,
                indicatorSize: TabBarIndicatorSize.label,
                indicatorPadding: EdgeInsets.all(5.0),
                indicatorColor: Colors.red,
              ),
              backgroundColor: Color(0xff707070),
            ),
          ),
        );
      }
    
      _launchURLsite() async {
        const url = 'https://canusupport.com/';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      _launchURLinsta() async {
        const url = 'https://www.instagram.com/canusupport/';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      _launchUrlcall(String url) async {
        if (await canLaunch(url)) {
          launch(url);
        } else {
          throw "Could not launch $url";
        }
      }
    
      _launchMapsUrl(String loca) async {
        final url = loca;
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      _launchUrlmail(String url) async {
        if (await canLaunch(url)) {
          launch(url);
        } else {
          throw "Could not launch $url";
        }
      }
    
      _launchURLface() async {
        const url = 'https://www.facebook.com/canusupport/';
        if (await canLaunch(url)) {
          await launch(url);
        } else {
          throw 'Could not launch $url';
        }
      }
    
      _launchUrlweb(String url) async {
        if (await canLaunch(url)) {
          launch(url);
        } else {
          throw "Could not launch $url";
        }
      }
    }
    
    

    The error appears to be in the listview builder. Any help would be greatly appreciated as this is a project that I am working on since a long time. Also the var foundations are just dummy values.

    • Sarvesh Dalvi
      Sarvesh Dalvi over 3 years
      Have you tried building that ListView with dummy values ?
    • Recondit
      Recondit over 3 years
      I was trying to implement the database (initially I was using var foundations and manually updating it) im just implementing the database for the name as of now , which is the snapshot.data[index].data['Name'] code
  • Recondit
    Recondit over 3 years
    Thank you for the answer. However , the code you provided is giving two errors , one that the "The getter 'length' isn't defined for the class 'QuerySnapshot'." for the codeline ----->itemCount: snapshot.data.length, It is also giving another runtime error saying that "The operator '[]' isn't defined for the class 'QuerySnapshot'." for the line ------->snapshot.data[index].data['Name'], Ill stick to the docs method though if possible , please tell why the error is occuring
  • Lulupointu
    Lulupointu over 3 years
    Fixed, just some typos
  • Lulupointu
    Lulupointu over 3 years
    No problem! Don't forget to upvote and accept if you think it's the right way to answer your question :)