Как добавить CircularProgressIndicator, когда приложение пытается получить местоположение пользователя во флаттере - PullRequest
1 голос
/ 28 апреля 2020

Я создаю приложение, которое пытается обнаружить местоположение пользователя, и после того, как местоположение пользователя обнаружено, они будут перенаправлять что-то опубликовать (когда _isMockLocation=false) ... Я применил Future Builder и CircularProgressIndicator внутри, когда _isMockLocation=false, но как его применить это когда приложение пытается получить местоположение пользователя ... вот мой код

_getCurrentLocation() async {
TrustLocation.start(5);
      Geolocator()
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.best) // my app stucks here.. I want to add CircularProgressIndicator here
          .then((Position position) {
        TrustLocation.onChange.listen((values) {
          setState(() {
            _isMockLocation = values.isMockLocation;
            _currentPosition = position;
          });
        });
         if (_isMockLocation) { show alert }
         else {**do something**} // when **do something**.. I have applied FutureBuilder here and applied it in Widget defaultClockOut()
     })
    }

GestureDetector(
              onTap: failOut
                  ? () {
                      print(failOut);
                      setState(() {
                        out = true;
                      });
                      _getCurrentLocation();
                    }
                  : null,
              child: Container(
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      isVisibleOut
                          ? defaultClockOut()
                          : isLoadingOut
                              ? Text("Loading...")
                              : (_image == null)
                                  ? Text('Click')
                                  : (_front.length == 0)
                                      ? Text("fail")
                                      : failOut
                                          ? Text("fail")
                                          : defaultClockOut()
                    ],
                  ),
                ),
              ),
            ),
Widget defaultClockOut() {
    print(isVisible);
    print("222");
    return FutureBuilder(
      future: getDataa(),
      builder: (context, snap) {
        if (snap.hasData) {
          print(snap.data);
          return Text(snap.data);
        } else {
          return Container(
              height: 25,
              child: CircularProgressIndicator(
                valueColor: new AlwaysStoppedAnimation<Color>(Colors.white),
              ));
        }
      },
    );
  }

, но у меня не было идеи добавить CircularProgressIndicator, так как я должен сделать что-то когда _isMockLocation=false ... есть ли способ добавить CircularProgressIndicator?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...