是否可以在Flutter中将自定义VoidCallback添加到动画插件

时间:2020-05-10 11:37:49

标签: flutter dart flutter-animation

我使用了此插件animations。我习惯了这个项目,也下载了他们的示例。单击项目时是否可以添加自定义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,
                      ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

1 个答案:

答案 0 :(得分: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'),
                );
              },
            );