NormalButton class

通用按钮,支持用户设置背景色、是否可用等属性 若BigMainButtonSmallMainButtonBigOutlineButton不能满足用户需要 可以直接使用该按钮

isEnable如果设置为false,那么按钮呈现灰色态,点击事件不响应

默认使用Text文本组件,如果用户想要显示其他组件。比如图片等,可以设置child属性

文本组件需要的样式属性,可以通过textStyle设置,也可以通过fontSize等单独设置

该组件的布局规则参考Container的布局规则 该组件的alignment的属性默认为null,即使父布局给的约束是无边界(最大宽度或者最大高度是double.infinity.) 组件的尺寸也会和child一样大。 那就是说:不给alignment属性设置值,即使把BrnNormalButton,放到columnListView中, 他也会尽可能的小。如果设置了constraints属性,那么就会按着constraints布局。

案例一

NormalButton(
   text: '主案特别长',
   onTap: () {
        Toast.show('点击了主按钮', context);
   },
)

按钮的大小就是text的大小+内边距的大小

案例二

NormalButton(
   constraints: BoxConstraints.expand(height: 60),
   text: '主案特别长',
   onTap: () {
        Toast.show('点击了主按钮', context);
   },
)

按钮的大小:宽度充满父布局、高度是60

如果给该组件的alignment赋值了,父布局的约束是有边界。 该组件的尺寸就是父布局的约束, 并且会按着alignment属性来摆放text或者child,比如居中摆放等.

案例一

NormalButton(
   alignment: Alignment.center,
   text: '主案特别长',
   onTap: () {
        Toast.show('点击了主按钮', context);
   },
)

按钮的大小:宽度充满父布局 文字居中摆放

Inheritance

Constructors

NormalButton({Key? key, required String text, Color backgroundColor = _BBackgroundColor, bool isEnable = true, VoidCallback? onTap, EdgeInsetsGeometry insertPadding = const EdgeInsets.symmetric(vertical: ButtonConstant.verticalPadding, horizontal: ButtonConstant.horizontalPadding), Decoration? decoration, Widget? child, TextStyle? textStyle, FontWeight fontWeight = _BFontWeight, double fontSize = _BFontSize, Color textColor = _BTextColor, Color? disableTextColor, Color disableBackgroundColor = _BDisableBackgroundColor, BoxConstraints constraints = const BoxConstraints.tightFor(), BorderRadiusGeometry borderRadius = const BorderRadius.all(Radius.circular(_BRadius)), Alignment? alignment})
const
NormalButton.outline({Key? key, Color? disableLineColor, Color? lineColor, double radius = 6, double borderWith = 1.0, required String text, bool isEnable = true, Color backgroundColor = _BBackgroundColor, Color disableBackgroundColor = _BDisableBackgroundColor, Alignment? alignment, Widget? child, VoidCallback? onTap, Color textColor = _BTextColor, FontWeight fontWeight = _BFontWeight, double fontSize = _BFontSize, Color? disableTextColor, EdgeInsetsGeometry insertPadding = const EdgeInsets.symmetric(vertical: ButtonConstant.verticalPadding, horizontal: ButtonConstant.horizontalPadding), TextStyle? textStyle, BoxConstraints constraints = const BoxConstraints.tightFor(), BorderRadiusGeometry borderRadius = const BorderRadius.all(Radius.circular(_BRadius))})

Properties

alignment Alignment?
按钮的内部对齐 默认为null
final
backgroundColor Color
按钮背景色 默认_BBackgroundColor
final
borderRadius BorderRadiusGeometry
按钮圆角大小
final
child Widget?
按钮的显示子节点 优先级高于text
final
constraints BoxConstraints
按钮的布局约束 默认是自适应大小
final
decoration Decoration?
按钮的修饰 默认实色背景
final
disableBackgroundColor Color
按钮不可用背景色 默认_BDisableBackgroundColor
final
disableTextColor Color?
按钮不可用的文字颜色
final
fontSize double
按钮的文字大小 默认_BFontSize
final
fontWeight FontWeight
按钮的文本Weight 默认是FontWeight.bold
final
hashCode int
The hash code for this object.
no setterinherited
insertPadding EdgeInsetsGeometry
按钮内边距 默认水平_BHorizontalPadding 垂直_BVerticalPadding
final
isEnable bool
按钮是否可用 默认是true
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onTap VoidCallback?
按钮点击的回调
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
text String
按钮显示的文案
final
textColor Color
按钮的文字颜色 默认白色_BTextColor
final
textStyle TextStyle?
按钮的文本显示样式 优先级高于textColor等属性
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}) 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