Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement PageView sliding View Flutter

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to achieve PageView Slide View Flutter", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve PageView sliding view Flutter"!

Import 'package:flutter/cupertino.dart';import' package:flutter/material.dart';void main () = > runApp (MaterialApp (home: MyApp (); / / create a PageController to make it easy to use the bottom navigation bar to change the content of PageView PageController _ pageController = new PageController (); int _ curIndex = 0 PageController / current index / / solid color page, batch generate var pages = [Page (Colors.orange), Page (Colors.purple), Page (Colors.green)] with Page class constructor Class Page extends StatelessWidget {Color c; Page (this.c); @ override Widget build (BuildContext context) {return Scaffold (body: Container (color: C,),);}} class MyApp extends StatefulWidget {@ override _ MyAppState createState () = > _ MyAppState () } class _ MyAppState extends State {@ override Widget build (BuildContext context) {return Scaffold (appBar: AppBar (title: Text ("sliding"),), / / PageView sliding interface [https://www.jianshu.com/p/036c3b865820] body: PageView.builder (controller: _ pageController, itemBuilder: (context,index) = > pages [index], itemCount: pages.length / / change the current index when sliding, and refresh the interface onPageChanged: (index) {setState (() {_ curIndex = index) }) },), / / create the bottom navigation bar bottomNavigationBar: BottomNavigationBar (items: [BottomNavigationBarItem (title: Text ("Orange"), icon:Icon (Icons.star)), BottomNavigationBarItem (title: Text ("Purple"), icon:Icon (Icons.star)) BottomNavigationBarItem (title: Text ("Green"), icon:Icon (Icons.star))], currentIndex: _ curIndex, / / use Controller to change PageView onTap: (index) {_ pageController.jumpToPage (index) in the navigation bar ),);}} at this point, I believe you have a deeper understanding of "how to implement PageView sliding View Flutter". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report