如何在获取 GPS 点后自动关闭 AlertDialog 框?

How to auto dismiss an AlertDialog box after getting GPS point?

我正在尝试创建一个在获取位置后显示“文本”的对话框,然后执行... Navigator.of(context).pop();自动关闭对话框

求助!我从 Flutter 开始...这是代码

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

......

showProgressDialogGPS(BuildContext context,
    {String message = 'Loading...'}) {
  showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) {
      Future.delayed(Duration(milliseconds: 50), () {
        _getPosition();
        Navigator.of(context).pop();
      });
      return AlertDialog(
        actions: [],
        content: Row(
          children: <Widget>[
            CircularProgressIndicator(),
            SizedBox(width: 20),
            Expanded(child: Text(message)),
          ],
        ),
      );
    },
  );
}

Future _getPosition() async {
  await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low)
      .then((value) {
    print(value);
  });
}


.......

谢谢大家!!!

您可以这样修改您的代码:

 Future.delayed(Duration(milliseconds: 50), () async{
        await _getPosition();
        Navigator.of(context).pop();
      });

在这里你正在等待_getPosition被执行然后语句Navigator.of(context).pop();将被执行。