Flutter LocationNotFoundException(名为“GMT”的位置不存在)
我需要为调度创建本地通知,问题是当我使用setLocalLocation函数获取时区名称时,它等于Flutter LocationNotFoundException(名为“GMT”的位置不存在),flutter,dart,push-notification,Flutter,Dart,Push Notification,我需要为调度创建本地通知,问题是当我使用setLocalLocation函数获取时区名称时,它等于[log]timeZoneName值为=>GMT 例外情况是: LocationNotFoundException (Location with the name "GMT" doesn't exist) const MethodChannel platform = MethodChannel('dexterx.dev/example_app'); void main() a
[log]timeZoneName值为=>GMT
例外情况是:
LocationNotFoundException (Location with the name "GMT" doesn't exist)
const MethodChannel platform = MethodChannel('dexterx.dev/example_app');
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _configureLocalTimeZone();
runApp(MyApp());
}
Future<void> _configureLocalTimeZone() async {
tz.initializeTimeZones();
final String timeZoneName = await platform.invokeMethod('getTimeZoneName');
log("timeZoneName value is =>$timeZoneName",error: {"name":"Value or not"});
tz.setLocalLocation(tz.getLocation(timeZoneName));
}
主要功能:
LocationNotFoundException (Location with the name "GMT" doesn't exist)
const MethodChannel platform = MethodChannel('dexterx.dev/example_app');
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _configureLocalTimeZone();
runApp(MyApp());
}
Future<void> _configureLocalTimeZone() async {
tz.initializeTimeZones();
final String timeZoneName = await platform.invokeMethod('getTimeZoneName');
log("timeZoneName value is =>$timeZoneName",error: {"name":"Value or not"});
tz.setLocalLocation(tz.getLocation(timeZoneName));
}
\u配置本地时区功能:
LocationNotFoundException (Location with the name "GMT" doesn't exist)
const MethodChannel platform = MethodChannel('dexterx.dev/example_app');
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _configureLocalTimeZone();
runApp(MyApp());
}
Future<void> _configureLocalTimeZone() async {
tz.initializeTimeZones();
final String timeZoneName = await platform.invokeMethod('getTimeZoneName');
log("timeZoneName value is =>$timeZoneName",error: {"name":"Value or not"});
tz.setLocalLocation(tz.getLocation(timeZoneName));
}
Future\u配置localtimezone()异步{
tz.initializeTimeZones();
最终字符串timeZoneName=await platform.invokeMethod('getTimeZoneName');
日志(“timeZoneName值=>$timeZoneName”,错误:{“名称”:“值是否”});
tz.setLocalLocation(tz.getLocation(timeZoneName));
}
您正在使用模拟器吗?默认情况下,没有设置时区。因此,您必须选择一个,以便GMT不会为空
您是否尝试更改手机设置中的时区
我当时正在开发emulator,将时区从美国改为法国后,我的应用程序就不再崩溃了。谢谢:)