GitHub 儲存庫kekland/future_button

future_button

可自訂的 Material 和 Cupertino 按鈕,帶有進度指示器等

future_button 專案封面
星標
36
分支
7
最近推送(UTC)
2022年12月19日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

future_button

Coverage Status Build status Pub version

Customizable Material and Cupertino buttons with progress indicators and more.

Useful if you want to run some background tasks when user presses on the button, and then show the result of the task.

Demonstration

How to use it

Usage is extremely simple - right now 5 types of buttons are supported:

  • CupertinoButton (normal + filled)
  • FlatButton (normal + icon)
  • IconButton
  • OutlineButton (normal + icon)
  • RaisedButton (normal + icon)

To convert a button to a FutureButton, just add a Future prefix and make sure that your onPressed callback is of type Future<void> Function(), instead of usual void Function().

Everything that the package does can be customized. Below is the list of all parameters:

/// The widget that's used as the progress indicator.
/// You can substitute it with your own progress indicator if necessary.
/// See [defaultMaterialProgressIndicatorBuilder] and[defaultCupertinoProgressIndicatorBuilder] for more info.
final WidgetBuilder progressIndicatorBuilder;

/// The location of progress indicator.
/// See [ProgressIndicatorLocation] for more info.
final ProgressIndicatorLocation progressIndicatorLocation;

/// Whether to show the result of the Future.
/// Will show [successIndicatorBuilder] if Future completes without errors.
/// Otherwise, will show [failureIndicatorBuilder].
final bool showResult;

/// Whether to animate the transitions using [AnimatedSwitcher].
/// Defaults to [true].
final bool animateTransitions;

/// Indicator to show when the Future is completed successfully.
/// Defaults to [defaultSuccessResultIndicatorBuilder].
final WidgetBuilder successIndicatorBuilder;

/// Indicator to show when the Future fails.
/// Defaults to [defaultFailureResultIndicatorBuilder].
final WidgetBuilder failureIndicatorBuilder;

/// For how long should the result be shown for.
/// Default to `Duration(seconds: 2)`.
final Duration resultIndicatorDuration;

/// Curve that's used to animate the button size.
/// Defaults to [Curves.easeInOut].
final Curve animationCurve;

/// Duration that's used to animate the button size.
/// Defaults to `Duration(milliseconds: 150)`.
final Duration animationDuration;

Example

FutureRaisedButton.icon(
  icon: Icon(Icons.star),
  label: Text('Star'),
  onPressed: () async {
    // Do some background task
    await Future.delayed(Duration(seconds: 5));
  },
);

See example project for more details.

Getting Started

Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  future_button: ^0.1.1
Install it

You can install packages from the command line:

$ flutter pub get
Import it

Now in your Dart code, you can use:

import 'package:future_button/future_button.dart';

Contact me

E-mail: kk.erzhan@gmail.com

Erzhan GitHub avatar
GitHub 作者

Erzhan ↗

i do some flutter things

Almaty, Kazakhstan
語言DartSwiftKotlinObjective-C

分類

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

  • flutter{"sdk":"flutter"}
  • pedantic開發依賴^1.9.0
  • flutter_test開發依賴{"sdk":"flutter"}

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