How to Stop Scrolling in a Gallery Widget

How to know when gallery widget stop scrolling?

You can tune the behaviour of the galleryview a little bit with calling setCallbackDuringFling(false). This should limit the calls to onItemSelected to cases where the user stopped scrolling.

How to stop backward animation of a gallery view

GallerView is a deprecated widget.

I use ViewPager which you can modify as a custom gallery. Your fragments will be your slides or images which you will be able to swipe around.

You can read more about that here or here.

If you want to swipe only one way, then you would have to extend ViewPager and override onTouch event.

Custom Gallery Not Scrolling

Scratch this post, figured it out, I was ovveriding the OnTouch event in my Activity ><

Flutter vertical swipe and avoiding scrolling Listview

You can wrap your image widget with GestureDetector and use this method to disable the scroll behavior when users tap down on the image widget.

A convenient behavior I found with this method is users can still scroll up or down if they want to (tap down and swipe IMMEDIATELY instead of tap down THEN swipe). This may not be the best way because I can't only block the scroll-up behavior.

This is my example:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
final String title;

const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
ScrollPhysics physics = const AlwaysScrollableScrollPhysics();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
// Add the scroll physics controller here
physics: physics,
children: [
for (int i = 0; i < 20; i++) ...[
// Wrap the Widget with GestureDetector
GestureDetector(
// Disable the scroll behavior when users tap down
onTapDown: (_) {
setState(() {
physics = const NeverScrollableScrollPhysics();
});
},
// Enable the scroll behavior when user leave
onTapCancel: () {
setState(() {
physics = const AlwaysScrollableScrollPhysics();
});
},
onPanUpdate: (details) {
// Catch the swipe up action.
if (details.delta.dy < 0) {
print('Swiping up the element $i');
}
// Catch the swipe down action.
if (details.delta.dy > 0) {
print('Swiping down the element $i');
}
},
// Your image widget here
child: Padding(
padding: const EdgeInsets.all(20),
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
),
Center(child: Text('Element $i')),
],
],
),
);
}
}

How to fix Listview scrolling jank when loading images from network

There are two was to speed up the rendering of your ListView of images.

The first is to set the cacheExtent property to a larger value in your ListView constructor. This property controls how much offscreen widgets are rendered, and will help by causing the rendering to start a bit sooner.

The second is to pre-cache your images using precacheImage. Flutter has an in-memory cache, so it is generally to necessary to cache everything to disk to get good read performance. Instead, you can ask Flutter to download these images ahead of time so that they are ready when the widget is built. For example, if you have a list of urls of your image, then in an initState method you could ask Flutter to cache all of them.

final List<String> imageUrls = [ /* ... */ ];

@override
void initState() {
for (String url in imageUrls) {
precacheImage(new NetworkImage(url), context);
}
super.initState();
}


Related Topics



Leave a reply



Submit