Aks*_*wal 5 flutter flutter-dependencies
我已经尝试通过this获取当前的国家/地区代码。给我最好的解决方案。
我想在 Splash 页面上显示国旗,所以我需要了解用户国家,这对我来说是必需的。
请帮帮我伙计们
您可以使用系统区域设置。
final List<Locale> systemLocales = WidgetsBinding.instance.window.locales;
String isoCountryCode = systemLocales.first.countryCode;
Run Code Online (Sandbox Code Playgroud)
从flutter v3.7.0开始,不要使用WidgetsBinding.instance.window.locale.countryCode
“window”已被弃用,不应使用。通过 View.of(context) 从上下文中查找当前的 FlutterView 或直接查询 PlatformDispatcher。已弃用,为即将到来的多窗口支持做准备。此功能在 v3.7.0-32.0.pre 之后已弃用。
这样flutter v3.7.0之后就可以使用
WidgetsBinding.instance.platformDispatcher.locale.countryCode
Run Code Online (Sandbox Code Playgroud)
您可以使用以下包devicelocale
在 pupspec.yaml 中添加依赖项
dependencies:
devicelocale: ^0.2.1
Run Code Online (Sandbox Code Playgroud)
导入到你想要的类中
import 'package:devicelocale/devicelocale.dart';
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下命令获取当前设备本地
String locale = await Devicelocale.currentLocale;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10316 次 |
| 最近记录: |