Skip to content

pageView ScrollController attached to multiple scroll views. #86549

@gbbest15

Description

@gbbest15

i have seen so Answer but does not related to pageView. ``
for me to jumpTo next page i keep getting This error:

ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 109 pos 12: '_positions.length == 1'

this is my full code

Code Sample
Column(
                          children: [
                            Expanded(
                              child: Container(
                                height: MediaQuery.of(context).size.height * 10,
                                child: TinderSwapCard(
                                  swipeUp: true,
                                  swipeDown: true,
                                  orientation: AmassOrientation.BOTTOM,
                                  totalNum: userData.length,
                                  stackNum: 3,
                                  swipeEdge: 6.0,
                                  maxWidth:
                                      MediaQuery.of(context).size.width * 0.9,
                                  maxHeight:
                                      MediaQuery.of(context).size.height * 0.9,
                                  minWidth:
                                      MediaQuery.of(context).size.width * 0.8,
                                  minHeight:
                                      MediaQuery.of(context).size.width * 0.8,
                                  allowVerticalMovement: true,
                                  cardBuilder: (context, index) =>
                                      StreamBuilder(
                                          stream: firestore
                                              .collection('Image')
                                              .doc(userData[index].id)
                                              .collection('Photos')
                                              .orderBy('timestap')
                                              .snapshots(),
                                          builder: (context, snapshot) {
                                            if (!snapshot.hasData) {
                                              return Center(
                                                child:
                                                    CircularProgressIndicator(),
                                              );
                                            }
                                            return Container(
                                              child: Stack(
                                                fit: StackFit.passthrough,
                                                alignment: Alignment.center,
                                                children: [
                                                  PageView.builder(
                                                      pageSnapping: true,
                                                      onPageChanged: (pageNum) {
                                                        setState(() {
                                                          pageNumber = pageNum;
                                                        });
                                                      },
                                                      physics:
                                                          NeverScrollableScrollPhysics(),
                                                      controller:
                                                          _pageController,
                                                      itemCount: snapshot
                                                          .data.docs.length,
                                                      itemBuilder:
                                                          (ctx, index) {
                                                        return GestureDetector(
                                                          onTap: () {
                                                            _pageController
                                                                .jumpToPage(1);
                                                          },
                                                          child: Container(
                                                            child: Card(
                                                              semanticContainer:
                                                                  true,
                                                              clipBehavior: Clip
                                                                  .antiAliasWithSaveLayer,
                                                              child: Image(
                                                                image:
                                                                    NetworkImage(
                                                                  snapshot
                                                                          .data
                                                                          .docs[
                                                                              index]
                                                                          .data()[
                                                                      'picture'],
                                                                ),
                                                                fit:
                                                                    BoxFit.fill,
                                                              ),
                                                            ),
                                                          ),
                                                        );
                                                      }),
                                                  if (snapshot
                                                          .data.docs.length !=
                                                      1)
                                                    Padding(
                                                      padding: const EdgeInsets
                                                              .symmetric(
                                                          vertical: 8.0,
                                                          horizontal: 8.0),
                                                      child: Align(
                                                        alignment:
                                                            Alignment.topCenter,
                                                        child: Row(
                                                          children: [
                                                            Expanded(
                                                              child:
                                                                  StepProgressIndicator(
                                                                totalSteps:
                                                                    snapshot
                                                                        .data
                                                                        .docs
                                                                        .length,
                                                                currentStep:
                                                                    pageNumber +
                                                                        1,
                                                                selectedColor:
                                                                    Colors.red,
                                                                unselectedColor:
                                                                    Colors
                                                                        .yellow,
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                      ),
                                                    ),
                                                  if (direction.value <= -1 &&
                                                      index == currentIndex)
                                                    Padding(
                                                      padding:
                                                          const EdgeInsets.all(
                                                              15.0),
                                                      child: Align(
                                                        alignment:
                                                            Alignment.topRight,
                                                        child: Padding(
                                                          padding:
                                                              EdgeInsets.all(
                                                                  8.0),
                                                          child: Container(
                                                              height: 100,
                                                              width: 100,
                                                              child: Image.asset(
                                                                  'assets/Nope.png')),
                                                        ),
                                                      ),
                                                    ),
                                                  if (direction.value >= 1)
                                                    Padding(
                                                      padding:
                                                          const EdgeInsets.all(
                                                              15.0),
                                                      child: Align(
                                                        alignment:
                                                            Alignment.topLeft,
                                                        child: Padding(
                                                          padding:
                                                              EdgeInsets.all(
                                                                  8.0),
                                                          child: Container(
                                                            height: 100,
                                                            width: 100,
                                                            child: Image.asset(
                                                                'assets/Like.png'),
                                                          ),
                                                        ),
                                                      ),
                                                    ),
                                                  PositionedDirectional(
                                                    bottom: 30,
                                                    child: GestureDetector(
                                                      onTap: () {},
                                                      child: Container(
                                                        decoration:
                                                            BoxDecoration(
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(15),
                                                          color: Colors.white70,
                                                        ),
                                                        padding:
                                                            EdgeInsets.all(10),
                                                        width: 305,
                                                        height: 100,
                                                        child: Row(
                                                          children: [
                                                            Container(
                                                              child: Image(
                                                                image:
                                                                    NetworkImage(
                                                                  userData[
                                                                          index]
                                                                      .profilePicture,
                                                                ),
                                                                fit:
                                                                    BoxFit.fill,
                                                              ),
                                                            ),
                                                            SizedBox(
                                                              width: 15,
                                                            ),
                                                            Expanded(
                                                              child: Column(
                                                                crossAxisAlignment:
                                                                    CrossAxisAlignment
                                                                        .start,
                                                                children: [
                                                                  Text(
                                                                    userData[
                                                                            index]
                                                                        .name,
                                                                    overflow:
                                                                        TextOverflow
                                                                            .fade,
                                                                    maxLines: 1,
                                                                    softWrap:
                                                                        false,
                                                                    style:
                                                                        TextStyle(
                                                                      color: Colors
                                                                          .black,
                                                                      fontSize:
                                                                          20,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .bold,
                                                                    ),
                                                                  ),
                                                                  Text(
                                                                    'male',
                                                                    style:
                                                                        TextStyle(
                                                                      color: Colors
                                                                          .black,
                                                                      fontSize:
                                                                          15,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .bold,
                                                                    ),
                                                                  ),
                                                                  Flexible(
                                                                    child: Text(
                                                                      'i am blesses',
                                                                      style:
                                                                          TextStyle(
                                                                        color: Colors
                                                                            .black,
                                                                        fontSize:
                                                                            15,
                                                                      ),
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                      ),
                                                    ),
                                                  ),
                                                  Positioned(
                                                    left: 60,
                                                    bottom: 60,
                                                    child: GestureDetector(
                                                      onTap: () {},
                                                      child: Container(
                                                        height: 30,
                                                        decoration:
                                                            BoxDecoration(
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(15),
                                                        ),
                                                        child: Icon(
                                                            Icons.play_arrow),
                                                      ),
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            );
                                          }),
                                  cardController: controller,
                                  swipeUpdateCallback:
                                      (DragUpdateDetails details,
                                          Alignment align) {
                                    direction.value = align.x.round();
                                  },
                                  swipeCompleteCallback:
                                      (CardSwipeOrientation orientation,
                                          int index) async {
                                    /// Get orientation & index of swiped card
                                    direction.value = 0;
                                    if (orientation ==
                                        CardSwipeOrientation.DOWN) {
                                      //! add to favourite
                                      setState(() {
                                        currentIndex = index + 1;
                                        pageNumber = 0;
                                      });

                                      await ControllerApi().addtoLikes(
                                          userData[index].id, context);
                                    } else if (orientation ==
                                        CardSwipeOrientation.UP) {
                                      setState(() {
                                        currentIndex = index + 1;
                                        pageNumber = 0;
                                      });
                                      //! to view the profile

                                      // var returnid = await
                                      Navigator.push(
                                        context,
                                        MaterialPageRoute(
                                          builder: (_) => MatchesProfile(
                                            viewId: userData[index].id,
                                          ),
                                        ),
                                      );
                                   
                                    } else if (orientation ==
                                        CardSwipeOrientation.LEFT) {
                                      setState(() {
                                        currentIndex = index + 1;
                                      });
                                      print('Remove from index.....');
                                    } else if (orientation ==
                                        CardSwipeOrientation.RIGHT) {
                                      //! to like... And match
                                      setState(() {
                                        currentIndex = index + 1;
                                        pageNumber = 0;
                                      });
                                      await ControllerApi()
                                          .addtoLikesWithMatches(
                                        userData[index].id,
                                        context,
                                      );
                                    }
                                  },
                                ),
                              ),
                            ),
                            Padding(
                              padding: const EdgeInsets.only(top: 55.0),
                              child: SizedBox(
                                height: 10,
                              ),
                            )
                          ],
                        ),

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions