main.dart
import 'package:flutter/material.dart';
void main() => runApp(const FlutterExample());
class FlutterExample extends StatelessWidget {
const FlutterExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(primarySwatch: Colors.orange),
home: const StateExample()
);
}
}
class StateExample extends StatefulWidget {
const StateExample({Key? key}) : super(key: key);
@override
_StateExampleState createState() => _StateExampleState();
}
class _StateExampleState extends State<StateExample> {
final PageController controller = PageController(initialPage: 0);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
title: const Text("Flutter - PageView Disable Swipe")
),
body: bodyContent()
);
}
bodyContent(){
return PageView(
scrollDirection: Axis.horizontal,
controller: controller,
// scroll physics that does not let the user scroll.
physics:const NeverScrollableScrollPhysics(),
children: <Widget>[
pageContent(Colors.grey, "Grey"),
pageContent(Colors.purple, "Purple"),
pageContent(Colors.teal, "Teal"),
],
);
}
pageContent(Color color, String text){
return Container(
color: color,
child: Center(
child: Text(
text,
style: const TextStyle(
fontSize: 45,
fontWeight: FontWeight.bold
),
),
),
);
}
}
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/06/1a6b6-flutterpageviewdisableswipe.png)
More flutter tutorials
- flutter – Rounded button example
- flutter – Floating action button example
- flutter – How to use TextField
- flutter – TextField border size
- flutter – TextField border shadow
- flutter – TextField text color
- flutter – TextField hint
- flutter – Floating label behavior
- flutter – TextField decoration
- flutter – TextField suffix text and icon
- flutter – TextField onChanged
- flutter – Slider label
- flutter – RangeSlider example
- flutter – RangeSlider labels
- flutter – PageView example