在下面的flutterExpansionPanelList
小部件中,我试图将白色背景着色为其他颜色,例如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"]),
],
),
最佳答案
你可以尝试两个动作。一个。将您的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"]),
],
),
)
关于flutter - Flutter着色背景ExpansionPanelList,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56349416/