パッケージ、リポジトリ、アプリカテゴリを検索

loader_overlay のカバー
パッケージ詳細v5.0.0

loader_overlay

スクリーン管理を簡素化するための簡単なパッケージです。任意の非同期タスクを読み込む際、このパッケージは非同期タスクが完了するまで、ユーザーが画面と相互作用することを防ぎます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
7万
いいね数
567
Pub ポイント
160

パッケージをインストール

flutter pub add loader_overlay

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

LoaderOverlay は、非同期操作中の画面管理を簡素化するための Flutter パッケージです。API 呼び出しやデータ処理などのタスクが実行中は、ユーザーの操作を防ぐためローディングオーバーレイを表示します。このオーバーレイは簡単にオン/オフ切り替えでき、タスク完了まで入力をブロックすることでスムーズなユーザー体験を確保します。Android、iOS、Web、macOS、Windows、Linux を含むすべての主要プラットフォームをサポートしています。複雑なカスタム実装なしで、読み込み状態での UX を向上させるのに最適です。

用途

  • 非同期操作中にUIをブロックする
  • 読み込み中に誤タップを防ぐ
  • フォームにローディングインジケーターを表示する
  • 長時間実行されるバックグラウンドタスクの管理
  • アプリの応答性の向上
  • ロード状態の処理を簡素化する

主な機能

  • シンプルなオーバーレイの有効化
  • 自動UIブロッキング
  • クロスプラットフォーム対応
  • 非同期タスクとの簡単な統合
  • カスタマイズ可能な読み込み表示
  • 非侵襲的設計

適している対象

  • 迅速な読み込みオーバーレイを求める開発者
  • 頻繁な非同期操作を持つアプリ
  • 明確な読み込みフィードバックを必要とするUI
  • UXの一貫性を重視するチーム
  • 最小限のボイラープレートが必要なプロジェクト

注意事項

  • 手動でオーバーレイを非表示にする必要がある場合があります
  • 制限されたカスタマイズオプション
  • 頻繁な切り替えによるパフォーマンスへの影響
  • 複雑な読み込みアニメーションには適していません
  • 適切な非同期タスクの調整に依存する

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Buy Me A Coffee

Introduction

Have you ever found yourself in the situation of doing some async processing your screen and wanting to prevent the user from interacting with the screen while the application is loading? If so, this package was made just for you.

Basic Usage

The most simple usage is just wrap the widget that you want an overlay on LoaderOverlay. Default loader will be shown.

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

This simple step will already configure the loader overlay for use.

After that configuration you can just call:

context.loaderOverlay.show();

This will show the overlay with the default loading indicator. The default loading configured is to just show a centered CircularProgressIndicator

To hide the overlay (after the async processing, for example), just call:

context.loaderOverlay.hide();

You can check if overlay is visible:


final isVisible = context.loaderOverlay.visible;

*Note: You will always need the context to show or hide the loader overlay

Simple Overlay

Basic Usage on Navigation

To use this package with named routes you can just wrap your MaterialApp with GlobalLoaderOverlay. This widget has all the features of LoaderOverlay but it is provided for all the routes of the app.

@override
Widget build(BuildContext context) {
  return GlobalLoaderOverlay(
    child: MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.teal, fontFamily: 'Baloo'),
      initialRoute: '/',
      routes: {
        '/': (context) => Page1(),
        '/page2': (context) => Page2(),
      },
    ),
  );
}

Customization

Your overlay loader widget can be any widget you want. For example you can import the package flutter_spinkit and customise your widget like this. To do that just pass your widget to overlayWidget and set useDefaultLoading to false.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoaderOverlay(
        useDefaultLoading: false,
        overlayWidgetBuilder: (_) { //ignored progress for the moment
          return Center(
            child: SpinKitCubeGrid(
              color: Colors.red,
              size: 50.0,
            ),
          );
        },
        child: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

Simple Custom Overlay

Another customisation you can do is configure the color and opacity of the overlay. The default opacity is grey with 0.4 opacity, but you can change it with the overlayColor: Colors.yellow.withValues(alpha: 0.8).

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoaderOverlay(
        useDefaultLoading: false,
        overlayWidgetBuilder: (_) { //ignored progress for the moment
          return Center(
            child: SpinKitCubeGrid(
              color: Colors.red,
              size: 50.0,
            ),
          );
        },
        overlayColor: Colors.yellow.withValues(alpha: 0.8),
        child: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

This is a much opaque yellow overlay:

Simple More Custom Overlay

You may want to have several different loaders in your app. In this case just pass any widget to the loaderOverlay.show:

class ReconnectingOverlay extends StatelessWidget {
  String? progress;

  ReconnectingOverlay(this.progress);

  @override
  Widget build(BuildContext context) =>
      Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            CircularProgressIndicator(),
            SizedBox(height: 12),
            Text(
              'Reconnecting...',
            ),
            SizedBox(height: 12),
            Text(
              progress ?? '',
            ),
          ],
        ),
      );
}
context.loaderOverlay.show(
  widgetBuilder: (progress) {
    return ReconnectingOverlay(
      progress != null ? progress as String : null,
    );
  },
);

