Flutter加载指示器插件loading_indicator_view_plus的使用
Flutter加载指示器插件loading_indicator_view_plus的使用
简介
loading_indicator_view_plus
是一个用于Flutter应用中的加载动画集合。该库是从 Hitomis/loading_indicator_view
演化而来的。
示例效果
使用方法
-
在
pubspec.yaml
文件中添加依赖:dependencies: loading_indicator_view_plus: ^2.0.0
-
运行
flutter pub get
更新依赖包。
动画类型
以下是可用的动画类型:
序号 | 类型 |
---|---|
1 | LineSpinFadeLoader |
2 | BallBeat |
3 | BallClipRotateMultiple |
4 | BallGridPulse |
5 | LineScale |
6 | BallPulseRise |
7 | BallScaleRippleMultiple |
8 | BallZigZag |
9 | BallScale |
10 | BallPulseSync |
11 | BallScaleMultiple |
12 | BallPulse |
13 | BallClipRotatePulse |
14 | BallGridBeat |
15 | SquareSpin |
16 | BallSpinFadeLoader |
17 | BallScaleRipple |
18 | SemiCircleSpin |
19 | LineScalePulseOut |
20 | BallClipRotate |
21 | Pacman |
22 | BallRotate |
23 | CubeTransition |
24 | TriangleSkewSpin |
完整示例代码
import 'package:flutter/material.dart';
import 'package:loading_indicator_view_plus/loading_indicator_view_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Loading indicator view plus Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _orderNum = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 185, 63, 81),
appBar: AppBar(
title: Text(widget.title),
),
body: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
childAspectRatio: 1.0,
),
children: [
wrapOrder(Center(child: LineSpinFadeLoaderIndicator())),
wrapOrder(Center(child: BallBeatIndicator())),
wrapOrder(Center(child: BallClipRotateMultipleIndicator())),
wrapOrder(Center(child: BallGridPulseIndicator())),
wrapOrder(Center(child: LineScaleIndicator())),
wrapOrder(Center(child: BallPulseRiseIndicator())),
wrapOrder(Center(child: BallScaleRippleMultipleIndicator())),
wrapOrder(Center(child: BallZigZagIndicator())),
wrapOrder(Center(child: BallScaleIndicator())),
wrapOrder(Center(child: BallPulseSyncIndicator())),
wrapOrder(Center(child: BallScaleMultipleIndicator())),
wrapOrder(Center(child: BallPulseIndicator())),
wrapOrder(Center(child: BallClipRotatePulseIndicator())),
wrapOrder(Center(child: BallGridBeatIndicator())),
wrapOrder(Center(child: SquareSpinIndicator())),
wrapOrder(Center(child: BallSpinFadeLoaderIndicator())),
wrapOrder(Center(child: BallScaleRippleIndicator())),
wrapOrder(Center(child: SemiCircleSpinIndicator())),
wrapOrder(Center(child: LineScalePulseOutIndicator())),
wrapOrder(Center(child: BallClipRotateIndicator())),
wrapOrder(Center(child: PacmanIndicator())),
wrapOrder(Center(child: BallRotateIndicator())),
wrapOrder(Center(child: CubeTransitionIndicator())),
wrapOrder(Center(child: TriangleSkewSpinIndicator())),
],
),
);
}
@override
void didUpdateWidget(MyHomePage oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget != widget) {
_orderNum = 1;
}
}
Widget wrapContainer(Widget child, [Color backgroundColor = Colors.green]) =>
Container(color: backgroundColor, child: child);
Widget wrapOrder(Widget child) => Stack(children: [
child,
Positioned(
left: 8,
bottom: 0,
child: Text("${_orderNum++}",
style: const TextStyle(color: Colors.white, fontSize: 18)),
),
]);
}
许可证
Copyright 2019 Hitomis, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
更多关于Flutter加载指示器插件loading_indicator_view_plus的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter加载指示器插件loading_indicator_view_plus的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
loading_indicator_view_plus
是一个用于 Flutter 的插件,它提供了多种加载指示器(Loading Indicators)的样式,可以帮助你在应用加载数据或执行耗时操作时显示一个漂亮的加载动画。
安装插件
首先,你需要在 pubspec.yaml
文件中添加 loading_indicator_view_plus
依赖:
dependencies:
flutter:
sdk: flutter
loading_indicator_view_plus: ^1.0.0+2 # 请根据最新版本号进行更新
然后运行 flutter pub get
来安装依赖。
基本使用
loading_indicator_view_plus
提供了多种加载指示器样式,你可以通过 Indicator
枚举来选择不同的样式。以下是一个简单的示例:
import 'package:flutter/material.dart';
import 'package:loading_indicator_view_plus/loading_indicator_view_plus.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Loading Indicator Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 使用 LineSpinFadeLoader 加载指示器
LoadingIndicator(
indicatorType: Indicator.lineSpinFadeLoader,
colors: [Colors.blue, Colors.green, Colors.red],
strokeWidth: 2.0,
),
SizedBox(height: 20),
Text('Loading...'),
],
),
),
),
);
}
}
参数说明
indicatorType
: 指定加载指示器的样式。Indicator
枚举中包含了多种样式,例如lineSpinFadeLoader
,ballSpinFadeLoader
,ballPulseSync
, 等等。colors
: 设置加载指示器的颜色。你可以传递一个颜色列表,指示器会使用这些颜色进行动画。strokeWidth
: 设置加载指示器的线条宽度(仅适用于某些样式的指示器)。
其他样式
loading_indicator_view_plus
支持多种加载指示器样式,以下是一些常见的样式示例:
LoadingIndicator(
indicatorType: Indicator.ballSpinFadeLoader,
colors: [Colors.blue, Colors.green, Colors.red],
),
LoadingIndicator(
indicatorType: Indicator.ballPulseSync,
colors: [Colors.purple, Colors.orange, Colors.blue],
),
LoadingIndicator(
indicatorType: Indicator.circleStrokeSpin,
colors: [Colors.teal, Colors.pink, Colors.yellow],
),
自定义颜色和大小
你可以通过 colors
参数自定义加载指示器的颜色,并通过 strokeWidth
参数调整线条的宽度。例如:
LoadingIndicator(
indicatorType: Indicator.lineSpinFadeLoader,
colors: [Colors.red, Colors.blue, Colors.green],
strokeWidth: 3.0,
),