Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a SliderProperty #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/src/story.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,28 @@ class DashbookContext {
);
}

double sliderProperty(
String name,
double defaultValue, {
String? tooltipMessage,
ControlProperty? visibilityControlProperty,
}) {
return addProperty(
Property<double>.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, {
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/property_widgets/properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
38 changes: 38 additions & 0 deletions lib/src/widgets/property_widgets/slider_property.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:dashbook/dashbook.dart';
import 'package:flutter/material.dart';

class SliderProperty extends StatefulWidget {
final Property<double> property;
final PropertyChanged onChanged;

const SliderProperty({
required this.property,
required this.onChanged,
super.key,
});

@override
State<StatefulWidget> createState() =>
SliderPropertyState(property.getValue());
}

class SliderPropertyState extends State<SliderProperty> {
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();
},
),
);
}
}