欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter pageview切換指示器的實現代碼

 更新時間:2019年04月26日 11:51:39   作者:量子  
這篇文章主要介紹了Flutter pageview切換指示器的實現代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

PageView 是一個滑動視圖列表,它也是繼承至 CustomScrollView 的。

在 PageView 里有三個構造函數:

  • PageView - 創(chuàng)建一個可滾動列表。
  • PageView.builder - 創(chuàng)建一個滾動列表,指定數量。
  • PageView.custom - 創(chuàng)建一個可滾動的列表,自定義子項。

效果

代碼

// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:math';
import 'package:flutter/material.dart';

void main() {
 runApp(new MyApp());
}

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
  return new MaterialApp(
   title: 'Flutter Demo',
   home: new MyHomePage(),
   debugShowCheckedModeBanner: false,
  );
 }
}

/// An indicator showing the currently selected page of a PageController
class DotsIndicator extends AnimatedWidget {
 DotsIndicator({
  this.controller,
  this.itemCount,
  this.onPageSelected,
  this.color: Colors.white,
 }) : super(listenable: controller);

 /// The PageController that this DotsIndicator is representing.
 final PageController controller;

 /// The number of items managed by the PageController
 final int itemCount;

 /// Called when a dot is tapped
 final ValueChanged<int> onPageSelected;

 /// The color of the dots.
 ///
 /// Defaults to `Colors.white`.
 final Color color;

 // The base size of the dots
 static const double _kDotSize = 8.0;

 // The increase in the size of the selected dot
 static const double _kMaxZoom = 2.0;

 // The distance between the center of each dot
 static const double _kDotSpacing = 25.0;

 Widget _buildDot(int index) {
  double selectedness = Curves.easeOut.transform(
   max(
    0.0,
    1.0 - ((controller.page ?? controller.initialPage) - index).abs(),
   ),
  );
  double zoom = 1.0 + (_kMaxZoom - 1.0) * selectedness;
  return new Container(
   width: _kDotSpacing,
   child: new Center(
    child: new Material(
     color: color,
     type: MaterialType.circle,
     child: new Container(
      width: _kDotSize * zoom,
      height: _kDotSize * zoom,
      child: new InkWell(
       onTap: () => onPageSelected(index),
      ),
     ),
    ),
   ),
  );
 }

 Widget build(BuildContext context) {
  return new Row(
   mainAxisAlignment: MainAxisAlignment.center,
   children: new List<Widget>.generate(itemCount, _buildDot),
  );
 }
}

class MyHomePage extends StatefulWidget {
 @override
 State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {

 final _controller = new PageController();

 static const _kDuration = const Duration(milliseconds: 300);

 static const _kCurve = Curves.ease;

 final _kArrowColor = Colors.black.withOpacity(0.8);

 final List<Widget> _pages = <Widget>[
  new ConstrainedBox(
   constraints: const BoxConstraints.expand(),
   child: new FlutterLogo(colors: Colors.blue),
  ),
  new ConstrainedBox(
   constraints: const BoxConstraints.expand(),
   child: new FlutterLogo(style: FlutterLogoStyle.stacked, colors: Colors.red),
  ),
  new ConstrainedBox(
   constraints: const BoxConstraints.expand(),
   child: new FlutterLogo(style: FlutterLogoStyle.horizontal, colors: Colors.green),
  ),
 ];

 @override
 Widget build(BuildContext context) {
  return new Scaffold(
   body: new IconTheme(
    data: new IconThemeData(color: _kArrowColor),
    child: new Stack(
     children: <Widget>[
      new PageView.builder(
       physics: new AlwaysScrollableScrollPhysics(),
       controller: _controller,
       itemBuilder: (BuildContext context, int index) {
        return _pages[index % _pages.length];
       },
      ),
      new Positioned(
       bottom: 0.0,
       left: 0.0,
       right: 0.0,
       child: new Container(
        color: Colors.grey[800].withOpacity(0.5),
        padding: const EdgeInsets.all(20.0),
        child: new Center(
         child: new DotsIndicator(
          controller: _controller,
          itemCount: _pages.length,
          onPageSelected: (int page) {
           _controller.animateToPage(
            page,
            duration: _kDuration,
            curve: _kCurve,
           );
          },
         ),
        ),
       ),
      ),
     ],
    ),
   ),
  );
 }
}

PageView 有以下常用屬性:

  • childrenDelegate → SliverChildDelegate - 子項列表。
  • controller → PageController - 控制臺。
  • onPageChanged → ValueChanged - 索引改變時觸發(fā)。
  • pageSnapping → bool - 設置為 false 以禁用頁面捕捉,對自定義滾動行為很有用。
  • physics → ScrollPhysics - 頁面視圖如何響應用戶輸入,即滾動的動畫表現。
  • reverse → bool - 是否反方向。
  • scrollDirection → Axis - 視圖滾動的方向。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android自定義View實現拖動自動吸邊效果

    Android自定義View實現拖動自動吸邊效果

    這篇文章主要為大家詳細介紹了Android自定義View實現拖動自動吸邊效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Android?Studio中如何修改APP圖標和APP名稱

    Android?Studio中如何修改APP圖標和APP名稱

    這篇文章主要介紹了Android?Studio中如何修改APP圖標和APP名稱,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 詳解Android的內存優(yōu)化--LruCache

    詳解Android的內存優(yōu)化--LruCache

    LruCache是基于Lru算法實現的一種緩存機制。本文對LruCache的概念和實現原理進行介紹,通過實例分析和使用介紹,讓大家更好的了解LruCache,下面跟著小編一起來看下吧
    2016-12-12
  • Android滑動事件沖突詳解(一)

    Android滑動事件沖突詳解(一)

    這篇文章主要為大家詳細介紹了Android滑動事件沖突,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android實現后臺開啟服務默默拍照功能

    Android實現后臺開啟服務默默拍照功能

    這篇文章主要為大家詳細介紹了Android實現后臺開啟服務默默拍照功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android反編譯程序整理詳解

    Android反編譯程序整理詳解

    很多做安卓開發(fā)的朋友都在尋找好的反編譯軟件和方法,小編給大家整理的很多目前流行的Android反編譯程序,希望能夠給你提供參考。
    2017-11-11
  • 操作SD卡中文件夾和文件的方法

    操作SD卡中文件夾和文件的方法

    操作SD卡中文件夾和文件的方法,需要的朋友可以參考一下
    2013-04-04
  • Android開發(fā)之開發(fā)者頭條(一)啟動頁實現

    Android開發(fā)之開發(fā)者頭條(一)啟動頁實現

    這篇文章主要介紹了Android開發(fā)之開發(fā)者頭條(一)啟動頁實現的相關資料,需要的朋友可以參考下
    2016-04-04
  • Android入門之使用SimpleAdapter實現復雜界面布局

    Android入門之使用SimpleAdapter實現復雜界面布局

    這篇文章主要為大家詳細介紹了Android如何使用SimpleAdapter實現復雜的界面布局,文中的示例代碼講解詳細,對我們學習Android有一定的幫助,需要的可以參考一下
    2022-11-11
  • 教你一步步實現Android微信自動搶紅包

    教你一步步實現Android微信自動搶紅包

    自從微信添加搶紅包的功能,微信的電商之旅算是正式開始正式火爆起來。但是作為Android開發(fā)者來說,我們首先考慮的是如何實現Android微信自動搶紅包呢,下面我們來一起看看吧。
    2016-08-08

最新評論