如何从动画上删除儿童背景颜色?
这是我的代码:
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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是扑打中的错误。问题是在这里
It is a bug in flutter. Issue is here