App Intro Demo with PageView in Flutter
The PageView widget in Flutter is used to display a scrollable view of multiple pages. Each page is represented by a widget that is built on demand as it is scrolled into view.
The PageView widget is commonly used to implement image galleries, carousels, and swipeable screens in mobile apps.
Code Sample:
import 'package:flutter/material.dart';
class PageViewDemo extends StatelessWidget {
final List _pages = [
Container(color: Colors.blue),
Container(color: Colors.red),
Container(color: Colors.green),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('PageView Demo')),
body: PageView(
children: _pages,
),
);
}
}
Properties:
- children (required): A list of widgets that represent the pages to be displayed in the PageView.
- scrollDirection: The axis along which the pages are scrolled. Default is horizontal.
- pageSnapping: Whether the pages should snap to the start/end of the viewport or be free-flowing. Default is true (snap to start/end).
- controller: A controller that can be used to control the page view programmatically, for example, to jump to a specific page.
- physics: The physics of the scrollable widget. Default is PageScrollPhysics.
- onPageChanged: A callback function that is called when the currently displayed page changes.
- allowImplicitScrolling: Whether the PageView should allow implicit scrolling when a user scrolls beyond the end of the list. Default is false.
- dragStartBehavior: Determines the behavior of the widget when the user starts dragging it. Default is DragStartBehavior.start.
..
App into demo : This Flutter code sample demonstrates how to create an app intro using PageView widget to display images, titles, and descriptions for each page.
import 'package:flutter/material.dart';
class AppIntro extends StatefulWidget {
const AppIntro({super.key});
@override
AppIntroState createState() => AppIntroState();
}
class AppIntroState extends State <AppIntro>{
// Create a PageController to control the PageView
final PageController _pageController = PageController(initialPage: 0);
// Define the pages of the app intro as a list of maps
final List
..
Comments
Post a Comment