我尝试重构我的Flutter应用并开始使用GetX库。 我使用库 "flutter_form_builder",这里有一些方法需要BuildContext参数。例如:
String? Function(T?) FormBuilderValidators.equal<T>(
BuildContext context,
Object value, {
String? errorText,
})
我尝试将Get.context作为参数添加,但是Get.context的类型是
BuildContext?
而不是BuildContext
。您有什么解决办法吗?
Get.context
不会为空,那么你可以在其后添加一个感叹号来告诉 Flutter 在运行时它不会为空。Get.context!
- Stack UnderflowGet.context!
或者Get.context as BuildContext
。哪个更好呢? - sosnus