小编yod*_*per的帖子

Flutter - 如何在我未来的构建器文本小部件中获得价值回报

我试图在未来的成功构建中获得两个坐标的距离,但我正在寻找如何在我的代码中的 Text() 小部件中获取返回的“kmDis”值:我的代码。在下面查看我的完整代码。

Future<String> getDistance(String lat, String lng) async {
    final distanceInMeters = await Geolocator().distanceBetween(
        currentLocation.latitude,
        currentLocation.longitude,
        double.parse(lat),
        double.parse(lng));

    double distancekm = distanceInMeters / 1000;
    String kmDis = distancekm.toStringAsFixed(1);
    //int finalkm = distancekm.round();

    return kmDis;
  }

@override
  Widget build(BuildContext context) {

return Scaffold(
        body:Text("i want to return my kmDis value as string here.")
)

  }

Run Code Online (Sandbox Code Playgroud)

dictionary future widget getdistance flutter

1
推荐指数
1
解决办法
1736
查看次数

标签 统计

dictionary ×1

flutter ×1

future ×1

getdistance ×1

widget ×1