flutter - 升级到 4.0.0-nullsaftey 后用于空值的空值检查运算符
问题描述
我试图找出为什么我几天都收到此错误但不走运。
我已经升级了 get_storage 并获取最新的依赖项并获取依赖项有重大变化
突破:不可能用空值初始化 Rx,这可能会导致我出现问题。
这是完整的错误:
The following _CastError was thrown building Container(bg: Color(0xffffffff), constraints: BoxConstraints(0.0<=w<=Infinity, h=345.0)):
Null check operator used on a null value
这是代码:
class RecommendedCarouselWidget extends GetWidget<HomeController> {
@override
Widget build(BuildContext context) {
return Container(
height: 345,
color: Get.theme.primaryColor,
child: GetX(builder: (context) {
return ListView.builder(
padding: EdgeInsets.only(bottom: 10),
primary: false,
shrinkWrap: false,
scrollDirection: Axis.horizontal,
itemCount: controller.eServices.length,
itemBuilder: (_, index) {
var _service = controller.eServices.elementAt(index);
return GestureDetector(
onTap: () {
Get.toNamed(Routes.E_SERVICE, arguments: {'eService': _service, 'heroTag': 'recommended_carousel'});
},
child: Container(
width: 160,
margin: EdgeInsetsDirectional.only(end: 20, start: index == 0 ? 20 : 0, top: 20, bottom: 10),
// padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
boxShadow: [
BoxShadow(color: Get.theme.focusColor.withOpacity(0.1), blurRadius: 10, offset: Offset(0, 5)),
],
),
child: Column(
//alignment: AlignmentDirectional.topStart,
children: [
Hero(
tag: 'recommended_carousel' + _service.id,
child: ClipRRect(
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)),
child: CachedNetworkImage(
height: 180,
width: double.infinity,
fit: BoxFit.cover,
imageUrl: _service.firstImageUrl,
placeholder: (context, url) => Image.asset(
'assets/img/loading.gif',
fit: BoxFit.cover,
width: double.infinity,
height: 100,
),
errorWidget: (context, url, error) => Icon(Icons.error_outline),
),
),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 10),
height: 115,
width: double.infinity,
decoration: BoxDecoration(
color: Get.theme.primaryColor,
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
_service.name ?? '',
maxLines: 2,
style: Get.textTheme.bodyText2.merge(TextStyle(color: Get.theme.hintColor)),
),
Wrap(
children: Ui.getStarsList(_service.rate),
),
SizedBox(height: 10),
Wrap(
spacing: 5,
alignment: WrapAlignment.spaceBetween,
direction: Axis.horizontal,
children: [
Text(
"Start from".tr,
style: Get.textTheme.caption,
),
Ui.getPrice(
_service.price,
style: Get.textTheme.bodyText2.merge(TextStyle(color: Get.theme.accentColor)),
unit: _service.priceUnit != 'fixed' ? "/h".tr : null,
),
],
)
],
),
),
],
),
),
);
});
}),
);
}
}
期待答案。
解决方案
推荐阅读
- javascript - 使用 React 检查主复选框时如何检查子复选框?
- python - 如何从 python 将数据列表发送到 postgresql,然后将该列表迭代到插入 postgresql 函数中?
- python - Matlab中名称后的两个连续括号
- html - 如何使用水晶报表打印包含表格的base64字符串
- oracle11g - 在 SQLPlus 中创建的用户无法与 SQL Developer 连接
- php - 使用 laravel 数据表服务器端功能对链接查询进行排序
- c# - EditorSceneManager 在 Play 模式下使用 SceneManager 测试
- mysql - 尝试在我的 django 项目中安装 mysqlclient 时出错?
- python - 如何根据 pandas/csv 文件在同一行中移动文件和文件夹?
- c# - 懒惰地检索用作 IEnumerable 的数组