為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):2637
flutter 插件
flutter 跑馬燈
可以指定跑馬燈的方向
可以傳入數(shù)組,可以是自定義的widget
可以控制跑馬燈的時(shí)間間隔
控制點(diǎn)擊事件等等
https://github.com/LiuC520/flutter_marquee
dependencies: flutter: sdk: flutter flutter_marquee: git: https://github.com/LiuC520/flutter_marquee.git
Attribute 屬性 | Description 描述 |
---|---|
children | 自定義的widget組件數(shù)組 |
texts | 也可以傳入 字符串?dāng)?shù)組 |
seletedTextColor | 當(dāng)前顯示text的顏色,只有texts有值才生效 |
textColor | 其他text的顏色,只有texts有值才生效 |
duration | 跑馬燈的切換時(shí)長(zhǎng) 默認(rèn)是4秒 |
itemDuration | 單個(gè)item的動(dòng)畫(huà)出現(xiàn)或者退出時(shí)長(zhǎng) 默認(rèn)是500毫秒 |
autoStart | 是否自動(dòng)開(kāi)始動(dòng)畫(huà) |
animationDirection | 動(dòng)畫(huà)顯示的切換方式,默認(rèn)是從上往下切換: AnimationDirection.l2r、AnimationDirection.r2l、AnimationDirection.t2b、AnimationDirection.b2t |
animateDistance | 移動(dòng)的距離: 如果沒(méi)有設(shè)置就是默認(rèn)獲取組件寬高,橫向動(dòng)畫(huà)就是組建的寬度,縱向的就是組件的高度 |
singleLine | 是否是單行顯示: 默認(rèn)是false |
onChange | 點(diǎn)擊事件回調(diào): 回調(diào)的參數(shù)是跑馬燈的widget的下標(biāo) |
1、首先在pubspec.yaml中添加依賴(lài)
dependencies: flutter: sdk: flutter flutter_marquee: git: https://github.com/flutter_marquee/flutter_marquee.git
import 'package:flutter_marquee/flutter_marquee.dart'; Column( children: <Widget>[ Column( children: <Widget>[ Text("從下到上,時(shí)間間隔6秒,傳入的是字符串?dāng)?shù)組"), Container( margin: EdgeInsets.all(4), height: 60, width: 200, decoration: BoxDecoration( border: Border.all(width: 2, color: Colors.red), borderRadius: BorderRadius.all(Radius.circular(8))), child: FlutterMarquee( texts: ["劉成", "劉成1111", "劉成2222", "劉成3333"].toList(), onChange: (i) { print(i); }, duration: 4), ) ], ), Column( children: <Widget>[ Text("從上到下,時(shí)間間隔8秒,傳入的是自定義的text widget"), Container( margin: EdgeInsets.all(4), height: 60, width: 200, decoration: BoxDecoration( border: Border.all(width: 2, color: Colors.red), borderRadius: BorderRadius.all(Radius.circular(8))), child: FlutterMarquee( children: <Widget>[ Text( "劉成", style: TextStyle(color: Colors.red), ), Text("劉成1111", style: TextStyle(color: Colors.green)), Text("劉成2222", style: TextStyle(color: Colors.blue)), Text("劉成3333", style: TextStyle(color: Colors.yellow)), ], onChange: (i) { print(i); }, animationDirection: AnimationDirection.t2b, duration: 8), ) ], ), Column( children: <Widget>[ Text("從左到右,時(shí)間間隔2秒,自定義的view"), Container( margin: EdgeInsets.all(4), height: 60, width: 200, decoration: BoxDecoration( border: Border.all(width: 2, color: Colors.red), borderRadius: BorderRadius.all(Radius.circular(8))), child: FlutterMarquee( children: <Widget>[ Center( child: Row( children: <Widget>[ Icon(Icons.menu), Text( "劉成", style: TextStyle(color: Colors.green), ), ], ), ), Center( child: Row( children: <Widget>[ Icon(Icons.add), Text( "劉成1111", style: TextStyle(color: Colors.red), ), ], ), ), Center( child: Row( children: <Widget>[ Icon(Icons.satellite), Text( "劉成2222", style: TextStyle(color: Colors.blue), ), ], ), ), Center( child: Row( children: <Widget>[ Icon(Icons.format_align_justify), Text("劉成3333", style: TextStyle(color: Colors.yellow)), ], ), ), ], onChange: (i) { print(i); }, animationDirection: AnimationDirection.l2r, duration: 2), ) ], ), Column( children: <Widget>[ Text("從右到左,時(shí)間間隔6秒"), Container( margin: EdgeInsets.all(4), height: 60, width: 200, decoration: BoxDecoration( border: Border.all(width: 2, color: Colors.red), borderRadius: BorderRadius.all(Radius.circular(8))), child: FlutterMarquee( texts: ["劉成", "劉成1111", "劉成2222", "劉成3333"].toList(), onChange: (i) { print(i); }, animationDirection: AnimationDirection.r2l, duration: 6), ) ], ),