From 46981e1f72da9442fbd9b904f72a008523b97721 Mon Sep 17 00:00:00 2001 From: John Thomas McDole Date: Sat, 14 Dec 2024 11:49:19 -0800 Subject: [PATCH] Add a SliderProperty --- lib/src/story.dart | 22 +++++++++++ .../widgets/property_widgets/properties.dart | 1 + .../property_widgets/slider_property.dart | 38 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/src/widgets/property_widgets/slider_property.dart diff --git a/lib/src/story.dart b/lib/src/story.dart index 5184195..17670ce 100644 --- a/lib/src/story.dart +++ b/lib/src/story.dart @@ -237,6 +237,28 @@ class DashbookContext { ); } + double sliderProperty( + String name, + double defaultValue, { + String? tooltipMessage, + ControlProperty? visibilityControlProperty, + }) { + return addProperty( + Property.withBuilder( + name, + defaultValue, + tooltipMessage: tooltipMessage, + visibilityControlProperty: visibilityControlProperty, + builder: (property, onChanged, key) => p.SliderProperty( + property: property, + onChanged: onChanged, + key: key, + ), + ), + ); + + } + Color colorProperty( String name, Color defaultValue, { diff --git a/lib/src/widgets/property_widgets/properties.dart b/lib/src/widgets/property_widgets/properties.dart index 4ddd5f8..29b8668 100644 --- a/lib/src/widgets/property_widgets/properties.dart +++ b/lib/src/widgets/property_widgets/properties.dart @@ -5,4 +5,5 @@ export 'edge_insets_property.dart'; export 'list_property.dart'; export 'number_property.dart'; export 'options_property.dart'; +export 'slider_property.dart'; export 'text_property.dart'; diff --git a/lib/src/widgets/property_widgets/slider_property.dart b/lib/src/widgets/property_widgets/slider_property.dart new file mode 100644 index 0000000..d2feff7 --- /dev/null +++ b/lib/src/widgets/property_widgets/slider_property.dart @@ -0,0 +1,38 @@ +import 'package:dashbook/dashbook.dart'; +import 'package:flutter/material.dart'; + +class SliderProperty extends StatefulWidget { + final Property property; + final PropertyChanged onChanged; + + const SliderProperty({ + required this.property, + required this.onChanged, + super.key, + }); + + @override + State createState() => + SliderPropertyState(property.getValue()); +} + +class SliderPropertyState extends State { + double value; + SliderPropertyState(this.value); + + @override + Widget build(BuildContext context) { + return PropertyScaffold( + tooltipMessage: widget.property.tooltipMessage, + label: widget.property.name, + child: Slider( + value: value, + onChanged: (newValue) { + value = newValue; + widget.property.value = newValue; + widget.onChanged(); + }, + ), + ); + } +}