我已经使用Expansion Tile生成了一个Expansion List View. 我在扩展磁贴标题中面临一些自定义问题.

下面是我的代码.

ExpansionTile(           
    title: Container(
        child: Text(
            getCategory(i),
            style: TextStyle(
            color: Colors.white,
            ),
        ),
        color: Colors.black
    ),

    children: <Widget>[
        new Container(
            height: 60.0,
            margin: const EdgeInsets.only(top:10.0, left: 10.0, right:10.0, bottom: 10.0),
            decoration: BoxDecoration(                    
            color: Colors.blue,
            borderRadius: new BorderRadius.all(  Radius.circular(5.0) ),
            ),
        ),
        new Container(
            height: 60.0,
            margin: const EdgeInsets.only(top:10.0, left: 10.0, right:10.0, bottom: 0.0),
            decoration: BoxDecoration(                    
            color: Colors.green,
            borderRadius: new BorderRadius.all(  Radius.circular(5.0) ),
            ),
        )
    ],
    backgroundColor: Colors.white,
)

我的成绩差了.

enter image description here

下面是我期待的.

enter image description here

如果任何人知道自定义页眉 colored颜色 的解决方法,请提供建议.

推荐答案

如果查看ExpansionTitle的源代码,您会注意到标题项是一个ListTile,因此无法更改背景,因为它没有具有color属性的父项.

将此文件添加到您的项目:https://gist.github.com/diegoveloper/02424eebd4d6e06ae649b31e4ebcf53c

以这种方式导入以避免冲突,因为名称相同.

    import 'package:nameofyourapp/custom_expansion_tile.dart' as custom;

我使用了一个别名"custom",但你可以更改任何别名.

用法:

    custom.ExpansionTile(
              headerBackgroundColor: Colors.black,
              iconColor: Colors.white,
              title: Container(
              ...

记住,flatter有很多现成的小部件,但是如果其中任何一个不符合您的需要,您必须判断源代码并创建自己的小部件.

Dart相关问答推荐

在 Dart 中,List.unmodifiable() 和 UnmodifiableListView 有什么不同?

如何在 Flutter Web 中使用 Skia/CanvasKit?

LinearProgressIndicator Flutter使用

异常:在Flatter项目上没有Linux桌面项目配置错误

Dart VM 的性能与 Node.js 相比如何?

属性 'docs' 不能无条件访问,因为接收到的可能是 'null' Flutter

如何在Dart中创建空Map

在 Flutter 的 TextFormField 中管理事件

如何使用工厂构造函数扩展抽象类?

Dart 构造函数与静态方法;例如,为什么 int.parse() 不是工厂构造函数?

将符号转换为字符串

Dart 是否支持参数化单元测试?

如何创建类型别名

VS Code 首选项的位置

学习 Dart 好还是我必须使用基本的 javascript?

启用空安全时,默认的List构造函数不可用.try 使用列表文字,List.filled或List.generate

如何判断一个对象是否是一个类的实例

如何在 Dart 中为 Completer.CompleteException(exception, stackTrace) 获取当前堆栈跟踪;

Dart lambda/shortland 函数混淆

在 Dart 中为数字添加前导零