Flutter -- 加载动画效果loading 类似iOS的SVProgressHUD效果

效果图

gif


根据需求创建一个自定义的Widget

import 'package:flutter/material.dart';

enum AnimationType {

  ///圆圈模式

  circular,

  ///横线模式

  Linear,

  ///刷新模式

  refresh

}

class KSProgressDialog extends StatelessWidget {

  ///是否显示

  final bool isShow;

  ///提醒内容

  final String? title;

  ///动画效果    默认圆圈模式

  final AnimationType? showType;

  ///背景透明度

  final double? alpha;

  ///字体颜色

  final Color? textColor;

  ///方块背景颜色

  final Color? itemColor;

  const KSProgressDialog(

      {Key? key,

      required this.isShow,

      this.title,

      this.showType = AnimationType.circular,

      this.alpha = 0.1,

      this.textColor = Colors.black,

      this.itemColor = Colors.black12})

      : super(key: key);

  @override

  Widget build(BuildContext context) {

    List<Widget> widgetList = [];

    //1.设置动画效果

    var progressIndicator;

    var needWidth =

        0.0; //Linear 模式下需要设置宽度,不然的话就会占满全屏,传递文字过多的话需要传递一个宽度的参数过来,可自己完善

    switch (showType) {

      case AnimationType.circular:

        progressIndicator = CircularProgressIndicator(

          strokeWidth: 2, //线的宽度

          valueColor: AlwaysStoppedAnimation<Color>(Colors.white), //线的颜色

          backgroundColor: Colors.grey, //圆圈的背景色

        );

        break;

      case AnimationType.Linear:

        title == null ? needWidth = 100 : needWidth = 150;

        progressIndicator = LinearProgressIndicator(

          valueColor: AlwaysStoppedAnimation<Color>(Colors.white), //线的颜色

          backgroundColor: Colors.grey, //圆圈的背景

        );

        break;

      case AnimationType.refresh:

        progressIndicator = RefreshProgressIndicator(

          valueColor: AlwaysStoppedAnimation<Color>(Colors.white), //线的颜色

          backgroundColor: Colors.grey, //圆圈的背景色

        );

        break;

      default:

    }

    if (isShow) {

      Widget progressView;

      if (title == null) {

        progressView = Center(

          child: Container(

            width: needWidth > 0 ? needWidth : null,

            padding: needWidth > 0

                ? EdgeInsets.only(top: 40, bottom: 40, left: 10, right: 10)

                : EdgeInsets.all(30.0),

            decoration: BoxDecoration(

                color: itemColor, borderRadius: BorderRadius.circular(10.0)),

            child: Column(

              mainAxisSize: MainAxisSize.min,

              children: <Widget>[

                progressIndicator,

              ],

            ),

          ),

        );

      } else {

        progressView = Center(

          child: Container(

            width: needWidth > 0 ? needWidth : null,

            padding: const EdgeInsets.all(20.0),

            decoration: BoxDecoration(

                color: itemColor, borderRadius: BorderRadius.circular(4.0)),

            child: Column(

              mainAxisSize: MainAxisSize.min,

              children: <Widget>[

                progressIndicator,

                Container(

                  padding: const EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0),

                  child: Text(

                    title!,

                    style: TextStyle(color: textColor, fontSize: 16.0),

                  ),

                )

              ],

            ),

          ),

        );

      }

      widgetList.add(Opacity(

        opacity: alpha!,

        child: new ModalBarrier(color: Colors.black38),

      ));

      widgetList.add(progressView);

    }

    return Stack(

      children: widgetList,

    );

  }

}

2. 使用举例

@override

  Widget build(BuildContext context) {

    if (isLoading == false) {

      return Scaffold(

        appBar: AppBar(

          title: Text("测试"),

        ),

        body: ListView.builder(

          itemBuilder: (context, index) {

            return _orderItemView();

          },

          itemCount: 10,

        ),

      );

    } else {

      return Scaffold(

        appBar: AppBar(

          title: Text("测试"),

        ),

        body: KSProgressDialog(isShow: true),

      );

    }

  }

具体的效果可以根据自己的情况进行修改,复制即用!

demo地址:

GitHub - Turboks/KSProgress: 加载动画效果loading 类似iOS的SVProgressHUD效果https://github.com/Turboks/KSProgress

