Flutter 篇 輪播圖 flutter_swiper
新增依賴
flutter_swiper: ^1.1.6 #輪播外掛
最新版本看:https://pub.dev/packages/flutter_swiper#-readme-tab-
Pub get 之後,引用
import 'package:flutter_swiper/flutter_swiper.dart';
效果圖
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class SwiperPage extends StatefulWidget {
@override
_SwiperState createState() => _SwiperState();
}
class _SwiperState extends State<SwiperPage> {
List<Image> imgs = [
//建立了一個圖片陣列
Image.asset(
'lib/images/swiper1.jpg',
fit: BoxFit.cover,
),
Image.asset(
'lib/images/swiper2.jpg',
fit: BoxFit.cover,
),
Image.asset(
'lib/images/swiper3.jpg',
fit: BoxFit.cover,
),
Image.asset(
'lib/images/swiper4.jpg',
fit: BoxFit.cover,
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("圖片輪播"),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Text("樣式1:"),
Container(
height: 175,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
//條目構建函式傳入了index,根據index索引到特定圖片
return imgs[index];
},
itemCount: imgs.length,
autoplay: true,//
pagination: new SwiperPagination(), //頁碼,通俗講就是下邊的圓點 這些都是控制元件預設寫好的,直接用
control: new SwiperControl(),//控制器,通俗講就是兩邊的箭頭
),
),
Text("樣式2:"),
Container(
height: 175,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return imgs[index];
},
itemCount: imgs.length,
autoplay: true,
pagination: new SwiperPagination(),
control: new SwiperControl(),
viewportFraction: 0.8,
scale: 0.9,
),
),
Text("樣式3:"),
Container(
height: 175,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return imgs[index];
},
itemCount: imgs.length,
autoplay: true,
pagination: new SwiperPagination(),
control: new SwiperControl(),
itemWidth: 300.0,
layout: SwiperLayout.STACK,
),
),
Text("樣式4:"),
Container(
height: 175,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return imgs[index];
},
itemCount: imgs.length,
autoplay: true,
pagination: new SwiperPagination(),
control: new SwiperControl(),
itemWidth: 300.0,
itemHeight: 400.0,
layout: SwiperLayout.TINDER,
),
),
Text("樣式5:"),
Container(
height: 175,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return imgs[index];
},
itemCount: imgs.length,
autoplay: true,
pagination: new SwiperPagination(),
control: new SwiperControl(),
layout: SwiperLayout.CUSTOM,
customLayoutOption: new CustomLayoutOption(
startIndex: -1, stateCount: 3)
.addRotate([-45.0 / 180, 0.0, 45.0 / 180]).addTranslate([
new Offset(-370.0, -40.0),
new Offset(0.0, 0.0),
new Offset(370.0, -40.0)
]),
itemWidth: 300.0,
itemHeight: 200.0,
),
),
],
),
),
);
}
}
屬性:
基本屬性
parameter | default | Description |
scrollDirection | Axis.horizontal | 滾動方向 |
loop | true | 是否迴圈 |
index | 0 | 初始索引 |
autoplay | false | 自動輪播 |
onlndexChanged | void onlndexChanged(int index) | 當索引值被改變時觸發的函式 |
onTap | void onTap(int index) | 點選事件 |
duration | 300.0 | 時間間隔 |
pagination | null | 頁碼 |
control | null | 控制器 |
相關文章
- Flutter 拆輪子之flutter_swiper自動無線輪播卡片Flutter
- Flutter輪播圖Flutter
- Flutter 封裝一個 Banner 輪播圖Flutter封裝
- 筆記-Flutter之輪播圖(多樣式)筆記Flutter
- Flutter 如何封裝一個 Banner 輪播圖?Flutter封裝
- 小程式輪播圖應用——技巧篇
- jQuery輪播圖之上下輪播jQuery
- 輪播圖
- flutter好用的輪子推薦三-超強輪播圖SwiperFlutter
- 微信小程式------輪播圖------縱向輪播圖微信小程式
- vue輪播圖Vue
- js 輪播圖 (原生)JS
- 文字輪播與圖片輪播?CSS 不在話下CSS
- ViewPage實現輪播圖View
- Banner實現輪播圖
- vue輪播圖外掛Vue
- 圖片輪播--純cssCSS
- js實現輪播圖JS
- 造輪子之圖片輪播元件(swiper)元件
- 微信小程式swiper輪播圖卡死來回瘋狂輪播微信小程式
- Android 和 iOS 圖片輪播AndroidiOS
- 輪播圖(JavaScript定時器)JavaScript定時器
- 原生js實現輪播圖JS
- uniapp自定義卡片輪播圖APP
- Flutter實現馬蜂窩小紅書自適應高度輪播圖Flutter
- 小說APP原始碼,手動滑動輪播圖時,輪播圖跟隨移動APP原始碼
- Android輪播圖從0到1Android
- react無縫滾動輪播圖React
- 淡入淡出的輪播圖元件元件
- 兩種方式實現輪播圖
- 如何使用JQ封裝輪播圖封裝
- 在 Flutter 中實現一個無限輪播Flutter
- 原生JS實現輪播圖的效果JS
- JavaScript焦點圖輪播效果詳解JavaScript
- vue元件之輪播圖的實現Vue元件
- 用CSS實現一個輪播圖CSS
- 如何使用RecyclerView打造首頁輪播圖View
- [分享會]只用CSS實現輪播圖CSS