flutter - 如何使容器在 Flutter 中保持/点击时“变亮”?
问题描述
我正在尝试创建一个带有滚动视图的应用程序,并且对象可以像谷歌新闻应用程序一样点击。谁能回答如何为容器设置动画以在握住瓷砖时发出白光?
这是我为应用程序提供的列表视图构建器
Container(
padding: EdgeInsets.only(top: 16),
child: ListView.builder(
physics: ClampingScrollPhysics(),
itemCount: article.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return news_tile(
imageurl: article[index].urlToimage,
news_title: article[index].title,
news_desc: article[index].description,
web_url: article[index].url
);
}),
)
这是列表视图构建器调用的磁贴的内容
class news_tile extends StatelessWidget {
String imageurl, news_title, news_desc,web_url;
news_tile({this.imageurl, this.news_title, this.news_desc,this.web_url});
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(
builder: (context) => article_view(
web_url: web_url,
)
));
},
child: Container(
margin: EdgeInsets.only(bottom: 16),
child: Column(
children: <Widget>[
ClipRRect(borderRadius: BorderRadius.circular(6), child: Image.network(imageurl)),
SizedBox(
height: 8,
),
Text(news_title, style: TextStyle(fontSize: 17,fontWeight: FontWeight.w600)),
SizedBox(
height: 8,
),
Text(news_desc, style: TextStyle(color: Colors.black54))
],
),
),
);
}
}
解决方案
您可以使用InkWell
小部件。它提供了类似的点击/保持颜色效果。在这里查看官方文档:
https://api.flutter.dev/flutter/material/InkWell-class.html
请注意,您需要一个Material
小部件作为 InkWell 的祖先,但文档对此进行了更多说明。
希望对你有帮助!
编辑:抱歉,因为您使用的是容器,Ink
所以对您来说也很重要:
https ://api.flutter.dev/flutter/material/Ink-class.html
检查文档部分“墨水飞溅不可见!” 为什么会这样。
推荐阅读
- android - 创建新片段与轮换从经理处获取现有片段之间的区别
- css - 将 Episerver 升级到 11.5 版后 TinyMCE“EditMenuName”css 属性不起作用
- visual-studio - 如何在 Visual Studio 2017 中禁用自动 ES6 导入语句
- apache-kafka - 当前是否存在用于 CSV 文件的 Kafka Sink 连接器?
- android - Android 中的 URL 模式匹配
- ios - 从 MSOffice 应用程序保存新文档时,NSFileProvider importDocument 提供空文件的 fileURL
- javascript - Spring 应用停止读取 css 和 js 文件
- python - Django 1.11:在我的并行测试运行中,什么使“pickle”失败了?
- ios - stopMonitoringForRegion 是否仅停止重复区域或也停止原始区域?
- android - 如何使用 FileProvider 查看/显示 PDF 文件?仅显示空白屏幕