【问题标题】:Flutter animations - How to trigger OpenContainer programmatically?Flutter 动画 - 如何以编程方式触发 OpenContainer?
【发布时间】:2022-07-16 23:16:59
【问题描述】:

我使用了颤振动画包:https://pub.dev/packages/animations

我试图在我的initState 函数中在 3 秒后自动打开容器。有没有办法以编程方式触发容器?我找不到控制器或其他东西的任何实现...

@override
  Widget build(BuildContext context) { 

    OpenContainer(
                transitionDuration: Duration(milliseconds: 400),
                transitionType: _transitionType,
                openBuilder: (BuildContext context, VoidCallback _) {
                  return AddRouteParent();
                },
                closedElevation: 6.0,
                closedShape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(_fabDimension / 2),
                  ),
                ),
                closedColor: Color(0xff17c387),
                closedBuilder:
                    (BuildContext context, VoidCallback openContainer) {
                  return Showcase(
                    shapeBorder: CircleBorder(),
                    radius: BorderRadius.all(Radius.circular(30)),
                    overlayPadding: EdgeInsets.all(5),
                    key: _five,
                    description:
                        'Hier kannst du dir deine\neigene Route erstellen.',
                    child: SizedBox(
                      height: _fabDimension,
                      child: Padding(
                        padding: const EdgeInsets.fromLTRB(12, 0, 20, 0),
                        child: Row(mainAxisSize: MainAxisSize.min, children: [
                          Icon(
                            Icons.add,
                            color: Colors.white,
                          ),
                          SizedBox(width: 12),
                          Text("Erstellen",
                              style:
                                  TextStyle(color:     Colors.white, fontSize: 18))
                        ]),
                      ),
                    ),
                  );
                });
  }

【问题讨论】:

  • 你试过了吗:"Future.delayed(const Duration(seconds: 3)).then((_) { //OpenContainer(); });" ?
  • OpenContainer 是我构建方法中的一个小部件。我知道 Future.delyed 并将利用它。但是不知道那里触发什么方法?
  • 在一个简单的方法或函数中,它应该触发如下:“Future showProgressCreditCard(BuildContext context) async { await showGeneralDialog( ...)}”
  • 但它是否仍然具有典型的 OpenContainer 转换或只是打开一个对话框? FAB 仍应从右下角转换为全屏页面。
  • 包没有那个参数codelabs.developers.google.com/codelabs/…。但是通过导航,您可以使用 Future.delayed... Navigator.of(context).push(MaterialPageRoute(... No?

标签: android flutter dart animation flutter-animation


【解决方案1】:

不久前解决了这个问题,只需像这样存储来自 closedBuilder 的动作参数:

closedBuilder: (BuildContext context, void Function() action) {
                  _openContainer = action;

然后像这样在其他任何地方调用它:_openContainer.call();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 2014-04-22
    • 1970-01-01
    相关资源
    最近更新 更多