Flutter 博客应用程序中对 null 值使用的 Null 检查运算符
构建 Expanded(flex: 1) 时抛出以下 _CastError: 对空值使用空检查运算符
相关的导致错误的小部件是: 扩展扩展:file:///home/abdallah/StudioProjects/gei/lib/news_page.dart:45:13
Expanded(child: GetBuilder<HomeController>(builder:(value) {
if(value.newss.isNotEmpty){
return ListView.builder(
itemCount: value.newss.length,
itemBuilder: (context, index) {
return Padding(padding: const EdgeInsets.symmetric(horizontal: 15.0,vertical: 5.0),
child: Post(model: value.newss[index],),
);
},
);
}else{
return const Center(child: Text("No News Avilable"),);
}
},
),
)
HomeController 代码
class HomeController extends GetxController{
final FirebaseFunctions _functions = FirebaseFunctions();
final ScrollController controller = ScrollController();
List<NewsModel> newss = [];
var isLoding = false.obs;
void getData() async{
newss.addAll(await _functions.getNews());
update();
}
@override
void onInit() {
super.onInit();
getData();
controller.addListener(() {
_functions.isLoading.listen((p) {
isLoding.value = p;
});
double maxScrollPoint = controller.position.maxScrollExtent;
double currentPosition = controller.position.pixels;
double height20 = Get.size.height *0.20;
if(maxScrollPoint - currentPosition <= height20){
getData();
}
});
}
}
The following _CastError was thrown building Expanded(flex: 1):
Null check operator used on a null value
The relevant error-causing widget was:
Expanded Expanded:file:///home/abdallah/StudioProjects/gei/lib/news_page.dart:45:13
Expanded(child: GetBuilder<HomeController>(builder:(value) {
if(value.newss.isNotEmpty){
return ListView.builder(
itemCount: value.newss.length,
itemBuilder: (context, index) {
return Padding(padding: const EdgeInsets.symmetric(horizontal: 15.0,vertical: 5.0),
child: Post(model: value.newss[index],),
);
},
);
}else{
return const Center(child: Text("No News Avilable"),);
}
},
),
)
HomeController Code
class HomeController extends GetxController{
final FirebaseFunctions _functions = FirebaseFunctions();
final ScrollController controller = ScrollController();
List<NewsModel> newss = [];
var isLoding = false.obs;
void getData() async{
newss.addAll(await _functions.getNews());
update();
}
@override
void onInit() {
super.onInit();
getData();
controller.addListener(() {
_functions.isLoading.listen((p) {
isLoding.value = p;
});
double maxScrollPoint = controller.position.maxScrollExtent;
double currentPosition = controller.position.pixels;
double height20 = Get.size.height *0.20;
if(maxScrollPoint - currentPosition <= height20){
getData();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
我认为错误在于,因为您使用了扩展本身,所以您尝试将其删除,让我问您是否在行或列上使用了它
I think the error is that because You use the expanded itself did You try to remove it and let me ask did You use it on a row or column