📌  相关文章
📜  自动获取用户国家/地区 - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:08.436000             🧑  作者: Mango

代码示例1
import 'dart:io' show Platform;
String localeName = Platform.localeName;
//output language_countryname => en_us
OR
geolocator: ^5.1.1
geocoder: ^0.2.1
Future getCountryName() async {
    Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    debugPrint('location: ${position.latitude}');
    final coordinates = new Coordinates(position.latitude, position.longitude);
    var addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
    var first = addresses.first;
    return first.countryName; // this will return country name
}