'future'<动态>的颤动实例

时间:2019-05-16 18:22:47

标签: dart flutter

颤抖的“未来”实例

class UvvAr extends StatefulWidget {
  @override
  _UvvArState createState() => _UvvArState();
}

class _UvvArState extends State<UvvAr> {

  Future getdocs() async{
    var firstore = Firestore.instance;
    QuerySnapshot qn = await firstore.collection('store').getDocuments();
    return qn.documents;
  }
var currentLocation;
      void initState() {
    super.initState();

    Geolocator().getCurrentPosition().then((currloc) {
      setState(() {
        currentLocation = currloc;
      });
    });
  }
  var ddd;
var x;
  Geolocator df = Geolocator();
 // Future<Position> pos = Geolocator().getCurrentPosition();
    Future buildChild(double m1,double m2) async {

     var m3 = 21.3902058;
     var m4 = 39.7947716;
       x = await df.distanceBetween(m3,m4, m1, m2);
 // ddd = await x / 1000;
      print(x);
         return x;

}
@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('sdf'),),
      body: Container(child: FutureBuilder(
        future: getdocs(),
        builder: (context, snapshot){
          if(snapshot.connectionState == ConnectionState.waiting){
            return Center(child: Text('lodeing'),);
          }else{
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, index){
            DocumentSnapshot mystore =
                              snapshot.data[index];
                   foo() async {
  var ufser = await buildChild(mystore['loca'].latitude,mystore['loca'].longitude);
  return ufser;
}
                return Column(
                  children: <Widget>[
                    ListTile(title: Text("${mystore['name']}"),),
                    Text("${foo()}")
                  ],
                );
              },
            );
          }
        },
      ),),
    );
  }
}

0 个答案:

没有答案