Skip to content

Instantly share code, notes, and snippets.

@rayliverified
Created November 17, 2021 06:39
Show Gist options
  • Save rayliverified/3dd62fcb66dfaee91b9cd17d29292e83 to your computer and use it in GitHub Desktop.
Save rayliverified/3dd62fcb66dfaee91b9cd17d29292e83 to your computer and use it in GitHub Desktop.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(App());
}
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
final PageController controller = PageController();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PageView Demo',
home: SafeArea(
child: Scaffold(
body: Center(
child: ScrollConfiguration(
behavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
}),
child: SizedBox(
width: 350,
height: 200,
child: PageView(
controller: controller,
physics: const BouncingScrollPhysics(),
scrollBehavior: WebScrollBehavior(),
children: const [
ColoredBox(color: Colors.amber),
ColoredBox(color: Colors.blue),
ColoredBox(color: Colors.green),
ColoredBox(color: Colors.red),
ColoredBox(color: Colors.purple),
],
),
),
),
),
),
),
);
}
}
class WebScrollBehavior extends MaterialScrollBehavior {
// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
// etc.
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment