ZoomButtons class

放大缩小按钮组(公开 API)。

这是一个简单的 StatelessWidget,提供标准的放大缩小按钮组 UI。 外部可以在任意位置使用,如自定义桌面 Chrome。

功能特性

  • 显示两个按钮:放大按钮(+)和缩小按钮(-)
  • 可选显示当前缩放级别(如 "100%")
  • 使用半透明黑色背景 + 圆角容器
  • 垂直排列,按钮之间有间距

使用示例

在自定义桌面 Chrome 中使用

Positioned(
  left: 20,
  bottom: 100,
  child: ZoomButtons(
    onZoomIn: () => _zoomIn(),
    onZoomOut: () => _zoomOut(),
    currentZoomLevel: _currentZoom,
  ),
)

在自定义页面中使用

class MyCustomDesktopPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        // 图片内容
        MyImageWidget(),
        // 放大缩小按钮
        Positioned(
          left: 20,
          bottom: 100,
          child: ZoomButtons(
            onZoomIn: () {
              // 放大图片
            },
            onZoomOut: () {
              // 缩小图片
            },
            currentZoomLevel: 1.5, // 150%
          ),
        ),
      ],
    );
  }
}

设计说明

此类遵循以下设计原则:

  1. 完全独立:不依赖特定的父组件,可以在任意位置使用
  2. 简单直观:提供标准的放大缩小按钮 UI,无复杂逻辑
  3. 可配置:支持自定义缩放级别显示
  4. 样式统一:使用一致的样式,保持视觉统一性

样式说明

  • 按钮尺寸:40x40 像素
  • 按钮背景:半透明黑色(opacity: 0.5)
  • 按钮圆角:8 像素
  • 图标尺寸:24 像素
  • 图标颜色:白色
  • 按钮间距:8 像素
  • 缩放级别文字:12 像素,白色
Inheritance

Constructors

ZoomButtons({Key? key, required VoidCallback onZoomIn, required VoidCallback onZoomOut, double? currentZoomLevel})
创建放大缩小按钮组。
const

Properties

currentZoomLevel double?
当前缩放级别(用于显示状态)。
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onZoomIn VoidCallback
放大回调。
final
onZoomOut VoidCallback
缩小回调。
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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