前言
Flutter是谷歌的移動(dòng)UI框架,可以快速在iOS和Android上構(gòu)建高質(zhì)量的原生用戶界面。
IT界著名的尼古拉斯·高爾包曾說:輪子是IT進(jìn)步的階梯!熱門的框架千篇一律,好用輪子萬里挑一!Flutter作為這兩年開始崛起的跨平臺(tái)開發(fā)框架,其第三方生態(tài)相比其他成熟框架還略有不足,但輪子的數(shù)量也已經(jīng)很多了。本系列文章挑選日常app開發(fā)常用的輪子分享出來,給大家提高搬磚效率,同時(shí)也希望flutter的生態(tài)越來越完善,輪子越來越多。
本系列文章準(zhǔn)備了超過50個(gè)輪子推薦,工作原因,盡量每1-2天出一篇文章。
tip:本系列文章合適已有部分flutter基礎(chǔ)的開發(fā)者,入門請(qǐng)戳:flutter官網(wǎng)
正文
輪子
- 輪子名稱:like_button
- 輪子概述:推特點(diǎn)贊效果帶數(shù)量滾動(dòng)動(dòng)畫
- 輪子作者:zmtzawqlp
- 推薦指數(shù):★★★★
- 常用指數(shù):★★★★
-
效果預(yù)覽:
效果圖
安裝
dependencies:
like_button: ^0.1.9
import 'package:like_button/like_button.dart';
用法介紹
用法很簡(jiǎn)單,就一個(gè)widget:
LikeButton()
帶數(shù)字:
LikeButton(likeCount:520)
自定義圖標(biāo):
LikeButton(
likeBuilder: (bool isLiked){
return Icon(Icons.person);
},
)
自定義圖標(biāo)+數(shù)字:
LikeButton(
likeBuilder: (bool isLiked){
return Icon(Icons.person);
},
likeCount:520
)
自定義圖標(biāo)+自定義泡泡顏色+數(shù)字:
LikeButton(
likeBuilder: (bool isLiked){
return Icon(Icons.person,color: isLiked ? Colors.blue : Colors.grey,);
},
likeCount:520,
circleColor:CircleColor(start: Color(0xff00ddff), end: Color(0xff0099cc)),
bubblesColor: BubblesColor(
dotPrimaryColor: Color(0xff33b5e5),
dotSecondaryColor: Color(0xff0099cc),
),
)
自定義圖標(biāo)+自定義泡泡顏色+數(shù)字修飾:
LikeButton(
likeBuilder: (bool isLiked){
return Icon(Icons.person,color: isLiked ? Colors.blue : Colors.grey,);
},
likeCount:520,
circleColor:CircleColor(start: Color(0xff00ddff), end: Color(0xff0099cc)),
bubblesColor: BubblesColor(
dotPrimaryColor: Color(0xff33b5e5),
dotSecondaryColor: Color(0xff0099cc),
),
countBuilder: (int count, bool isLiked, String text) {
var color = isLiked?Colors.red:Colors.grey;
Widget result;
result = Text(
text,
style: TextStyle(color: color,fontSize: 20),
);
return result;
},
countDecoration:(Widget count){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
count,
SizedBox(
width: 10.0,
),
Text(
"loves",
style: TextStyle(color: Colors.indigoAccent),
)
],
);
}
)
請(qǐng)求時(shí)改變狀態(tài)
LikeButton(
onTap: (bool isLiked)
{
return onLikeButtonTap(isLiked, item);
}
)
這是一個(gè)異步回調(diào),你可以等待服務(wù)返回之后再改變狀態(tài)。也可以先改變狀態(tài),請(qǐng)求失敗之后重置回狀態(tài)
Future<bool> onLikeButtonTap(bool isLiked, TuChongItem item) {
///send your request here
///
final Completer<bool> completer = new Completer<bool>();
Timer(const Duration(milliseconds: 200), () {
item.isFavorite = !item.isFavorite;
item.favorites =
item.isFavorite ? item.favorites + 1 : item.favorites - 1;
// if your request is failed,return null,
completer.complete(item.isFavorite);
});
return completer.future;
}
詳細(xì)參數(shù)
| 參數(shù) | 描述 | 默認(rèn) | |
|---|---|---|---|
| size | like Widget的大小 | 30.0 | |
| animationDuration | like widget動(dòng)畫的時(shí)間 | const Duration(milliseconds: 1000) | |
| bubblesSize | 動(dòng)畫時(shí)候的泡泡的大小 | size * 2.0 | |
| bubblesColor | 動(dòng)畫時(shí)候的泡泡的顏色,需要設(shè)置4種 | const BubblesColor(dotPrimaryColor: const Color(0xFFFFC107),dotSecondaryColor: const Color(0xFFFF9800),dotThirdColor: const Color(0xFFFF5722),dotLastColor: const Color(0xFFF44336),) | |
| circleSize | 動(dòng)畫時(shí)候的圈的最大大小 | size * 0.8 | |
| circleColor | 動(dòng)畫時(shí)候的圈的顏色,需要設(shè)置2種 | const CircleColor(start: const Color(0xFFFF5722), end: const Color(0xFFFFC107) | |
| onTap | 點(diǎn)擊時(shí)候的回調(diào),你可以在里面請(qǐng)求服務(wù)改變狀態(tài) | ||
| isLiked | 是否喜歡。如果設(shè)置null的話,將會(huì)一直有動(dòng)畫,而且喜歡數(shù)量一直增長 | false | |
| likeCount | 喜歡數(shù)量。如果為null的話,不顯示 | null | |
| mainAxisAlignment | MainAxisAlignment ,like widget和like count widget是放在一個(gè)Row里面的,對(duì)應(yīng)Row的mainAxisAlignment屬性 | MainAxisAlignment.center | |
| likeBuilder | like widget的創(chuàng)建回調(diào) | null | |
| countBuilder | like count widget的創(chuàng)建回調(diào) | null | |
| likeCountAnimationDuration | 喜歡數(shù)量變化動(dòng)畫的時(shí)間 | const Duration(milliseconds: 500) | |
| likeCountAnimationType | 喜歡數(shù)量動(dòng)畫的類型(none,part,all)。沒有動(dòng)畫;只動(dòng)畫改變的部分;全部部分 | LikeCountAnimationType.part | |
| likeCountPadding | like count widget 跟 like widget的間隔 | const EdgeInsets.only(left: 3.0) | |
| countPostion | top,right,bottom,left. count的位置(上下左右) | CountPostion.right | |
| countDecoration | count 的修飾器,你可以通過它為count增加其他文字或者效果 | null |
