segment display widget
segment display widget for flutter. supports multiple types of segment displays and segment customization.
features
- 7-segment display
- 14-segment display
- 16-segment display
- customizable segment shapes (segment styles)
- supports
.
(decimal point) and:
(colon) characters
see web demo.
note: flutter web support is currently in beta, so you may experience some issues.
installation
- depend on it
add this to your package’s pubspec.yaml file:
dependencies:
segment_display: ^0.4.1
- install it
you can install packages from the command line:
$ flutter packages get
alternatively, your editor might support flutter packages get. check the docs for your editor to learn more.
- import it
now in your dart code, you can use:
import 'package:segment_display/segment_display.dart';
usage
seven-segment display
example:
sevensegmentdisplay(
value: "123",
size: 12.0,
)
fourteen-segment display
example:
fourteensegmentdisplay(
value: "123",
size: 12.0,
)
sixteen-segment display
example:
sixteensegmentdisplay(
value: "123",
size: 12.0,
)
styles and customization
you can customize segment display with:
characterspacing
– space between individual charactersbackgroundcolor
– display background colorsegmentstyle
– style for segments (shape, color,…), see segment style
example:
sevensegmentdisplay(
text: "123",
textsize: 12.0,
characterspacing: 10.0,
backgroundcolor: colors.transparent,
segmentstyle: hexsegmentstyle(
enabledcolor: colors.red,
disabledcolor: colors.red.withopacity(0.15),
),
)
segment display widget style
to change segment color, size or shape, use segment style.
there are following segment styles:
- defaultsegmentstyle
- hexsegmentstyle
- rectsegmentstyle
and you can also create or 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).withopacity(0.15),
segmentbasesize: const size(1.0, 2.0),
),
)
enabledcolor
– color of enabled segmentsdisabledcolor
– color of disabled segmentssegmentbasesize
– size ratio for segments;size(1.0, 2.0)
basically means that ratio will be 1:2 (width:length)
note:
segmentstyle.segmentbasesize
*segmentdisplay.textsize
= segmentsize
custom segment styles
to create your own segment style (shape), extends segmentstyle
class and implement methods
createhorizontalpath
, createverticalpath
, creatediagonalbackwardpath
and creatediagonalforwardpath
.
class customsegmentstyle extends segmentstyle {
const customsegmentstyle({
size segmentbasesize,
color enabledcolor,
color disabledcolor,
}) : super(
segmentbasesize: segmentbasesize,
enabledcolor: enabledcolor,
disabledcolor: 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 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 usecreatehorizontalpath
/createverticalpath
/creatediagonalbackwardpath
/creatediagonalforwardpath
by default so you don’t have to override allcreatepath7*
methods.
Comments are closed.