搜索插件、代码仓与 APP 分类

screen_loader 封面
插件详情v4.0.1

screen_loader

易于使用的 mixin ScreenLoader,可处理屏幕上的加载,而无需使用状态或导航堆栈。您也可以自定义加载。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1470
喜欢数
50
Pub 分数
150

安装插件

flutter pub add screen_loader

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

ScreenLoader 是一个 Flutter/Dart 包,提供了一个简单的 mixin 来管理屏幕上的加载状态,而无需显式的状态管理或导航栈操作。它使开发者能够以最少的样板代码在各个屏幕之间显示和控制加载指示器。该包支持对加载 UI 的自定义,使其能够适应各种设计需求。非常适合需要在多个小部件中保持一致且可重用的加载体验的应用程序。

适合场景

  • 在异步操作期间显示加载覆盖层
  • 简化表单中的加载状态管理
  • 向 API 调用添加加载指示器
  • 创建可重用的加载组件
  • 通过流畅的加载过渡提升用户体验
  • 减少屏幕级加载逻辑中的样板代码

主要特点

  • 基于 Mixin 的加载实现
  • 可自定义的加载 UI
  • 无需状态管理
  • 跨所有平台运行
  • 所需设置最少
  • 支持异步操作处理

适合对象

  • 寻求轻量级加载解决方案的开发者
  • 使用最小状态管理的团队
  • 频繁异步数据获取的应用
  • 需要一致加载器的UI密集型应用程序
  • Flutter 初学者探索加载模式
  • 跨平台应用程序,针对多种设备

使用建议

  • 仅限基本加载功能
  • 需要与异步工作流进行手动集成
  • 不适合复杂的加载状态
  • 可能需要额外的样式来支持自定义设计
  • 依赖于正确的控件树结构
  • 默认情况下不处理错误状态

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

screen_loader

Why ScreenLoader?

  1. With the help of stream_mixin, it shows and hides the loader without updating the state of the widget which increases the performance
  2. It does not push any sort of widget to navigation stack, this helps in not messing up the navigation stack and context
  3. Easy to use, just use your screen with ScreenLoader mixin and wrap the widget with loadableWidget
  4. The loader is customizable. You can use any widget as a loader
  5. You can configure same loader for all the screens at once
  6. You can also configure different loader for different screens

Basic usage

  1. Use your screen with the ScreenLoader mixin
  2. Wrap the widget with loadableWidget
  3. Use performFuture function to show loader while your future is being performed

Configure different loader for individual screen

Simply overide loader() method

loader() {
    // here any widget would do
    return AlertDialog(
        title: Text('Wait.. Loading data..'),
    );
}

Configure the loader for all screens at once

void main() {
  configScreenLoader(
    loader: AlertDialog(
      title: Text('Gobal Loader..'),
    ),
    bgBlur: 20.0,
  );
  runApp(MyApp());
}

Priority of loaders (highest first)

  • Local loader: the one you override in your widget
  • Global loader: the one you specify in configScreenLoader. Note: if you don't override local(), this loader will be used
  • Default loader: if you don't specify global loader or override local loader, this loader will be used

Migration guide to 4.0.0

  1. ScreenLoaderApp widget is removed. Now no need to wrap your App around any widget just to set the global configurations. Instead call configScreenLoader() before runApp()
-void main() => runApp(MyApp());
+void main() {
+  configScreenLoader(
+    loader: AlertDialog(
+      title: Text('Gobal Loader..'),
+    ),
+    bgBlur: 20.0,
+  );
+  runApp(MyApp());
+}
 
 class MyApp extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
-    return ScreenLoaderApp(
-      app: MaterialApp(
-        debugShowCheckedModeBanner: false,
-        title: 'Screen Loader',
-        theme: ThemeData(
-          primarySwatch: Colors.blue,
-        ),
-        home: Screen(),
-      ),
-      globalLoader: AlertDialog(
-        title: Text('Gobal Loader..'),
+    return MaterialApp(
+      debugShowCheckedModeBanner: false,
+      title: 'Screen Loader',
+      theme: ThemeData(
+        primarySwatch: Colors.blue,
       ),
-      globalLoadingBgBlur: 20.0,
+      home: Screen(),
     );
   }
 }
  1. Instead of replacing the build function with screen use the build function itself and wrap the widget you want to show loader on with the loadableWidget.

-class _ScreenState extends State<Screen> with ScreenLoader<Screen> {
+class _ScreenState extends State<Screen> with ScreenLoader {
   @override
   loader() {
     return AlertDialog(
@@ -49,17 +51,19 @@ class _ScreenState extends State<Screen> with ScreenLoader<Screen> {
   }
 
   @override
-  Widget screen(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(
-        title: Text('ScreenLoader Example'),
-      ),
-      body: _buildBody(),
-      floatingActionButton: FloatingActionButton(
-        onPressed: () async {
-          await this.performFuture(NetworkService.getData);
-        },
-        child: Icon(Icons.refresh),
+  Widget build(BuildContext context) {
+    return loadableWidget(
+      child: Scaffold(
+        appBar: AppBar(
+          title: Text('ScreenLoader Example'),
+        ),
+        body: _buildBody(),
+        floatingActionButton: FloatingActionButton(
+          onPressed: () async {
+            await this.performFuture(NetworkService.getData);
+          },
+          child: Icon(Icons.refresh),
+        ),
       ),
     );
   }

PS
  • PRs are welcome
  • Please raise issues on https://github.com/arnold-parge/screen_loader.
  • Open for suggestions ❤️

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。