![](/img/trans.png)
[英]How can I get the screen size in Flutter without BuildContext?
[英]How can I get BuildContext in GetX Flutter?
class UpdateCheckerService extends GetxService{
final newVersion = NewVersion(
androidId: 'net.uniqueapps.beautyone',
);
UpdateCheckerService() {
checkUpdate(newVersion);
}
void checkUpdate(NewVersion newVersion) {
newVersion.showAlertIfNecessary(context: Get.context!); //how can I get context here
}
}
我正在尝试使用 GetX 在 Flutter 中创建一个更新检查器,但是新版本插件询问上下文我给了 Get.context 但它抛出了 null。
获取上下文! 或Get.context 作为 BuildContext
Get.context // this is BuildContext?
Get.context! // this is BuildContext
Get.context // this is BuildContext?
Get.context! // this is BuildContext
或者你可以使用这种方式
Get.context as BuildContext // this is BuildContext
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.