Created
November 17, 2021 06:39
-
-
Save rayliverified/3dd62fcb66dfaee91b9cd17d29292e83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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