Flutter 的 SharedAxisTransition 不起作用

问题描述 投票:0回答:0

我正在尝试在两个选项卡之间实现共享轴转换。因此,当点击 bottomnavigationbar 时,selectedIndex 可以从 == 0 变为 == 1,反之亦然。在数量发生变化期间,我希望过渡到动画。该代码没有任何错误,但没有显示动画。请提前提出建议并感谢。

body: PageTransitionSwitcher(
        duration: const Duration(milliseconds: 500),
        transitionBuilder: (Widget child, Animation<double> primaryAnimation,
            Animation<double> secondaryAnimation) {
          return SharedAxisTransition(
              animation: primaryAnimation,
              secondaryAnimation: secondaryAnimation,
              transitionType: SharedAxisTransitionType.horizontal,
              child: child);
        },
        child: selectedIndex == 0
            ? AnimationLimiter(
                child: AnimatedList(
                  key: _key,
                  initialItemCount: db.dailyList.length,
                  itemBuilder: (context, index, animation) {
                    return AnimationConfiguration.staggeredList(
                      position: index,
                      duration: const Duration(milliseconds: 375),
                      child: SlideAnimation(
                        verticalOffset: 50.0,
                        child: FadeInAnimation(
                          child: SizeTransition(
                            sizeFactor: animation,
                            child: Tile(
                              title: db.dailyList[index][0],
                              goalAchieved: db.dailyList[index][1],
                              onChanged: (value) =>
                                  {checkBoxChanged(value, index)},
                              deleteFunction: (context) => deleteGoal(index),
                            ),
                          ),
                        ),
                      ),
                    );
                  },
                ),
              )
            : AnimationLimiter(
                child: ListView.builder(
                  itemCount: dbAchieved.dailyAchievedList.length,
                  itemBuilder: (context, index) {
                    return AchievedTile(
                      title: dbAchieved.dailyAchievedList[index][0],
                      deleteFunction: (context) => deleteAchievedGoal(index),
                    );
                  },
                ),
              ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Theme.of(context).backgroundColor,
        unselectedItemColor: Colors.black.withOpacity(0.7),
        selectedItemColor: Colors.black,
        currentIndex: selectedIndex,
        onTap: (index) => setState(() {
          selectedIndex = index;
        }),
        items: const [
          BottomNavigationBarItem(
              icon: Icon(Icons.fact_check_outlined), label: 'Carpe Diem'),
          BottomNavigationBarItem(icon: Icon(Icons.done), label: 'Achieved')
        ],
      ),
flutter flutter-animation
© www.soinside.com 2019 - 2024. All rights reserved.