如何解决Flutter:带下拉菜单的卡片小部件
当我单击我的卡片小部件时,我希望其根据即将到来的数据被下拉。我的卡上有文字和图标。我将Inkwell添加为可点击的。但是当我单击时,我希望将我即将到来的数据添加下来。这可能吗?
child: Card(
child: InkWell(
onTap: () { });
},child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0),child: Icon(
Icons.favorite,),Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0),child: Text(
snapshot.text,style: TextStyle(fontSize: 16),],
我有一个这样的列表,
当单击一个项目时,我想要如下相关的文本。例如,我希望有2家与该国相关的公司来。像开卡一样。 (对不起的视觉效果。我很快就做到了:))
解决方法
确实有可能,整个想法都基于以下理论:
您的
country card
及其关联的company card
应该是一个不同的StatefulWidget
,它将由布尔值控制
请注意:我已经给出了非常基本的视图表示形式,您可以使用该UI并使其看起来像自己想要的UI
这是您的即时贴视图,如下所示:
class CardWidget extends StatefulWidget {
// right now it only accepts title,but you can add more
// arguments to be accepted by this widget
CardWidget({Key key,this.title}) : super(key: key);
final String title;
@override
_CardWidgetState createState() => _CardWidgetState();
}
class _CardWidgetState extends State<CardWidget> {
// responsible for toggle
bool _showData = false;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.start,children: [
SizedBox(height: 10.0),// list card containing country name
GestureDetector(
onTap: (){
setState(() => _showData = !_showData);
},child: Container(
width: MediaQuery.of(context).size.width,decoration: BoxDecoration(
color: Colors.white,boxShadow: [BoxShadow(color: Colors.grey,offset: Offset(0.0,3.0))]
),child: Padding(
padding: EdgeInsets.all(15.0),child: Row(
mainAxisAlignment: MainAxisAlignment.start,children: [
// add your other icon here
Text(widget.title)
]
)
)
)
),// this is the company card which is toggling based upon the bool
_showData ? Column(
crossAxisAlignment: CrossAxisAlignment.start,children: ['Kia','Samsung'].map((e){
// make changes in the UI here for your company card
return Card(child: Text(e));
}).toList()
) : SizedBox() // else blank
]
);
}
}
这是我在主界面中调用CardWidget
的方式
// this is dummy data,you can play with the data and the UI
Column(
children: ['Korea','China','Japan','USA','India'].map((country){
// returning the CardWidget passing only title
return CardWidget(title: country);
}).toList()
)
结果
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。