Флаттер: PageView теряет карусель при смене экрана - PullRequest
0 голосов
/ 07 апреля 2020

Я использую приведенный ниже код для карусели с использованием PageView

PageView.builder(
                              onPageChanged: (value) {
                                setState(() {
                                  currentpage = value;
                                });
                              },
                              controller: controller,
                              itemCount: data.length,
                              itemBuilder: (context, index) {
                                return GestureDetector(
                                  onTap: () {
                                    debugPrint('Nilesh Rathod $index');
                                    if (index == 0) {
                                      Navigator.push(
                                              context,
                                              PageTransition(
                                                  type: PageTransitionType
                                                      .rightToLeft,
                                                  child: DetailPage()))
                                          .then((value) {
                                        debugPrint('nilu pilu');
                                        controller.jumpToPage(0);
                                      });
                                    }
                                  },
                                  child: AnimatedBuilder(
                                    animation: controller,
                                    builder: (context, child) {
                                      double value = 1.0;
                                      if (controller.position.haveDimensions) {
                                        value = controller.page - index;
                                        value = (1 - (value.abs() * .5))
                                            .clamp(0.0, 1.0);
                                      }

                                      return Align(
                                        alignment: Alignment.topCenter,
                                        child: SizedBox(
                                          height:
                                              Curves.easeOut.transform(value) *
                                                  300,
                                          width:
                                              Curves.easeOut.transform(value) *
                                                  250,
                                          child: child,
                                        ),
                                      );
                                    },
                                    child: Stack(children: <Widget>[
                                      index == 0
                                          ? Container(
                                              height: 300,
                                              width: 220,
                                              child: IconButton(
                                                onPressed: () {
                                                  Utils.changeScreen(
                                                      context, CreateTripApp());
                                                },
                                                icon: Image.asset(
                                                  'assets/images/flight.png',
                                                  height: 120,
                                                  fit: BoxFit.cover,
                                                  width: 100,
                                                ),
                                              ),
                                              decoration: BoxDecoration(
                                                image: DecorationImage(
                                                  image: AssetImage(
                                                      'assets/images/home.png'),
                                                  fit: BoxFit.cover,
                                                ),
                                                borderRadius: BorderRadius.all(
                                                  Radius.circular(20.0),
                                                ),
                                              ))
                                          : Container(
                                              height: 300,
                                              width: 220,
                                              decoration: BoxDecoration(
                                                  color: index % 2 == 0
                                                      ? Colors.red
                                                      : Colors.green,
                                                  borderRadius:
                                                      BorderRadius.all(
                                                          Radius.circular(
                                                              20.0))),
                                            ),
                                      Positioned(
                                          bottom: 30,
                                          right: 10,
                                          left: 10,
                                          child: index == 0
                                              ? Align(
                                                  alignment:
                                                      Alignment.bottomCenter,
                                                  child: Text(
                                                    Constants.createYourTrip,
                                                    textAlign: TextAlign.center,
                                                    style: TextStyle(
                                                      color: Colors.white,
                                                      fontSize: 16.0,
                                                      fontFamily:
                                                          Fonts.standardBold,
                                                    ),
                                                  ))
                                              : Align(
                                                  alignment:
                                                      Alignment.bottomCenter,
                                                  child: Text(
                                                    'Hello There',
                                                    textAlign: TextAlign.center,
                                                    style: TextStyle(
                                                      color: Colors.white,
                                                      fontSize: 16.0,
                                                      fontFamily:
                                                          Fonts.standardBold,
                                                    ),
                                                  )))
                                    ]),
                                  ),
                                );
                              })

И он работает нормально, как исключено

enter image description here

, но при переходе на другую страницу я теряю эффект карусели, пожалуйста, проверьте скриншот ниже для того же

enter image description here

Если вам нужна дополнительная информация, пожалуйста, дайте мне знать. Заранее спасибо. Ваши усилия будут оценены.

...