I am trying to recreate the MediaPicker from Instagram.
The current structure of this screen looks like this:
return Scaffold(
appBar: buildAppBar(context),
body: PageView(
physics: NeverScrollableScrollPhysics(), //disable the "normal" pageview scrolling
onPageChanged: (index) {
setState(() {
pageIndex = index;
});
},
controller: pageController,
children: [
Column(
children: [
Expanded(
flex: 3,
child: buildPreviewWidget(selection, _buildCropPreview), //this cropview has a gesture recognizer on it
),
const SizedBox(height: 2),
Expanded(
flex: 2,
child: GestureDetector(
onHorizontalDragStart: (details) {
double offset = screenWidth - details.localPosition.dx;
pageController.jumpTo(offset);
},
onHorizontalDragUpdate: (details) {
double offset = screenWidth - details.localPosition.dx;
pageController.jumpTo(offset);
},
child:MediaGrid( //this is the media grid
allowMultiSelection: multiSelectable,
collection: allCollection),
)),
],
),
CameraScreen(),
],
),
bottomNavigationBar: buildBottomNavigationBar(),
);
The initial problem was, that whenever I dragged around in the cropview, the swiping gesture of the pageview got triggered which was not what I wanted.
So my idea was to disable the standard way of scrolling with NeverScrollableScrollPhysics()
and then wrap only the MediaGrid()
with a GestureRecognizer()
so that I can achieve the same swipe animation with the help of the PageViews pageController.jumpTo()
but only on the MediaGrid()
However my implementation seems to be bad because the pageview is stuttering like this
https://i.stack.imgur.com/Guh9k.jpg
How do I smooth the stuttering or is there an even better way to achieve this?