搜索插件、代码仓与 APP 分类

segment_display 封面
插件详情v0.6.0

segment_display

适用于 Flutter 的数码管显示小部件。支持多种类型的数码管显示和数码管自定义。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
635
喜欢数
28
Pub 分数
160

安装插件

flutter pub add segment_display

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于渲染数码管的 Flutter 小部件,非常适合数字时钟或仪表类 UI。支持多种数码管类型(7 段、14 段),并允许完全自定义数码管,包括颜色、大小和间距。该包轻量且可在所有主要平台上运行:Android、iOS、Web、macOS、Windows 和 Linux。非常适合创建复古风格界面或应用中的数字指示器。

适合场景

  • 数字时钟显示
  • 数字仪表和计数器
  • 复古用户界面设计
  • 仪表盘数字指示器
  • 自定义段落动画
  • 嵌入式设备接口仿真

主要特点

  • 支持多种段类型
  • 高度可定制的分段
  • 跨平台兼容性
  • 内置数字渲染
  • 与现有控件的轻松集成
  • 响应式布局处理

适合对象

  • 开发复古主题应用的开发者
  • 需要数值显示的UI设计师
  • 需要视觉数字指示器的应用程序
  • 具有嵌入式系统美学的项目
  • 面向多个平台的团队

使用建议

  • 仅限数值内容
  • 复杂布局需要手动样式设置
  • 未针对高频更新进行优化
  • 无内置动画预设
  • 最适合静态或低更新场景

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Segment display widget

Segment display

Pub CI Demo

Segment display widget for Flutter. Supports multiple types of segment displays and segment customization.

Contents

Features

  • 7-segment display
  • 14-segment display
  • 16-segment display
  • Customizable segment shapes (segment styles)
  • Supports . (decimal point) and : (colon) characters
  • Always-visible disabled decimal points (showDisabledDividers)
  • Custom character-to-bitmask entries (customCharacterMap)

See WEB DEMO.

Installation

  1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  segment_display: ^0.6.0
  1. Install it

You can install packages from the command line:

$ flutter pub get
  1. Import it

Now in your Dart code, you can use:

import 'package:segment_display/segment_display.dart';

Usage

Seven-segment display

CHARACTERS

Example:

SevenSegmentDisplay(
  value: "123",
  size: 12.0,
)
Seven-segment display
Fourteen-segment display

CHARACTERS

Example:

FourteenSegmentDisplay(
  value: "123",
  size: 12.0,
)
Fourteen-segment display
Sixteen-segment display

CHARACTERS

Example:

SixteenSegmentDisplay(
  value: "123",
  size: 12.0,
)
Sixteen-segment display

Styles and customization

You can customize segment display with:

  • characterSpacing - space between individual characters
  • backgroundColor - display background color
  • segmentStyle - style for segments (shape, color,...), see segment style
  • showDisabledDividers - always show a decimal point after each digit (dim unless . is present in value)
  • customCharacterMap - add or override character-to-bitmask entries

Example:

SevenSegmentDisplay(
  value: "123",
  size: 12.0,
  characterSpacing: 10.0,
  backgroundColor: Colors.transparent,
  segmentStyle: HexSegmentStyle(
    enabledColor: Colors.red,
    disabledColor: Colors.red.withValues(alpha: 0.15),
  ),
)
Disabled dividers

Set showDisabledDividers: true to always show a decimal point after each digit — dim when not in value, lit when . follows the character:

SevenSegmentDisplay(
  value: "12.3",
  size: 12.0,
  showDisabledDividers: true,  // dots visible after all digits
)
Custom character map

Use customCharacterMap to add characters not in the built-in map, or override existing ones, by supplying a char → bitmask map:

// 7-segment: bit 0 = G (middle), bit 6 = A (top), etc.
SevenSegmentDisplay(
  value: "~",
  size: 12.0,
  customCharacterMap: {'~': 0x63},
)
Segment style

To change segment color, size or shape, use segment style.

There are following segment styles:

  • DefaultSegmentStyle
    DefaultSegmentStyle
  • HexSegmentStyle
    HexSegmentStyle
  • RectSegmentStyle
    RectSegmentStyle

and you can also create your own style (shape) - see custom segment styles

Example:

SevenSegmentDisplay(
  value: "13:37",
  size: 12.0,
  segmentStyle: HexSegmentStyle(
    enabledColor: const Color(0xFF00FF00),
    disabledColor: const Color(0xFF00FF00).withValues(alpha: 0.15),
    segmentBaseSize: const Size(1.0, 2.0),
  ),
)
Style example
  • enabledColor - color of enabled segments
  • disabledColor - color of disabled segments
  • segmentBaseSize - size ratio for segments; Size(1.0, 2.0) basically means that ratio will be 1:2 (width:length)

NOTE: SegmentStyle.segmentBaseSize * SegmentDisplay.size = segmentSize

Custom segment styles

To create your own segment style (shape), extend SegmentStyle and implement createHorizontalPath, createVerticalPath, createDiagonalBackwardPath and createDiagonalForwardPath.

class CustomSegmentStyle extends SegmentStyle {

  const CustomSegmentStyle({
    super.segmentBaseSize,
    super.enabledColor,
    super.disabledColor,
  });

  @override
  Path createHorizontalPath(SegmentPosition position, Size segmentSize) {
    // ...
  }
  
  @override
  Path createVerticalPath(SegmentPosition position, Size segmentSize) {
    // ...
  }
  
  @override
  Path createDiagonalBackwardPath(SegmentPosition position, Size segmentSize) {
    // ...
  }
  
  @override
  Path createDiagonalForwardPath(SegmentPosition position, Size segmentSize) {
    // ...
  }
}

You can also customize the shape for individual segments by overriding createPath** methods. For 7-segment display, there are createPath7* methods, for 14-segment display createPath14* and so on.

Example: if you want to change the shape of the top segment in 7-segment display, you just have to override createPath7A method.

class CustomSegmentStyle extends SegmentStyle {

  // ..
  
  @override
  Path createPath7A(Size segmentSize, double padding) {
    // ...
  }
  
  // ...
  
}

NOTE: createPath** methods use createHorizontalPath/createVerticalPath/createDiagonalBackwardPath/createDiagonalForwardPath by default so you don't have to override all createPath7* methods.

Features and bugs

Please file feature requests and bugs at the issue tracker.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。