If you pass widget to context.loaderOverlay.show, then defaultLoader and widgetOverlay will be ignored;

Simple More Custom Overlay

Progress

If you want to show some progress while the loader overlay is visible, you can do it with the context.loaderOverlay.show(progress: 'Doing progress #0',) for an initial progress, and with context.loaderOverlay.progress('Doing progress #1'); every time the progress need to change. Both this methods pass the progress to the current widgetBuilder on every call.

Setting up the builder to use the progress

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoaderOverlay(
        useDefaultLoading: false,
        overlayWidgetBuilder: (dynamic? progress) {
          return Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SpinKitCubeGrid(
                color: Colors.red,
                size: 50.0,
              ),
              SizedBox(
                height: 50,
              ),
              if (progress != null) Text(progress)
            ],
          );
        },
        child: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

Once the builder is configured, you can call it and update the progress by calling:

context.loaderOverlay.show(
  progress: 'Doing progress #0',
);

await Future.delayed(Duration(seconds: 1));
context.loaderOverlay.progress('Doing progress #1');
await Future.delayed(Duration(seconds: 1));
context.loaderOverlay.progress('Doing progress #2');
await Future.delayed(Duration(seconds: 1));
context.loaderOverlay.progress('Doing progress #3');
await Future.delayed(Duration(seconds: 1));

if (_isLoaderVisible) {
  context.loaderOverlay.hide();
}

This will have as result:

Progress Overlay

You can also remove by complete the overlayColor (set to transparent), set the useDefaultLoading to false, and use a fully personalized overlayWidgetBuilder to make your own 100% customizable overlay.

    LoaderOverlay(
      overlayColor: Colors.transparent,
      useDefaultLoading: false,
      overlayWidgetBuilder: (progress) {
        return BackdropFilter(
          filter: ImageFilter.blur(
            sigmaX: 4.5,
            sigmaY: 4.5,
          ),
          child: Center(
            child: Container(
              width: 100,
              height: 100,
              color: Colors.purple,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  CircularProgressIndicator(),
                  Text(
                    'Doing stuff... bip...bup',
                    textAlign: TextAlign.center,
                  )
                ],
              ),
            ),
          ),
        );
      },
    )

Complete Custom Overlay

Breaking changes

1 - Since version 3.0.0 the overlay widget's got changed by a builder to manage the progress.

Before:

      LoaderOverlay(
        //...
        useDefaultLoading: false,
        overlayWidget: Center(
          child: SpinKitCubeGrid(
            color: Colors.red,
            size: 50.0,
          ),
        ),
        //...      
      )

After:

      LoaderOverlay(
        //...
        useDefaultLoading: false,
        overlayWidgetBuilder: (_) {
          return Center(
            child: SpinKitCubeGrid(
              color: Colors.red,
              size: 50.0,
            ),
          );
        },
        //...
      )

2 - overlayOpacity was removed. Now use the opacity direct in the overlayColor

Before:

      LoaderOverlay(
        //...
        overlayColor: Colors.black,
        overlayOpacity: 0.8,
        //...
      )

After:

      LoaderOverlay(
        //...
        overlayColor: Colors.black.withValues(alpha: 0.8),
        //...
      )

Animation

By default, the overlay does not animate in or out. You can enable animations by passing the appropriate parameters to LoaderOverlay. Internally, an AnimatedSwitcher is used to manage animations, so the parameters are passed directly to the AnimatedSwitcher. By specifying a duration and reverseDuration, the overlay will animate in and out using a fade (the default transition used by AnimatedSwitcher). You can also pass curves, a transition builder and a layout builder for further customisation.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoaderOverlay(
        duration: const Duration(milliseconds: 250),
        reverseDuration: const Duration(milliseconds: 250),
        // switchInCurve,
        // switchOutCurve,
        // transitionBuilder,
        // layoutBuilder,
        child: MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

Todo

  • [ ] Tests

Suggestions & Bugs

For any suggestions or bug report please head to issue tracker.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト