RatingBar class
评分组件 - 支持整星、半星、精确评分等多种模式
Rating Bar Component - Supports full star, half star, and precise rating modes
功能特性 / Features
- 支持自定义星星数量和大小 / Custom star count and size
- 支持步长控制(整星/半星/任意精度) / Step control (full/half/any precision)
- 支持只读模式 / Read-only mode support
- 完全自定义星星样式 / Fully customizable star appearance
- 可配置是否允许0分 / Configurable zero rating
- 支持触摸和滑动交互 / Touch and swipe interaction
- 支持评分值格式化显示 / Rating value formatting support
使用场景 / Use Cases
- 商品评价 / Product reviews
- 用户满意度调查 / User satisfaction surveys
- 内容评分系统 / Content rating systems
- 技能等级展示 / Skill level display
基础示例 / Basic Example
// 简单评分条
RatingBar(
count: 5,
value: 3.5,
size: 30,
normalImage: Icon(Icons.star_border, color: Colors.grey),
selectImage: Icon(Icons.star, color: Colors.amber),
selectAble: true,
onRatingUpdate: (rating) {
print('当前评分: $rating');
},
)
高级示例 / Advanced Example
// 半星评分(步长0.5)
RatingBar(
count: 5,
value: 3.5,
step: 0.5,
maxRating: 10.0,
allowZero: false,
normalImage: Icon(Icons.star_border),
selectImage: Icon(Icons.star, color: Colors.orange),
selectAble: true,
onRatingUpdate: (rating) => print(rating),
)
// 只读展示模式
RatingBar(
count: 5,
value: 4.2,
readOnly: true,
normalImage: Icon(Icons.star_border),
selectImage: Icon(Icons.star, color: Colors.amber),
)
注意事项 / Notes
- value 必须在 0 到 maxRating 之间 / Must be between 0 and maxRating
- step 必须大于 0 / Must be greater than 0
- count 必须大于 0 / Must be greater than 0
- 当 readOnly 为 true 时,selectAble 会被忽略 / selectAble is ignored when readOnly is true
- 建议使用 Icon 或 Image.asset 作为星星图片 / Recommend using Icon or Image.asset for star images
See also:
- Slider - Flutter 原生滑块组件
- LinearProgressBar - 本库的进度条组件
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- RatingBar
- Available extensions
Constructors
-
RatingBar({double maxRating = 10.0, int count = 5, double value = 0, double size = 20, required Widget normalImage, required Widget selectImage, double padding = 3, bool selectAble = false, double step = 1.0, bool allowZero = true, bool readOnly = false, ValueChanged<
double> ? onRatingUpdate, String valueFormatter(double value)?, Key? key}) -
const
Properties
- allowZero → bool
-
是否允许0分 / Whether to allow zero rating
final
- count → int
-
星星数量 / Number of stars
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxRating → double
-
最大评分值 / Maximum rating value
final
- normalImage → Widget
-
未选中星星样式 / Unselected star widget
final
-
onRatingUpdate
→ ValueChanged<
double> ? -
评分变化回调 / Rating change callback
final
- padding → double
-
星星间距 / Spacing between stars
final
- readOnly → bool
-
是否只读模式 / Whether read-only mode
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectAble → bool
-
是否可交互 / Whether interactive
final
- selectImage → Widget
-
选中星星样式 / Selected star widget
final
- size → double
-
星星大小 / Star size
final
- step → double
-
评分步长 / Rating step
final
- value → double
-
当前评分值 / Current rating value
final
- valueFormatter → String Function(double value)?
-
评分值格式化器 / Rating value formatter
final
Methods
-
blurred(
{double blur = 5, Color blurColor = Colors.white, BorderRadius? borderRadius, double colorOpacity = 0.5, Widget? overlay, AlignmentGeometry alignment = Alignment.center}) → Blur -
Available on Widget, provided by the BlurExtension extension
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _RatingBarState -
Creates the mutable state for this widget at a given location in the tree.
override
-
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
-
frosted(
{double blur = 5, Color frostColor = Colors.white, AlignmentGeometry alignment = Alignment.center, double? height, double? width, double frostOpacity = 0.0, BorderRadius? borderRadius, EdgeInsetsGeometry padding = EdgeInsets.zero}) → Blur -
Available on Widget, provided by the FrostExtension extension
-
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