From 0a48add4a577fb4b1b6e042722c02c0adbdf2ecd Mon Sep 17 00:00:00 2001 From: robiness Date: Sat, 4 Nov 2023 15:56:58 +0100 Subject: [PATCH 1/4] Clean up naming, structure and imports --- example/lib/stage_data/my_widget_stage.dart | 2 +- example/test/widget_test.dart | 2 +- .../field_configurators/field_configurators.dart | 9 +++++++++ lib/src/stage/stage.dart | 5 +++++ lib/src/{widgets => stage}/stage_area.dart | 1 - lib/src/{ => stage}/stage_controller.dart | 8 ++++---- lib/src/{widgets => stage}/stage_craft.dart | 8 ++++---- .../stage_data.dart} | 3 +-- lib/src/{ => stage}/stage_settings.dart | 6 ++++-- lib/src/widgets/configuration_bar.dart | 14 +++++--------- lib/src/widgets/widgets.dart | 2 ++ lib/stage_craft.dart | 6 ++---- 12 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 lib/src/field_configurators/field_configurators.dart create mode 100644 lib/src/stage/stage.dart rename lib/src/{widgets => stage}/stage_area.dart (99%) rename lib/src/{ => stage}/stage_controller.dart (92%) rename lib/src/{widgets => stage}/stage_craft.dart (92%) rename lib/src/{widget_stage_data.dart => stage/stage_data.dart} (97%) rename lib/src/{ => stage}/stage_settings.dart (97%) create mode 100644 lib/src/widgets/widgets.dart diff --git a/example/lib/stage_data/my_widget_stage.dart b/example/lib/stage_data/my_widget_stage.dart index 23fe321..3e5cbb9 100644 --- a/example/lib/stage_data/my_widget_stage.dart +++ b/example/lib/stage_data/my_widget_stage.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:stage_craft/stage_craft.dart'; /// Defines everything you need to put it on the stage. -class MyWidgetStageData extends WidgetStageData { +class MyWidgetStageData extends StageData { MyWidgetStageData() : _color = ColorFieldConfiguratorNullable(value: null, name: 'color'), _borderColor = ColorFieldConfiguratorNullable(value: null, name: 'borderColor'), diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 3a341c4..d3927f1 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { extension WidgetTesterExtension on WidgetTester { Future pumpWidgetData( - WidgetStageData stageData, + StageData stageData, ) async { await pumpWidget( MaterialApp( diff --git a/lib/src/field_configurators/field_configurators.dart b/lib/src/field_configurators/field_configurators.dart new file mode 100644 index 0000000..273c457 --- /dev/null +++ b/lib/src/field_configurators/field_configurators.dart @@ -0,0 +1,9 @@ +export 'bool_field_configurator.dart'; +export 'color_field_configurator.dart'; +export 'double_field_configurator.dart'; +export 'enum_field_configurator.dart'; +export 'field_configurator.dart'; +export 'int_field_configurator.dart'; +export 'offset_field_configurator.dart'; +export 'padding_field_configurator.dart'; +export 'string_field_configurator.dart'; diff --git a/lib/src/stage/stage.dart b/lib/src/stage/stage.dart new file mode 100644 index 0000000..ff396a8 --- /dev/null +++ b/lib/src/stage/stage.dart @@ -0,0 +1,5 @@ +export 'stage_area.dart'; +export 'stage_controller.dart'; +export 'stage_craft.dart'; +export 'stage_data.dart'; +export 'stage_settings.dart'; diff --git a/lib/src/widgets/stage_area.dart b/lib/src/stage/stage_area.dart similarity index 99% rename from lib/src/widgets/stage_area.dart rename to lib/src/stage/stage_area.dart index 1482acb..089880a 100644 --- a/lib/src/widgets/stage_area.dart +++ b/lib/src/stage/stage_area.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:stage_craft/src/stage_settings.dart'; import 'package:stage_craft/stage_craft.dart'; class StageArea extends StatefulWidget { diff --git a/lib/src/stage_controller.dart b/lib/src/stage/stage_controller.dart similarity index 92% rename from lib/src/stage_controller.dart rename to lib/src/stage/stage_controller.dart index 6da5a34..cc3ca81 100644 --- a/lib/src/stage_controller.dart +++ b/lib/src/stage/stage_controller.dart @@ -1,5 +1,5 @@ import 'package:flutter/widgets.dart'; -import 'package:stage_craft/src/widget_stage_data.dart'; +import 'package:stage_craft/src/stage/stage_data.dart'; class StageController extends ChangeNotifier { StageController({ @@ -64,7 +64,7 @@ class StageController extends ChangeNotifier { double scale(double value) => value * (1 / zoom); - void selectWidget(WidgetStageData selectedWidget) { + void selectWidget(StageData selectedWidget) { if (_selectedWidget == selectedWidget) { for (final configurator in _selectedWidget!.allConfigurators) { configurator.removeListener(notifyListeners); @@ -82,9 +82,9 @@ class StageController extends ChangeNotifier { notifyListeners(); } - WidgetStageData? _selectedWidget; + StageData? _selectedWidget; - WidgetStageData? get selectedWidget => _selectedWidget; + StageData? get selectedWidget => _selectedWidget; final Color initialBackgroundColor; diff --git a/lib/src/widgets/stage_craft.dart b/lib/src/stage/stage_craft.dart similarity index 92% rename from lib/src/widgets/stage_craft.dart rename to lib/src/stage/stage_craft.dart index 699446d..308852d 100644 --- a/lib/src/widgets/stage_craft.dart +++ b/lib/src/stage/stage_craft.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart'; -import 'package:stage_craft/src/stage_controller.dart'; -import 'package:stage_craft/src/widget_stage_data.dart'; +import 'package:stage_craft/src/stage/stage_area.dart'; +import 'package:stage_craft/src/stage/stage_controller.dart'; +import 'package:stage_craft/src/stage/stage_data.dart'; import 'package:stage_craft/src/widgets/configuration_bar.dart'; -import 'package:stage_craft/src/widgets/stage_area.dart'; import 'package:universal_io/io.dart'; /// The [StageCraft] widget is the main widget of the StageCraft package. @@ -38,7 +38,7 @@ class StageCraft extends StatefulWidget { final Widget? configurationBarFooter; /// The initially selected stage data. - final WidgetStageData? stageData; + final StageData? stageData; @override State createState() => _StageCraftState(); diff --git a/lib/src/widget_stage_data.dart b/lib/src/stage/stage_data.dart similarity index 97% rename from lib/src/widget_stage_data.dart rename to lib/src/stage/stage_data.dart index 433ed3e..933d032 100644 --- a/lib/src/widget_stage_data.dart +++ b/lib/src/stage/stage_data.dart @@ -62,8 +62,7 @@ import 'package:stage_craft/stage_craft.dart'; /// ]; /// } /// ``` -abstract class WidgetStageData extends ChangeNotifier { - +abstract class StageData extends ChangeNotifier { /// The name of the widget. String get name; diff --git a/lib/src/stage_settings.dart b/lib/src/stage/stage_settings.dart similarity index 97% rename from lib/src/stage_settings.dart rename to lib/src/stage/stage_settings.dart index 9084941..3816e21 100644 --- a/lib/src/stage_settings.dart +++ b/lib/src/stage/stage_settings.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; -import 'package:stage_craft/src/stage_controller.dart'; +import 'package:stage_craft/src/stage/stage_controller.dart'; class StageSettingsWidget extends StatelessWidget { const StageSettingsWidget({ @@ -201,7 +201,9 @@ class _ZoomSliderState extends State { mainAxisSize: MainAxisSize.min, children: [ const Text('Zoom'), - Text(widget.stageController.zoom.toStringAsFixed(2),), + Text( + widget.stageController.zoom.toStringAsFixed(2), + ), SizedBox( width: 300, child: Slider( diff --git a/lib/src/widgets/configuration_bar.dart b/lib/src/widgets/configuration_bar.dart index e2786e3..4ffcda9 100644 --- a/lib/src/widgets/configuration_bar.dart +++ b/lib/src/widgets/configuration_bar.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:stage_craft/src/field_configurators/field_configurator.dart'; -import 'package:stage_craft/src/stage_controller.dart'; +import 'package:stage_craft/src/stage/stage_controller.dart'; class ConfigurationBar extends StatefulWidget { const ConfigurationBar({ @@ -30,10 +30,8 @@ class _ConfigurationBarState extends State { widgetConfigurators = widget.controller.selectedWidget?.widgetConfigurators; widget.controller.addListener(() { setState(() { - stageConfigurators = - widget.controller.selectedWidget?.stageConfigurators; - widgetConfigurators = - widget.controller.selectedWidget?.widgetConfigurators; + stageConfigurators = widget.controller.selectedWidget?.stageConfigurators; + widgetConfigurators = widget.controller.selectedWidget?.widgetConfigurators; }); }); } @@ -58,8 +56,7 @@ class _ConfigurationBarState extends State { title: 'Stage', configurators: stageConfigurators, ), - if (widget.configurationBarFooter != null) - widget.configurationBarFooter! + if (widget.configurationBarFooter != null) widget.configurationBarFooter! ], ), ), @@ -93,8 +90,7 @@ class _ConfiguratorGroup extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: - const EdgeInsets.symmetric(horizontal: 8.0, vertical: 16), + padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 16), child: Center( child: Text( textAlign: TextAlign.center, diff --git a/lib/src/widgets/widgets.dart b/lib/src/widgets/widgets.dart new file mode 100644 index 0000000..30631e1 --- /dev/null +++ b/lib/src/widgets/widgets.dart @@ -0,0 +1,2 @@ +export 'color_picker.dart'; +export 'configuration_bar.dart'; diff --git a/lib/stage_craft.dart b/lib/stage_craft.dart index 2d2df5d..a89da56 100644 --- a/lib/stage_craft.dart +++ b/lib/stage_craft.dart @@ -1,5 +1,3 @@ export 'src/field_configurators/field_configurator.dart'; -export 'src/stage_controller.dart'; -export 'src/widget_stage_data.dart'; -export 'src/widgets/color_picker.dart'; -export 'src/widgets/stage_craft.dart'; +export 'src/stage/stage.dart'; +export 'src/widgets/widgets.dart'; From c563638271291cd44dc405031c714e9dfe72fda6 Mon Sep 17 00:00:00 2001 From: robiness Date: Sat, 4 Nov 2023 22:14:02 +0100 Subject: [PATCH 2/4] Clean up naming, structure and imports --- example/lib/main.dart | 4 +- example/lib/my_widget_stage.dart | 4 +- .../bool_field_configurator_stage_data.dart | 25 ++++++++ .../color_field_configurator_stage_data.dart | 25 ++++++++ example/lib/stage_data/my_widget_stage.dart | 54 ---------------- example/lib/widgets/my_widget.dart | 61 ------------------- example/test/widget_test.dart | 4 +- .../bool_field_configurator.dart | 8 +-- .../color_field_configurator.dart | 43 ++++++------- 9 files changed, 80 insertions(+), 148 deletions(-) create mode 100644 example/lib/stage_data/bool_field_configurator_stage_data.dart create mode 100644 example/lib/stage_data/color_field_configurator_stage_data.dart delete mode 100644 example/lib/stage_data/my_widget_stage.dart delete mode 100644 example/lib/widgets/my_widget.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index d8f6d76..92a9d42 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,4 @@ -import 'package:example/stage_data/my_widget_stage.dart'; +import 'package:example/stage_data/color_field_configurator_stage_data.dart'; import 'package:flutter/material.dart'; import 'package:stage_craft/stage_craft.dart'; @@ -17,7 +17,7 @@ class MyApp extends StatelessWidget { debugShowCheckedModeBanner: false, home: Scaffold( body: StageCraft( - stageData: MyWidgetStageData(), + stageData: ColorFieldConfiguratorStageData(), ), ), ); diff --git a/example/lib/my_widget_stage.dart b/example/lib/my_widget_stage.dart index c5fdcf7..be791ca 100644 --- a/example/lib/my_widget_stage.dart +++ b/example/lib/my_widget_stage.dart @@ -1,4 +1,4 @@ -import 'package:example/stage_data/my_widget_stage.dart'; +import 'package:example/stage_data/bool_field_configurator_stage_data.dart'; import 'package:flutter/material.dart'; import 'package:stage_craft/stage_craft.dart'; import 'package:window_manager/window_manager.dart'; @@ -25,7 +25,7 @@ Future main() async { MaterialApp( home: Scaffold( body: StageCraft( - stageData: MyWidgetStageData(), + stageData: BoolFieldConfiguratorStageData(), ), ), ), diff --git a/example/lib/stage_data/bool_field_configurator_stage_data.dart b/example/lib/stage_data/bool_field_configurator_stage_data.dart new file mode 100644 index 0000000..66998e2 --- /dev/null +++ b/example/lib/stage_data/bool_field_configurator_stage_data.dart @@ -0,0 +1,25 @@ +import 'package:flutter/widgets.dart'; +import 'package:stage_craft/stage_craft.dart'; + +class BoolFieldConfiguratorStageData extends StageData { + @override + String get name => 'BoolFieldConfiguration'; + + final value = BoolFieldConfigurator(value: true, name: 'value'); + + @override + List get stageConfigurators => []; + + @override + List get widgetConfigurators => [value]; + + @override + Widget widgetBuilder(BuildContext context) { + return BoolConfigurationWidget( + value: value.value, + updateValue: (value) { + this.value.value = value!; + }, + ); + } +} diff --git a/example/lib/stage_data/color_field_configurator_stage_data.dart b/example/lib/stage_data/color_field_configurator_stage_data.dart new file mode 100644 index 0000000..59fafad --- /dev/null +++ b/example/lib/stage_data/color_field_configurator_stage_data.dart @@ -0,0 +1,25 @@ +import 'package:flutter/widgets.dart'; +import 'package:stage_craft/stage_craft.dart'; + +class ColorFieldConfiguratorStageData extends StageData { + @override + String get name => 'ColorFieldConfiguration'; + + final value = ColorFieldConfigurator(value: const Color(0xFF000000), name: 'value'); + + @override + List get stageConfigurators => []; + + @override + List get widgetConfigurators => [value]; + + @override + Widget widgetBuilder(BuildContext context) { + return ColorConfigurationWidget( + value: value.value, + updateValue: (value) { + this.value.value = value!; + }, + ); + } +} diff --git a/example/lib/stage_data/my_widget_stage.dart b/example/lib/stage_data/my_widget_stage.dart deleted file mode 100644 index 3e5cbb9..0000000 --- a/example/lib/stage_data/my_widget_stage.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'package:example/widgets/my_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:stage_craft/stage_craft.dart'; - -/// Defines everything you need to put it on the stage. -class MyWidgetStageData extends StageData { - MyWidgetStageData() - : _color = ColorFieldConfiguratorNullable(value: null, name: 'color'), - _borderColor = ColorFieldConfiguratorNullable(value: null, name: 'borderColor'), - _text = StringFieldConfigurator(value: "My text", name: 'text'), - _nullableBool = BoolFieldConfiguratorNullable(value: false, name: 'nullableBool'), - _borderRadius = DoubleFieldConfiguratorNullable(value: 4, name: 'borderRadius'), - _padding = PaddingFieldConfigurator(value: const EdgeInsets.all(8), name: 'padding'); - - @override - String get name => 'MyWidget'; - - @override - Size get stageSize => const Size(400, 200); - - final ColorFieldConfiguratorNullable _color; - final ColorFieldConfiguratorNullable _borderColor; - final StringFieldConfigurator _text; - final BoolFieldConfiguratorNullable _nullableBool; - final DoubleFieldConfiguratorNullable _borderRadius; - final PaddingFieldConfigurator _padding; - - @override - Widget widgetBuilder(BuildContext context) { - return MyWidget( - color: _color.value, - borderColor: _borderColor.value, - text: _text.value, - borderRadius: _borderRadius.value, - isTrue: _nullableBool.value, - padding: _padding.value, - ); - } - - @override - List get widgetConfigurators { - return [ - _color, - _borderColor, - _text, - _borderRadius, - _nullableBool, - _padding, - ]; - } - - @override - List get stageConfigurators => []; -} diff --git a/example/lib/widgets/my_widget.dart b/example/lib/widgets/my_widget.dart deleted file mode 100644 index c5d3f5a..0000000 --- a/example/lib/widgets/my_widget.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:flutter/material.dart'; - -class MyWidget extends StatelessWidget { - const MyWidget({ - super.key, - required this.color, - required this.text, - this.isTrue, - this.borderColor, - EdgeInsets? padding, - this.borderRadius = 8, - }) : padding = padding ?? const EdgeInsets.all(8.0); - - final Color? color; - final Color? borderColor; - final double? borderRadius; - final String text; - final bool? isTrue; - final EdgeInsets padding; - - @override - Widget build(BuildContext context) { - return Padding( - padding: padding, - child: Container( - decoration: BoxDecoration( - color: color ?? Colors.transparent, - borderRadius: BorderRadius.circular(borderRadius ?? 0), - ), - child: Row( - children: [ - Expanded( - child: Container( - decoration: BoxDecoration( - border: Border.all(color: borderColor ?? const Color(0xFF000000)), - borderRadius: BorderRadius.circular(borderRadius ?? 0), - ), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text("$text is $isTrue"), - ), - ), - ), - Expanded( - child: Container( - decoration: BoxDecoration( - border: Border.all(color: borderColor ?? const Color(0xFF000000)), - borderRadius: BorderRadius.circular(borderRadius ?? 0), - ), - child: const Padding( - padding: EdgeInsets.all(8.0), - child: Text("right"), - ), - ), - ), - ], - ), - ), - ); - } -} diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index d3927f1..8a9aa40 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -5,14 +5,14 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:example/stage_data/my_widget_stage.dart'; +import 'package:example/stage_data/bool_field_configurator_stage_data.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:stage_craft/stage_craft.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { - await tester.pumpWidgetData(MyWidgetStageData()); + await tester.pumpWidgetData(BoolFieldConfiguratorStageData()); expect(find.text('MyOtherWidget'), findsOneWidget); }); } diff --git a/lib/src/field_configurators/bool_field_configurator.dart b/lib/src/field_configurators/bool_field_configurator.dart index bdefe62..cc82c3f 100644 --- a/lib/src/field_configurators/bool_field_configurator.dart +++ b/lib/src/field_configurators/bool_field_configurator.dart @@ -9,7 +9,7 @@ class BoolFieldConfiguratorNullable extends FieldConfigurator { @override Widget build(BuildContext context) { - return BoolFieldConfigurationWidget( + return BoolConfigurationWidget( value: value, updateValue: updateValue, ); @@ -25,7 +25,7 @@ class BoolFieldConfigurator extends FieldConfigurator { @override Widget build(BuildContext context) { - return BoolFieldConfigurationWidget( + return BoolConfigurationWidget( value: value, updateValue: (value) { updateValue(value ?? false); @@ -34,8 +34,8 @@ class BoolFieldConfigurator extends FieldConfigurator { } } -class BoolFieldConfigurationWidget extends ConfigurationWidget { - const BoolFieldConfigurationWidget({ +class BoolConfigurationWidget extends ConfigurationWidget { + const BoolConfigurationWidget({ required super.value, required super.updateValue, }); diff --git a/lib/src/field_configurators/color_field_configurator.dart b/lib/src/field_configurators/color_field_configurator.dart index 7884877..eb2aab6 100644 --- a/lib/src/field_configurators/color_field_configurator.dart +++ b/lib/src/field_configurators/color_field_configurator.dart @@ -93,30 +93,27 @@ class ColorConfigurationWidget extends ConfigurationWidget { }, ); }, - child: Align( - alignment: Alignment.centerRight, - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: ClipRRect( - borderRadius: BorderRadius.circular(8), - child: Container( - height: 38, - width: 38, - foregroundDecoration: BoxDecoration( - // The actual color drawn over the chessboard pattern - color: value, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: ClipRRect( + borderRadius: BorderRadius.circular(8), + child: Container( + height: 38, + width: 38, + foregroundDecoration: BoxDecoration( + // The actual color drawn over the chessboard pattern + color: value, + ), + // The chessboard pattern + child: const CustomPaint( + foregroundPainter: ChessBoardPainter( + boxSize: 8, + // The color of the chessboard pattern + color: Colors.grey, ), - // The chessboard pattern - child: const CustomPaint( - foregroundPainter: ChessBoardPainter( - boxSize: 8, - // The color of the chessboard pattern - color: Colors.grey, - ), - child: ColoredBox( - // Background of the chessboard pattern - color: Colors.white, - ), + child: ColoredBox( + // Background of the chessboard pattern + color: Colors.white, ), ), ), From 4becde1d11bcb00697775af7fec75d9405592137 Mon Sep 17 00:00:00 2001 From: robiness Date: Tue, 7 Nov 2023 14:06:29 +0100 Subject: [PATCH 3/4] Fix updateValue --- example/lib/main.dart | 11 +++++++--- example/pubspec.lock | 16 ++++++++++++++ .../double_field_configurator.dart | 7 +----- .../field_configurator.dart | 22 +++++-------------- .../field_configurators.dart | 1 + .../int_field_configurator.dart | 15 +++++-------- .../offset_field_configurator.dart | 8 ++----- .../padding_field_configurator.dart | 11 ++++------ .../string_field_configurator.dart | 9 ++------ lib/stage_craft.dart | 2 +- 10 files changed, 46 insertions(+), 56 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 92a9d42..ffbfca6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,4 @@ -import 'package:example/stage_data/color_field_configurator_stage_data.dart'; +import 'package:example/stage_data/string_list_configurator_stage_data.dart'; import 'package:flutter/material.dart'; import 'package:stage_craft/stage_craft.dart'; @@ -6,9 +6,14 @@ void main() { runApp(const MyApp()); } -class MyApp extends StatelessWidget { +class MyApp extends StatefulWidget { const MyApp({super.key}); + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( @@ -17,7 +22,7 @@ class MyApp extends StatelessWidget { debugShowCheckedModeBanner: false, home: Scaffold( body: StageCraft( - stageData: ColorFieldConfiguratorStageData(), + stageData: StringListConfiguratorStageData(), ), ), ); diff --git a/example/pubspec.lock b/example/pubspec.lock index b42ceaa..43e2206 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -191,6 +191,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + universal_io: + dependency: transitive + description: + name: universal_io + sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad" + url: "https://pub.dev" + source: hosted + version: "2.2.2" vector_math: dependency: transitive description: diff --git a/lib/src/field_configurators/double_field_configurator.dart b/lib/src/field_configurators/double_field_configurator.dart index b30a6f9..dd0a80f 100644 --- a/lib/src/field_configurators/double_field_configurator.dart +++ b/lib/src/field_configurators/double_field_configurator.dart @@ -13,7 +13,6 @@ class DoubleFieldConfiguratorNullable extends FieldConfigurator { Widget build(BuildContext context) { return DoubleFieldConfigurationWidget( configurator: this, - updateValue: updateValue, ); } } @@ -29,9 +28,6 @@ class DoubleFieldConfigurator extends FieldConfigurator { Widget build(BuildContext context) { return DoubleFieldConfigurationWidget( configurator: this, - updateValue: (value) { - updateValue(value ?? 0.0); - }, ); } } @@ -40,7 +36,6 @@ class DoubleFieldConfigurationWidget extends StatefulConfigurationWidget extends StatefulWidget { final FieldConfigurator fieldConfigurator; @override - State> createState() => - _FieldConfiguratorWidgetState(); + State> createState() => _FieldConfiguratorWidgetState(); } -class _FieldConfiguratorWidgetState - extends State> { +class _FieldConfiguratorWidgetState extends State> { @override Widget build(BuildContext context) { return Padding( @@ -99,11 +97,9 @@ abstract class StatefulConfigurationWidget extends StatefulWidget { const StatefulConfigurationWidget({ super.key, required this.configurator, - required this.updateValue, }); final FieldConfigurator configurator; - final void Function(T newValue) updateValue; } class FieldConfiguratorInputField extends StatefulWidget { @@ -119,12 +115,10 @@ class FieldConfiguratorInputField extends StatefulWidget { final void Function(String value)? onChanged; @override - State createState() => - _FieldConfiguratorInputFieldState(); + State createState() => _FieldConfiguratorInputFieldState(); } -class _FieldConfiguratorInputFieldState - extends State { +class _FieldConfiguratorInputFieldState extends State { bool _isHovering = false; @override @@ -139,9 +133,7 @@ class _FieldConfiguratorInputFieldState color: Colors.blue.withOpacity(0.1), borderRadius: BorderRadius.circular(2), border: Border.all( - color: _isHovering - ? Colors.blue.withOpacity(0.5) - : Colors.transparent, + color: _isHovering ? Colors.blue.withOpacity(0.5) : Colors.transparent, ), ), child: Padding( @@ -191,9 +183,7 @@ class _NullableButtonState extends State { padding: const EdgeInsets.all(4.0), child: Container( decoration: BoxDecoration( - color: isNull || _isHovering - ? Colors.blue.withOpacity(0.2) - : Colors.transparent, + color: isNull || _isHovering ? Colors.blue.withOpacity(0.2) : Colors.transparent, border: Border.all(color: isNull ? Colors.blue : Colors.grey), borderRadius: BorderRadius.circular(4), ), diff --git a/lib/src/field_configurators/field_configurators.dart b/lib/src/field_configurators/field_configurators.dart index 273c457..7770356 100644 --- a/lib/src/field_configurators/field_configurators.dart +++ b/lib/src/field_configurators/field_configurators.dart @@ -7,3 +7,4 @@ export 'int_field_configurator.dart'; export 'offset_field_configurator.dart'; export 'padding_field_configurator.dart'; export 'string_field_configurator.dart'; +export 'string_list_configurator.dart'; diff --git a/lib/src/field_configurators/int_field_configurator.dart b/lib/src/field_configurators/int_field_configurator.dart index 4f6561e..b43f59b 100644 --- a/lib/src/field_configurators/int_field_configurator.dart +++ b/lib/src/field_configurators/int_field_configurator.dart @@ -11,9 +11,8 @@ class IntFieldConfiguratorNullable extends FieldConfigurator { @override Widget build(BuildContext context) { - return IntFieldConfigurationWidget( + return IntFieldConfigurationWidget( configurator: this, - updateValue: updateValue, ); } } @@ -27,20 +26,16 @@ class IntFieldConfigurator extends FieldConfigurator { @override Widget build(BuildContext context) { - return IntFieldConfigurationWidget( + return IntFieldConfigurationWidget( configurator: this, - updateValue: (value) { - updateValue(value ?? 0); - }, ); } } -class IntFieldConfigurationWidget extends StatefulConfigurationWidget { +class IntFieldConfigurationWidget extends StatefulConfigurationWidget { const IntFieldConfigurationWidget({ super.key, required super.configurator, - required super.updateValue, }); @override @@ -56,7 +51,7 @@ class _IntFieldConfigurationWidgetState extends State { Widget build(BuildContext context) { return OffsetFieldConfigurationWidget( configurator: this, - updateValue: (value) { - updateValue(value ?? Offset.zero); - }, ); } } @@ -24,7 +21,6 @@ class OffsetFieldConfigurationWidget extends StatefulConfigurationWidget { Widget build(BuildContext context) { return PaddingFieldConfigurationWidget( configurator: this, - updateValue: updateValue, ); } } @@ -29,7 +28,6 @@ class PaddingFieldConfigurator extends FieldConfigurator { Widget build(BuildContext context) { return PaddingFieldConfigurationWidget( configurator: this, - updateValue: (value) => updateValue(value ?? EdgeInsets.zero), ); } } @@ -38,7 +36,6 @@ class PaddingFieldConfigurationWidget extends StatefulConfigurationWidget { Widget build(BuildContext context) { return StringFieldConfigurationWidget( configurator: this, - updateValue: updateValue, ); } } @@ -28,9 +27,6 @@ class StringFieldConfigurator extends FieldConfigurator { Widget build(BuildContext context) { return StringFieldConfigurationWidget( configurator: this, - updateValue: (value) { - updateValue(value ?? ''); - }, ); } } @@ -39,7 +35,6 @@ class StringFieldConfigurationWidget extends StatefulConfigurationWidget Date: Tue, 7 Nov 2023 14:06:43 +0100 Subject: [PATCH 4/4] Add StringListConfigurator --- .../string_list_configurator_stage_data.dart | 22 ++++++ .../string_list_configurator.dart | 76 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 example/lib/stage_data/string_list_configurator_stage_data.dart create mode 100644 lib/src/field_configurators/string_list_configurator.dart diff --git a/example/lib/stage_data/string_list_configurator_stage_data.dart b/example/lib/stage_data/string_list_configurator_stage_data.dart new file mode 100644 index 0000000..9cff6e0 --- /dev/null +++ b/example/lib/stage_data/string_list_configurator_stage_data.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:stage_craft/stage_craft.dart'; + +class StringListConfiguratorStageData extends StageData { + final value = StringListConfigurator(value: ['jo', 'jojo2', 'jojojo'], name: 'value'); + + @override + String get name => 'StringListConfigurator'; + + @override + List get stageConfigurators => []; + + @override + List get widgetConfigurators => [ + value, + ]; + + @override + Widget widgetBuilder(BuildContext context) { + return StringListConfiguratorWidget(configurator: value); + } +} diff --git a/lib/src/field_configurators/string_list_configurator.dart b/lib/src/field_configurators/string_list_configurator.dart new file mode 100644 index 0000000..01d9b03 --- /dev/null +++ b/lib/src/field_configurators/string_list_configurator.dart @@ -0,0 +1,76 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:stage_craft/src/field_configurators/field_configurator.dart'; + +class StringListConfigurator extends FieldConfigurator> { + StringListConfigurator({ + required super.value, + required super.name, + this.defaultValue, + }); + + final String? defaultValue; + + @override + Widget build(BuildContext context) { + return StringListConfiguratorWidget( + configurator: this, + defaultValue: defaultValue, + ); + } +} + +class StringListConfiguratorWidget extends StatefulConfigurationWidget> { + const StringListConfiguratorWidget({ + super.key, + required super.configurator, + this.defaultValue, + }); + + final String? defaultValue; + + @override + State createState() => _StringListConfiguratorWidgetState(); +} + +class _StringListConfiguratorWidgetState extends State { + @override + Widget build(BuildContext context) { + return Column( + children: [ + ...widget.configurator.value.mapIndexed((index, e) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Expanded( + child: FieldConfiguratorInputField( + controller: TextEditingController(text: e)..selection = TextSelection.collapsed(offset: e.length), + onChanged: (value) { + widget.configurator.value[index] = value; + widget.configurator.updateValue(widget.configurator.value); + }, + ), + ), + IconButton( + icon: const Icon(Icons.remove), + onPressed: () { + final newValue = widget.configurator.value; + newValue.removeAt(index); + widget.configurator.updateValue(newValue); + }, + ) + ], + ); + }), + IconButton( + icon: const Icon(Icons.add), + onPressed: () { + final newValue = widget.configurator.value; + newValue.add(widget.defaultValue ?? 'new value'); + widget.configurator.updateValue(newValue); + }, + ), + ], + ); + } +}