首页 > 解决方案 > 是否可以将自定义 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,
                      ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

标签: flutterdartflutter-animation

解决方案


我找到了自己的答案。如果这个错了,请告诉我。

将小部件包裹InkWellclosedBuilder

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'),
                );
              },
            );

推荐阅读