如何从动画上删除儿童背景颜色?

发布于 2025-02-12 01:02:01 字数 6700 浏览 0 评论 0原文

这是我的代码:

class Temp extends StatefulWidget {
  const Temp({Key? key}) : super(key: key);

  @override
  State<Temp> createState() => _TempState();
}

// stores ExpansionPanel state information
class Item {
  Item(bool exp) {
    this.isExpanded = exp;
  }
  late bool isExpanded;
}

List<Item> items = [Item(false), Item(true), Item(true), Item(false)];

class _TempState extends State<Temp> {

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 4,
        child: Scaffold(
          body: SingleChildScrollView(
            child: Container(
              child: ExpansionPanelList(
                expandedHeaderPadding: EdgeInsets.zero,
                expansionCallback: (int index, bool isExpanded) {
                  setState(() {
                    items[index].isExpanded = !isExpanded;
                  });
                },
                children: [
                  ExpansionPanel(
                    headerBuilder: (BuildContext context, bool isExpanded) {
                      return ListTile(
                        title: Text("Test", style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
                        leading: Icon(Icons.info),
                        minLeadingWidth : 4,
                        contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
                        dense:true,
                      );
                    },
                    body: Column(
                      children: [
                          ListTile(
                          title: Text("Test 1", style: TextStyle(fontSize: 16)),
                          leading: Icon(Icons.handshake_outlined),
                          minLeadingWidth : 4,
                          contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
                          dense:true,
                        ),
                        ExpansionTile(
                          title: const Text('Test 2', style: TextStyle(color: Colors.black87),),
                          leading: Icon(Icons.handshake_outlined, color: Colors.black54,),
                          trailing: Column(),
                          children: <Widget>[
                            ListTile(
                              dense: true,
                              tileColor: Color(0xffffeed4),
                              title: Text('Foo', style: TextStyle (fontSize: 16),),
                              trailing: SizedBox(
                                  child: Text("foo", style: TextStyle (fontSize: 16),)
                              ),
                            ),
                            ListTile(
                              tileColor: Color(0xffffeed4),
                              title: Text('Bar', style: TextStyle (fontSize: 16),),
                              dense: true,
                              trailing: SizedBox(
                                  child: Text("bar", style: TextStyle (fontSize: 16),)
                              ),
                            ),
                            Container(
                              height: 10,
                              color: Color(0xffffeed4),
                            ),
                            Container(
                              color: Color(0xffffeed4),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.copy,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.delete_rounded,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.info_outline,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              height: 10,
                              color: Color(0xffffeed4),
                            )

                          ],
                          onExpansionChanged: (bool expanded) {
                            //setState(() => _customTileExpanded = expanded);
                          },
                        ),
                      ],
                    ),
                    isExpanded: items[1].isExpanded,
                    canTapOnHeader: true
                  ),
                ],

              ),
            ),
          ),

          floatingActionButton: FloatingActionButton(
            onPressed: null,
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        )
    );

  }
}

这是结果:

”“在此处输入图像说明”

当我单击expassiontile title/header时,您会看到,不仅可以在此stemptimiontile上看到儿童背景 title/header(测试2),但也要在上一个(test 1)上。结果,这很丑陋。我不希望儿童背景颜色在扩展标题/标题上可见。有人可以说怎么做吗?

This is my code:

class Temp extends StatefulWidget {
  const Temp({Key? key}) : super(key: key);

  @override
  State<Temp> createState() => _TempState();
}

// stores ExpansionPanel state information
class Item {
  Item(bool exp) {
    this.isExpanded = exp;
  }
  late bool isExpanded;
}

List<Item> items = [Item(false), Item(true), Item(true), Item(false)];

class _TempState extends State<Temp> {

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 4,
        child: Scaffold(
          body: SingleChildScrollView(
            child: Container(
              child: ExpansionPanelList(
                expandedHeaderPadding: EdgeInsets.zero,
                expansionCallback: (int index, bool isExpanded) {
                  setState(() {
                    items[index].isExpanded = !isExpanded;
                  });
                },
                children: [
                  ExpansionPanel(
                    headerBuilder: (BuildContext context, bool isExpanded) {
                      return ListTile(
                        title: Text("Test", style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
                        leading: Icon(Icons.info),
                        minLeadingWidth : 4,
                        contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
                        dense:true,
                      );
                    },
                    body: Column(
                      children: [
                          ListTile(
                          title: Text("Test 1", style: TextStyle(fontSize: 16)),
                          leading: Icon(Icons.handshake_outlined),
                          minLeadingWidth : 4,
                          contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
                          dense:true,
                        ),
                        ExpansionTile(
                          title: const Text('Test 2', style: TextStyle(color: Colors.black87),),
                          leading: Icon(Icons.handshake_outlined, color: Colors.black54,),
                          trailing: Column(),
                          children: <Widget>[
                            ListTile(
                              dense: true,
                              tileColor: Color(0xffffeed4),
                              title: Text('Foo', style: TextStyle (fontSize: 16),),
                              trailing: SizedBox(
                                  child: Text("foo", style: TextStyle (fontSize: 16),)
                              ),
                            ),
                            ListTile(
                              tileColor: Color(0xffffeed4),
                              title: Text('Bar', style: TextStyle (fontSize: 16),),
                              dense: true,
                              trailing: SizedBox(
                                  child: Text("bar", style: TextStyle (fontSize: 16),)
                              ),
                            ),
                            Container(
                              height: 10,
                              color: Color(0xffffeed4),
                            ),
                            Container(
                              color: Color(0xffffeed4),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.copy,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.delete_rounded,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                  TextButton(
                                    style: TextButton.styleFrom(
                                      backgroundColor: Colors.indigo,
                                      shape: CircleBorder(),
                                    ),
                                    child: Icon(
                                      Icons.info_outline,
                                      color: Colors.white,
                                    ),
                                    onPressed: () {},
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              height: 10,
                              color: Color(0xffffeed4),
                            )

                          ],
                          onExpansionChanged: (bool expanded) {
                            //setState(() => _customTileExpanded = expanded);
                          },
                        ),
                      ],
                    ),
                    isExpanded: items[1].isExpanded,
                    canTapOnHeader: true
                  ),
                ],

              ),
            ),
          ),

          floatingActionButton: FloatingActionButton(
            onPressed: null,
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        )
    );

  }
}

And this is the result:

enter image description here

As you see when I click on ExpansionTile title/header then children background is visible not only on this ExpansionTile title/header (Test 2) but also on the previous one (Test 1). As a result it is rather ugly. I don't want children background color be visible on ExpansionTile title/header. Could anyone say how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懷念過去 2025-02-19 01:02:01

这是扑打中的错误。问题是在这里

It is a bug in flutter. Issue is here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文