NZButton class

NZButton 是 NezhaUI 提供的高性能、高可定制化的按钮组件。

提供了命名构造函数(如 NZButton.primary)以简化代码编写, 并支持 label 简写、加载状态 isLoading 和通栏布局 block

Inheritance

Constructors

NZButton({Key? key, required VoidCallback? onPressed, Widget? child, String? label, NZButtonStyle style = NZButtonStyle.primary, double? width, double height = 48.0, EdgeInsetsGeometry? padding, double borderRadius = 12.0, Widget? icon, double iconGap = 8.0, bool isLoading = false, bool block = false, double? progress, Color? progressColor, Color? color, Color? foregroundColor})
const
NZButton.outline({Key? key, required VoidCallback? onPressed, String? label, Widget? child, double? width, double height = 48.0, double borderRadius = 12.0, Widget? icon, double iconGap = 8.0, bool isLoading = false, bool block = false, double? progress, Color? progressColor, Color? color, Color? foregroundColor})
快速创建描边按钮 (透明背景,主色边框)
factory
NZButton.primary({Key? key, required VoidCallback? onPressed, String? label, Widget? child, double? width, double height = 48.0, double borderRadius = 12.0, Widget? icon, double iconGap = 8.0, bool isLoading = false, bool block = false, double? progress, Color? progressColor, Color? color, Color? foregroundColor})
快速创建主要按钮 (背景色为主色,文字为白色)
factory
NZButton.secondary({Key? key, required VoidCallback? onPressed, String? label, Widget? child, double? width, double height = 48.0, double borderRadius = 12.0, Widget? icon, double iconGap = 8.0, bool isLoading = false, bool block = false, double? progress, Color? progressColor, Color? color, Color? foregroundColor})
快速创建次要按钮 (微信风格:灰色背景,绿色文字)
factory
NZButton.text({Key? key, required VoidCallback? onPressed, String? label, Widget? child, double? width, double height = 48.0, double borderRadius = 12.0, Widget? icon, double iconGap = 8.0, bool isLoading = false, bool block = false, double? progress, Color? progressColor, Color? color, Color? foregroundColor})
快速创建文字按钮 (无背景,无边框)
factory

Properties

block bool
是否通栏(全宽)显示
final
borderRadius double
圆角半径,默认为 12.0
final
child Widget?
按钮内容组件,优先级高于 label
final
color Color?
自定义背景颜色
final
foregroundColor Color?
自定义前景(文字和图标)颜色
final
hashCode int
The hash code for this object.
no setterinherited
height double
按钮高度,默认为 48.0
final
icon Widget?
按钮图标
final
iconGap double
图标与文字之间的间距
final
isLoading bool
是否处于加载状态
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
label String?
按钮文字简写
final
onPressed VoidCallback?
点击回调
final
padding EdgeInsetsGeometry?
内部边距
final
progress double?
进度值 (0.0 到 1.0),若提供则显示进度条背景
final
progressColor Color?
进度条颜色,若不提供则使用 foregroundColor 的淡化版本
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style NZButtonStyle
按钮样式
final
width double?
按钮宽度,设置 block 为 true 时失效
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited