我有一个ListTile构建器,它返回这个ListTile.List Tile的 colored颜色 白色被其父级覆盖.我怎么才能阻止这一切?

return ListTile(
   key: Key(index.toString()),
   tileColor: Colors.white,
   title: Text(widget.userExercises[index].name),
   subtitle: Text("${widget.userExercises[index].reps} Reps"),
   trailing: Text("${widget.userExercises[index].sets} Sets"),
   onTap: () => widget.editFunction(widget.userExercises[index]),
);

然而,当我运行我的应用程序时,tileColor会被父容器的 colored颜色 覆盖.

return Container(
  alignment: Alignment.center,
  color: Colors.lightBlue,
  child: ExerciseTable(
    userExercises: todaysExercises,
    editFunction: _showEditDialog,
  ),
);

导致以下情况:

The tiles with Bench Press should be white

谢谢!(很抱歉图像大小,我不知道如何更改)

推荐答案

ListTile将其tileColor绘制在Material小部件的祖先上.当彩色的ContainerListTile和那个祖先之间时,你就看不到tileColor了.引用这里的https://github.com/flutter/flutter/pull/86355/commits/9341a6b1d0d2852ee3c7eb413bbbdc9327f425c8条:

/// Requires one of its ancestors to be a [Material] widget.
/// One ancestor must be a [Material] widget and typically this is
/// provided by the app's [Scaffold]. The [tileColor],
/// [selectedTileColor], [focusColor], and [hoverColor] are not
/// painted by the list tile itself but by the material widget
/// ancestor. This generally has no effect. However, if an opaque
/// widget, like `Container(color: Colors.white)`, is included in
/// between the [ListTile] and its [Material] ancestor, then the
/// opaque widget will obscure the material widget and its background
/// [tileColor], etc. If this a problem, one can wrap a material
/// widget around the list tile, e.g.:
///
/// Container(
///   color: Colors.green,
///   child: Material(
///     child: ListTile(
///       title: const Text('ListTile with red background'),
///       tileColor: Colors.red,
///     ),
///   ),
/// )

另请参阅此讨论:https://github.com/flutter/flutter/issues/83108

Flutter相关问答推荐

如何使用底部导航栏修复此导航问题

Android Emulator冻结,但在调整窗口大小时解冻

Flutter 中的多页表现

摆动如何更改弹出菜单项高亮显示 colored颜色 半径

如何在用Ffltter成功登录后重定向下一页?

Flutter 文件拾取器Android SingleInstance模式它返回的文件路径为空

在flutter web上渲染多个Youtube视频

运行调试flutter应用程序时出错:B/BL超出范围(最大+/-128MB)到'';

如何在flutter中更改showModalBottomSheet小部件中CheckboxListTile小部件的值?

创建仅定义导出的文件是否有意义?

如何在flutter中加载并显示adx锚定的自适应广告?

如何在Flutter中的textField中在可编辑文本和前缀图标之间添加空格?

使用Flutter项目设置Firebase遇到困难?这些解决方案或许能帮到你!

Flutter开发中,如何通过'nfc_manager'插件在Android设备上避免默认的New Tag Scanned弹出窗口?

Riverpod中stateNotiferProvider和notifierProvider的区别

输入处于活动状态时如何设置文本字段标签的样式?

Firebase 中的查询限制 - .orderBy() 错误

如何在dart中编写多个条件?

是否可以在 Flutter 中使用 ToggleButtons 在页面 PageView 之间切换?

Flutter GetX:Get.put 在 Widget 中的什么位置?