GitHub 代码仓Bharathh-Raj/multi_state_button

multi_state_button

一个 Flutter 包,为按钮提供多种状态,并具有无限的可定制性。

multi_state_button 项目封面
星标
7
复刻
0
最近推送(UTC)
2021年8月30日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

multi_state_button

Pub support support

A package which provides multiple states for a button with endless customizability.

Sample

Getting Started

Add dependency
dependencies:
  multi_state_button: ^1.1.3
Super simple to use
import 'package:multi_state_button/multi_state_button.dart';
class MyApp extends StatelessWidget {
    static const String _submit = "Submit";
    static const String _loading = "Loading";
    static const String _success = "Success";
    final MultiStateButtonController multiStateButtonController =  MultiStateButtonController(initialStateName: _submit);
    @override
    Widget build(BuildContext context) {
        return MultiStateButton(
            multiStateButtonController: multiStateButtonController,
            buttonStates:[
                ButtonState(
                  stateName: _submit,
                  child: Text(
                    _submit,
                  ),
                  textStyle: TextStyle(color: Colors.white, fontSize: 20),
                  size: Size(160, 48),
                  color: Colors.blue,
                  onPressed:() => multiStateButtonController.setButtonState = _loading,
                  ),
                  ButtonState(
                  stateName: _loading,
                  alignment: Alignment.center,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: CircularProgressIndicator(
                        strokeWidth: 3,
                        color: Colors.white,
                    ),
                  ),
                  decoration: BoxDecoration(
                    color: Colors.teal,
                    borderRadius: BorderRadius.all(Radius.circular(48)),
                  ),
                  size: Size(48, 48),
                  onPressed: () => multiStateButtonController.setButtonState = _success,
                  ),
                  ButtonState(
                  stateName: _success,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        _success,
                      ),
                      const SizedBox(
                        width: 16,
                      ),
                      Icon(
                        Icons.check,
                        color: Colors.white,
                      )
                    ],
                  ),
                  textStyle: TextStyle(color: Colors.white, fontSize: 22),
                  color: Colors.green,
                  size: Size(200, 48),
                  onPressed: ()=> multiStateButtonController.setButtonState = _submit,
                  ),
            ],
        );
    }
}
Properties to configure
MultiStateButton properties
class MultiStateButton extends StatefulWidget {
  /// List of button states.
  /// Note: Default initial State is the first button state.
  /// Can override this behaviour with [initialStateName] constructor parameter of [MultiStateButtonController].
  final List<ButtonState> buttonStates;

  /// Used to change the current state of the button
  final MultiStateButtonController multiStateButtonController;

  /// Transition duration between button state transition.
  /// Defaults to 500 milliseconds
  final Duration transitionDuration;

  /// Transition curve between button state transition.
  /// Defaults to [Curves.easeIn]
  final Curve transitionCurve;
}
SingleStateButton properties
class SingleStateButton extends StatelessWidget {
  /// State for single state button
  final ButtonState buttonState;
}
ButtonState Properties
class ButtonState {
  /// This is the name used to identify the state of the button.
  /// This name is used to change the state using [MultiStateButtonController]
  final String stateName;
  final Widget child;
  final VoidCallback? onPressed;

  /// Size of the button
  final Size? size;

  /// Color of the button.
  /// This should be null if boxDecoration is not null.
  final Color color;

  /// Decorate the button with color, border radius, box shadow, gradient etc...
  final BoxDecoration? decoration;

  /// Used to align the child.
  /// Defaults to [Alignment.center]
  final AlignmentGeometry alignment;

  /// If descendant of the button is a Text child, this textStle is used to enable transition animtation between two states.
  final TextStyle? textStyle;

  /// The transformation matrix to apply before painting the button.
  final Matrix4? transform;

  /// The clip behavior when [decoration] is not null.
  final Clip clipBehavior;

  /// The decoration to paint in front of the child.
  final Decoration? foregroundDecoration;

  /// SubRoutine to run on transition animation ends.
  final VoidCallback? onAnimationEnd;

  /// The alignment of the child, relative to the size of the button, if [transform] is specified.
  /// When [transform] is null, the value of this property is ignored.
  final AlignmentGeometry? transformAlignment;
}

Example Project

support

Features and bugs

Please file feature requests and bugs at the issue tracker.

Bharath GitHub avatar
GitHub 作者

Bharath ↗

语言DartSwiftKotlinObjective-C

分类

此仓库发布的插件

使用的依赖

依赖清单 2 项

  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

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

GitHub Docs — About repositories ↗