欢迎star✨!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Flutter是Google开源的一款跨平台的UI开发框架,可以快速地构建高质量的移动、Web和桌面应用程序。而Embedded Linux是指Linux操作系统在嵌入式设备中的应用。通过将Flutter与Embedded Linux结合起来,可以让开发者在嵌入式设备上创建漂亮且功能强大的应用程序。 Flutter的跨平台特性使得开发者可以使用相同的代码库在多个平台上运行应用程序,包括嵌入式设备。嵌入式设备通常资源有限,但Flutter的轻量级和高性能使得它非常适合在此类设备上运行。Flutter的热重载功能可以让开发者快速迭代和测试应用程序,提高开发效率。 使用Flutter-Embedded Linux,开发者可以利用Flutter的丰富的UI组件和强大的渲染引擎来创建嵌入式设备上的用户界面。Flutter提供了丰富的UI控件和动画效果,可以实现各种视觉效果和交互体验。Flutter还具备良好的跨平台兼容性和高度定制性,可以适应不同嵌入式设备的各种需求。 除此之外,Flutter-Embedded Linux还提供了与Linux操作系统的良好集成,可以调用底层系统资源和API,如文件系统、网络接口等。这使得开发者可以通过Flutter在嵌入式设备上实现更强大的功能,例如与传感器的交互、与云服务的连接等。 总而言之,Flutter-Embedded Linux是一个强大的开发工具,可以帮助开发者在嵌入式设备中创建高质量的应用程序。它结合了Flutter的跨平台特性和Embedded Linux的优势,为开发者提供了更灵活、高效的开发环境。无论是工业控制、智能家居还是其他嵌入式应用,Flutter-Embedded Linux都能提供良好的开发体验和用户体验。 ### 回答2: Flutter-embedded-linux是指在嵌入式Linux平台上使用Flutter框架进行应用开发的一种技术方案。嵌入式Linux是指在资源有限的嵌入式设备上运行Linux操作系统的系统;而Flutter是一种跨平台的移动应用开发框架,可以同时在AndroidiOS上运行。 使用Flutter-embedded-linux可以让开发者在嵌入式Linux平台上开发出跨平台的应用。这样一来,开发者不再需要针对不同的平台编写不同的代码,大大提高了开发效率。同时,Flutter的高性能和优秀的用户体验也被保留在嵌入式设备上。 在使用Flutter-embedded-linux时,开发者需要在嵌入式Linux平台上搭建Flutter的开发环境,包括安装Flutter SDK、配置相关的依赖库等。然后,可以使用Flutter提供的开发工具和API进行应用的开发和调试。 Flutter-embedded-linux可以应用于很多领域,例如智能家居、智能工业设备、嵌入式系统等。开发者可以利用Flutter-embedded-linux开发各种类型的应用,如物联网设备控制应用、工业监控系统、嵌入式音视频播放器等。 需要注意的是,由于嵌入式Linux平台的资源限制,开发者在使用Flutter-embedded-linux时需要特别关注应用的性能和资源消耗情况,避免出现过多的资源占用或性能瓶颈。 总之,Flutter-embedded-linux为开发者在嵌入式Linux平台上开发跨平台应用提供了一种方便、高效、高性能的技术方案,有望在嵌入式设备领域得到广泛应用。 ### 回答3: Flutter-Embedded-Linux是一种使用Flutter框架进行嵌入式开发的技术方案。Flutter是一种跨平台的开源UI框架,可以快速构建高性能、精美的应用程序。而Embedded-Linux则是嵌入式设备常用的操作系统。 通过将Flutter应用程序集成到Linux嵌入式系统中,可以在嵌入式设备上实现高效、流畅和美观的用户界面。Flutter的特点是能够在不同平台上保持一致的用户体验,因此在嵌入式系统上也能够实现类似于移动设备和桌面系统上的应用程序。 使用Flutter-Embedded-Linux进行嵌入式开发有一些优势。首先,Flutter具有快速构建UI界面的能力,可以节省开发时间。其次,Flutter对于动画和渲染效果的支持非常好,可以在嵌入式设备上实现更加流畅和绚丽的动画效果。此外,Flutter还支持热重载功能,可以实时更新应用程序而无需重新启动,极大地提高了开发效率。 然而,使用Flutter-Embedded-Linux也存在一些挑战。嵌入式设备通常资源有限,对占用内存和CPU的要求较高,需要对Flutter应用程序进行优化以提高性能。另外,由于Flutter是基于Dart语言开发的,需要事先熟悉Dart开发语言和Flutter框架的使用。 总之,Flutter-Embedded-Linux是一种用于嵌入式开发的技术方案,可以帮助开发者快速构建高品质的应用程序界面。它在嵌入式设备上的应用可以提供与移动设备和桌面系统相媲美的用户体验。但是,开发者需要注意对资源的合理利用和性能的优化,以确保应用程序在嵌入式设备上能够运行流畅。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值