flutter - 是否可以将自定义 VoidCallback 添加到 Flutter 中的动画插件
问题描述
我使用了这个插件动画。我习惯了我的项目,还下载了他们的示例。VoidCallback
单击项目时是否可以添加自定义?单击此项目时,我要async
编程,并且then
需要将最终结果传递给_DetailsPage
. 我希望你能理解我的问题
您可以从上面的链接获取此源代码
List<Widget>.generate(10, (int index) {
return OpenContainer(
transitionType: _transitionType,
openBuilder: (BuildContext _, VoidCallback openContainer) {
return _DetailsPage();
},
tappable: false,
closedShape: const RoundedRectangleBorder(),
closedElevation: 0.0,
closedBuilder: (BuildContext _, VoidCallback openContainer) {
return ListTile(
leading: Image.asset(
'assets/avatar_logo.png',
width: 40,
),
onTap: openContainer,
title: Text('List item ${index + 1}'),
subtitle: const Text('Secondary text'),
);
},
);
}),
class _DetailsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Details page')),
body: ListView(
children: <Widget>[
Container(
color: Colors.black38,
height: 250,
child: Padding(
padding: const EdgeInsets.all(70.0),
child: Image.asset(
'assets/placeholder_image.png',
),
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Title',
// TODO(shihaohong): Remove this once Flutter stable adopts the modern
// Material text style nomenclature.
// ignore: deprecated_member_use
style: Theme.of(context).textTheme.headline.copyWith(
color: Colors.black54,
fontSize: 30.0,
),
),
const SizedBox(height: 10),
Text(
_loremIpsumParagraph,
// TODO(shihaohong): Remove this once Flutter stable adopts the modern
// Material text style nomenclature.
// ignore: deprecated_member_use
style: Theme.of(context).textTheme.body1.copyWith(
color: Colors.black54,
height: 1.5,
fontSize: 16.0,
),
),
],
),
),
],
),
);
}
}
解决方案
我找到了自己的答案。如果这个错了,请告诉我。
将小部件包裹InkWell
在closedBuilder
closedBuilder: (BuildContext _, VoidCallback openContainer) {
return InkWell(
onTap: ()async{
await //do some async program
openContainer();
},
child: ListTile(
leading: Image.asset(
'assets/avatar_logo.png',
width: 40,
),
onTap: openContainer,
title: Text('List item ${index + 1}'),
subtitle: const Text('Secondary text'),
);
},
);
推荐阅读
- javascript - ES6 imports doesn't work
- android - SQLiteException: no such table: USER (Sqlite code 1): , while compile: SELECT * FROM USER WHERE id=? 限制 1
- java - 使用导入范围功能下载文件时出错
- sql-server - 用于在两个 html 标记之间选择字符串的 SQL 查询
- mpxj - 从 mpxj 库创建时,有什么方法可以删除或不包含某些 xml 元素?
- cordova - initPublisher 的完成处理程序
- keras - 使用 Keras 的 RNN 中的多特征序列填充和屏蔽
- c# - EntityFramework 和带有对象数组的自定义类(一对多)
- php - 将数据推送到php中每个值的末尾
- vba - 设置目的地错误