【问题标题】:Color of ListTile overflows its parent - FlutterListTile 的颜色溢出其父级 - Flutter
【发布时间】:2021-09-11 05:57:49
【问题描述】:

问题:ListTile 和 HoverColor 的“颜色”溢出了它们的父项。可能还有其他颜色,但我还没有测试过。 这是这个奇怪问题的屏幕截图。 screenshot

@override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: titles.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onSecondaryTap: () {
              print('clicked index : $index');
            },
            child: ListTile(
              hoverColor: Colors.amber,
              title: Padding(
                padding: EdgeInsets.only(bottom: 0, top: 0),
                child: Text(
                  titles[index],
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: dark,
                    fontSize: 14,
                  ),
                ),
              ),
              subtitle: Padding(
                padding:
                    const EdgeInsets.only(bottom: 0, top: 0, left: 0, right: 0),
                child: Text(
                  subtitles[index],
                  style: TextStyle(
                    color: _statusColor(subtitles[index]),
                    fontSize: 11,
                  ),
                ),
              ),
              leading: CircleAvatar(
                radius: 25,
                backgroundImage: NetworkImage(
                    "https://images.unsplash.com/photo-1547721064-da6cfb341d50"),
              ),
            ),
          );
        });
  }
}

【问题讨论】:

  • 你能在你使用它的地方添加父小部件吗?
  • 我通过添加“MaterialApp”和“Scaffold”作为列表的父级解决了这个问题。但我不确定在 1 个应用程序中使用太多 MaterialApp 和 Scaffold 是否正确。跨度>
  • 项目中应该只有一个材质应用。但是你可以随心所欲地使用任意数量的脚手架。尝试用脚手架包裹它,它会起作用
  • 我更新了我的代码,它现在完美无缺。您的回答也解决了我心中的许多问题。谢谢。
  • 我已经添加了问题的答案,请接受它。

标签: flutter flutter-layout flutter-listview


【解决方案1】:

根据您在 cmets 中提供的信息,您的问题是您没有用脚手架包装小部件,因此请尝试仅用脚手架包装它,它会起作用。

项目中应该只有一个材质应用程序。但是你可以拥有任意数量的脚手架。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 2022-01-17
    • 2021-08-25
    • 2023-03-25
    • 2023-03-31
    • 2018-10-01
    相关资源
    最近更新 更多