【问题标题】:Flutter colorize background ExpansionPanelList颤振着色背景扩展面板列表
【发布时间】:2019-10-14 09:47:09
【问题描述】:

在下面颤动的ExpansionPanelList 小部件中,我正在尝试将白色背景着色为其他颜色,例如indigo,我找不到任何文档或有用的链接来实现这一点

ExpansionPanelList(
  expansionCallback: (int index, bool isExpanded) {
    setState(() {
      _categoryExpansionStateMap[_categoryExpansionStateMap.keys
          .toList()[index]] = !isExpanded;
    });
  },
  children: <ExpansionPanel>[
    ExpansionPanel(
        headerBuilder: (BuildContext context, bool isExpanded) {
          return ListTile(
            contentPadding: EdgeInsets.all(3.0),
            leading: Container(
              padding:
                  EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
              decoration: BoxDecoration(
                  border: Border(
                      left: BorderSide(
                          width: 3.0, color: Colors.white54))),
              child: Icon(
                Icons.account_circle,
                size: 30.0,
                color: Colors.black,
              ),
            ),
            title: ListTile(
              contentPadding: EdgeInsets.all(0.0),
              title: Text(
                Strings.yourBasicInformation,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 14.0,),
              )
            ),
          );
        },
        body: Biography(),
        isExpanded: _categoryExpansionStateMap["Biography"]),
  ],
),

【问题讨论】:

  • 您是否尝试过将您的 ExpansionPanelTile 包装在一个容器中并在容器的颜色参数中传递颜色?

标签: flutter flutter-layout


【解决方案1】:

你可以尝试两个动作。一。将您的 ExpansionPanelList 包裹在 Container 中并在 Container 中传递颜色,我认为它应该可以工作,我不知道您的其余代码。

第二步是将ExpansionPanelList 包装在Theme 组件中。传递一个数据,然后调用ThemeData().copyWith(canvasColor: Colors.white)。然后,它看起来像这样:

    Theme(
        data: ThemeData().copyWith(canvasColor: Colors.white),
        child: ExpansionPanelList(
          expansionCallback: (int index, bool isExpanded) {
            setState(() {
              _categoryExpansionStateMap[_categoryExpansionStateMap.keys
                  .toList()[index]] = !isExpanded;
            });
          },
          children: <ExpansionPanel>[
            ExpansionPanel(
                headerBuilder: (BuildContext context, bool isExpanded) {
                  return ListTile(
                    contentPadding: EdgeInsets.all(3.0),
                    leading: Container(
                      padding:
                      EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
                      decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  width: 3.0, color: Colors.white54))),
                      child: Icon(
                        Icons.account_circle,
                        size: 30.0,
                        color: Colors.black,
                      ),
                    ),
                    title: ListTile(
                        contentPadding: EdgeInsets.all(0.0),
                        title: Text(
                          Strings.yourBasicInformation,
                          style: TextStyle(
                            color: Colors.black,
                            fontSize: 14.0,),
                        )
                    ),
                  );
                },
                body: Biography(),
                isExpanded: _categoryExpansionStateMap["Biography"]),
          ],
        ),
      )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2018-06-05
    • 2020-10-01
    • 2021-06-02
    • 2023-01-03
    • 2021-12-21
    相关资源
    最近更新 更多