Flutter动画加载指示器插件flutter_animated_loadingkit的使用

Flutter动画加载指示器插件flutter_animated_loadingkit的使用

✨ Flutter Animated Loadingkit ✨

这是一个由Flutter动画实现的自定义加载指示器集合。

安装

pubspec.yaml文件中添加依赖:

dependencies:
  flutter_animated_loadingkit: ^0.0.7

导入

在Dart文件中导入此包:

import 'package:flutter_animated_loadingkit/flutter_animated_loadingkit.dart';

使用方法

下面是一个创建SideWaySurge加载指示器的例子:

const loader = AnimatedLoadingSideWaySurge(
  expandWidth: 70,
  borderColor: Colors.black,
  speed: Duration(milliseconds: 600),
);

示例代码

下面提供了一个完整的示例demo,您可以直接运行这个例子来查看不同类型的加载指示器。

main.dart

import 'package:flutter/material.dart';
import 'package:flutter_animated_loadingkit/flutter_animated_loadingkit.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Animated LoadingKit Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            // 创建一个SideWaySurge加载指示器
            const AnimatedLoadingSideWaySurge(
              expandWidth: 70,
              borderColor: Colors.black,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Circle Surge加载指示器
            const CircleSurge(
              size: 70,
              color: Colors.red,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Dual Surge加载指示器
            const DualSurge(
              size: 70,
              color1: Colors.green,
              color2: Colors.blue,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Face Surge加载指示器
            const FaceSurge(
              size: 70,
              color: Colors.purple,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Round Burst加载指示器
            const RoundBurst(
              size: 70,
              color: Colors.orange,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Floral Burst加载指示器
            const FloralBurst(
              size: 70,
              color: Colors.pink,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Star Burst加载指示器
            const StarBurst(
              size: 70,
              color: Colors.teal,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Waving Line加载指示器
            const WavingLine(
              width: 100,
              height: 50,
              color: Colors.deepOrange,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Heart Beat加载指示器
            const HeartBeat(
              size: 70,
              color: Colors.red,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Infinity Spin加载指示器
            const InfinitySpin(
              size: 70,
              color: Colors.indigo,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Tango加载指示器
            const Tango(
              size: 70,
              color: Colors.brown,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Spinner加载指示器
            const Spinner(
              size: 70,
              color: Colors.cyan,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Jumping Dots加载指示器
            const JumpingDots(
              size: 70,
              dotColor: Colors.grey,
              backgroundColor: Colors.white,
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Firework加载指示器
            const Firework(
              size: 70,
              colors: [Colors.red, Colors.green, Colors.blue],
              speed: Duration(milliseconds: 600),
            ),
            SizedBox(height: 20,),
            // 创建一个Spiral Lines加载指示器
            const SpiralLines(
              size: 70,
              color: Colors.amber,
              speed: Duration(milliseconds: 600),
            ),
          ],
        ),
      ),
    );
  }
}

示例

以下是几种加载指示器的效果图:

Side-Way Surge Circle Surge Dual Surge Face Surge Round Burst
Side-Way Surge Circle Surge Dual Surge Face Surge Round Burst
Floral Burst Star Burst Waving Line Heart Beat Infinity Spin
Floral Burst Star Burst Waving Line Heart Beat Infinity Spin
Tango Spinner Jumping Dots Firework Spiral Lines
Tango Spinner Jumping Dots Firework Spiral Lines

如果您喜欢这个包,请不要忘记点击⭐️按钮!

谢谢并祝您编码愉快 👻


更多关于Flutter动画加载指示器插件flutter_animated_loadingkit的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter动画加载指示器插件flutter_animated_loadingkit的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


当然,以下是如何在Flutter项目中使用flutter_animated_loadingkit插件来实现动画加载指示器的示例代码。flutter_animated_loadingkit是一个流行的Flutter插件,用于在应用中显示加载动画。

首先,确保你的Flutter项目中已经添加了flutter_animated_loadingkit依赖。在你的pubspec.yaml文件中添加以下依赖:

dependencies:
  flutter:
    sdk: flutter
  flutter_animated_loadingkit: ^x.y.z  # 替换为最新版本号

然后运行flutter pub get来安装依赖。

以下是一个简单的示例,展示如何在Flutter应用中使用flutter_animated_loadingkit

import 'package:flutter/material.dart';
import 'package:flutter_animated_loadingkit/flutter_animated_loadingkit.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Animated LoadingKit Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoadingScreen(),
    );
  }
}

class LoadingScreen extends StatefulWidget {
  @override
  _LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> with SingleTickerProviderStateMixin {
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();
    // 模拟加载过程,3秒后停止加载动画
    Future.delayed(Duration(seconds: 3), () {
      setState(() {
        _isLoading = false;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Loading Indicator Demo'),
      ),
      body: Center(
        child: _isLoading
            ? Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  // 使用FlutterAnimatedLoadingKit的BallBounceLoading
                  BallBounceLoading(
                    size: 50.0,
                    color: Colors.blue,
                  ),
                  SizedBox(height: 20),
                  Text(
                    'Loading...',
                    style: TextStyle(fontSize: 20),
                  ),
                ],
              )
            : Text('Loading Complete!'),
      ),
    );
  }
}

在这个示例中,我们创建了一个简单的Flutter应用,其中包含一个加载屏幕。在加载屏幕中,我们使用BallBounceLoading来显示一个加载动画,并在3秒后停止加载动画,显示“Loading Complete!”文本。

关键点

  1. 依赖添加:在pubspec.yaml中添加flutter_animated_loadingkit依赖。
  2. 导入包:在代码文件中导入flutter_animated_loadingkit包。
  3. 使用动画组件:使用BallBounceLoading(或其他提供的加载动画组件)来显示加载动画。
  4. 状态管理:通过Flutter的状态管理(如setState)来控制加载动画的显示与隐藏。

你可以根据需要替换BallBounceLoadingflutter_animated_loadingkit提供的其他加载动画组件,如BallClipRotateLoadingBallTrianglePathLoading等。

希望这个示例对你有帮助!如果你有任何其他问题,请随时询问。

回到顶部