-
Toast
1.添加依賴
toast: ^0.1.3
然后
import 'package:toast/toast.dart';
調(diào)用toast:
Toast.show("", context, duration: Toast.LENGTH_SHORT);
-
圖片加載緩存cached_network_image
1.添加依賴
cached_network_image: ^2.3.3
2.使用控件
CachedNetworkImage(
imageUrl: "",
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
)
-
添加WebView加載網(wǎng)頁
Android里面有的WebView,F(xiàn)lutter里面也得有吱晒。
1.添加依賴
dependencies:
flutter_webview_plugin: ^0.2.1+2
2.使用前引入
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class MyWebView extends StatefulWidget {
_MyWebView createState() => _MyWebView();
}
class _MyWebView extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: WebviewScaffold(url: "https://www.baidu.com",
// 允許網(wǎng)頁縮放
withZoom: true,
// 允許LocalStorage
withLocalStorage: true,
withJavascript: true),
)
);
}
}
-
刷新加載庫 flutter_easyrefresh
顧名思義,EasyRefresh非常簡單上手就能在Flutter應(yīng)用上實現(xiàn)下拉刷新以及上拉加載操作,它支持幾乎所有的Flutter控件。它與Android里面的庫SmartRefreshLayout非常像,刷新加載風(fēng)格可以div觉阅。
1.添加依賴
flutter_easyrefresh: ^2.1.0
2.屬性介紹:
EasyRefresh(
// 是否開啟控制結(jié)束加載
enableControlFinishLoad: false,
// 控制器
controller: _controller,
// 自定義頂部上啦加載
footer: ClassicalFooter(
bgColor: Colors.white,
// 更多信息文字顏色
infoColor: KColor.refreshTextColor,
// 字體顏色
textColor: KColor.refreshTextColor,
// 加載失敗時顯示的文字
loadText: KString.loadFailedText,
// 沒有更多時顯示的文字
noMoreText: '',
// 是否顯示提示信息
showInfo: false,
// 正在加載時的文字
loadingText: KString.loading,
// 準備加載時顯示的文字
loadReadyText: KString.loadReadyText,
// 加載完成顯示的文字
loadedText: KString.loadedText,
)
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
//刷新加載控件封裝
class MyEasyRefresh extends StatelessWidget {
EasyRefreshController easyRefreshController;
Widget listView;
MyEasyRefresh(this.listView) {
easyRefreshController = EasyRefreshController();
}
@override
Widget build(BuildContext context) {
return EasyRefresh(
controller: easyRefreshController,
enableControlFinishRefresh: false,
enableControlFinishLoad: false,
header: ClassicalHeader(
textColor: Colors.black87,
refreshText: "往下拉稻爬,往下拉",
refreshedText: "刷新完成",
refreshingText: "正在刷新",
refreshReadyText: "快放手"
),
footer: ClassicalFooter(
textColor: Colors.black87,
loadText: "往上拉嗜闻,往上拉",
loadedText: "加載完成",
loadingText: "正在加載",
loadReadyText: "快放手"
),
onRefresh: () async {
print("刷新完成");
},
onLoad: () async {
print("加載完成");
},
child: listView);
}
}
-
自動輪播控件flutter_swiper
1.引入庫
flutter_swiper: ^1.1.6
2.使用示例:
Swiper(
itemBuilder: (BuildContext context,int index){
return new Image.network("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603442938191&di=6d134b40bcc1e448fa4654faaebdf827&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170312%2F325af66b3351496783fd3cb4750f6759_th.jpg",
fit: BoxFit.fill);
},
itemCount: 3,
pagination: SwiperPagination(),
controller: new SwiperController(),
)
-
視頻播放器videoPlayer
1.引入庫
video_player: ^0.11.1+2
2.使用示例:
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(VideoApp());
class VideoApp extends StatefulWidget {
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
-
網(wǎng)絡(luò)請求庫dio
1.引入庫
dio: ^3.0.10
2.使用示例:
簡單用法:
Response response;
Dio dio = new Dio();
response = await dio.get("");
print(response.data.toString());
post傳參請求:
FormData formData = new FormData.fromMap({
"name": "wendux",
"age": 25,
});
response = await dio.post("", data: formData);
參考:
Flutter常用的庫