From b913baa3d30fb2b3936a8780926682235e94086f Mon Sep 17 00:00:00 2001 From: hetvin kathiriya Date: Tue, 21 Jan 2025 15:45:27 +0530 Subject: [PATCH] fix: update code according latest version --- example/lib/main.dart | 165 ++------ lib/src/controllers/painter_controller.dart | 73 ++-- lib/src/views/widgets/object_widget.dart | 437 ++++++-------------- 3 files changed, 188 insertions(+), 487 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 08e3522f..66e1e149 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -19,8 +19,7 @@ class MyApp extends StatelessWidget { return MaterialApp( debugShowCheckedModeBanner: false, title: "Flutter Painter Example", - theme: ThemeData( - primaryColor: Colors.brown, accentColor: Colors.amberAccent), + theme: ThemeData(primaryColor: Colors.brown, secondaryHeaderColor: Colors.amberAccent), home: const FlutterPainterExample(), ); } @@ -80,8 +79,7 @@ class _FlutterPainterExampleState extends State { settings: PainterSettings( text: TextSettings( focusNode: textFocusNode, - textStyle: const TextStyle( - fontWeight: FontWeight.bold, color: red, fontSize: 18), + textStyle: const TextStyle(fontWeight: FontWeight.bold, color: red, fontSize: 18), ), freeStyle: const FreeStyleSettings( color: red, @@ -105,8 +103,7 @@ class _FlutterPainterExampleState extends State { /// to use it as a background void initBackground() async { // Extension getter (.image) to get [ui.Image] from [ImageProvider] - final image = - await const NetworkImage('https://picsum.photos/1920/1080/').image; + final image = await const NetworkImage('https://picsum.photos/1920/1080/').image; setState(() { backgroundImage = image; @@ -136,17 +133,14 @@ class _FlutterPainterExampleState extends State { icon: const Icon( PhosphorIcons.trash, ), - onPressed: controller.selectedObjectDrawable == null - ? null - : removeSelectedDrawable, + onPressed: controller.selectedObjectDrawable == null ? null : removeSelectedDrawable, ), // Delete the selected drawable IconButton( icon: const Icon( Icons.flip, ), - onPressed: controller.selectedObjectDrawable != null && - controller.selectedObjectDrawable is ImageDrawable + onPressed: controller.selectedObjectDrawable != null && controller.selectedObjectDrawable is ImageDrawable ? flipSelectedImageDrawable : null, ), @@ -182,8 +176,7 @@ class _FlutterPainterExampleState extends State { Positioned.fill( child: Center( child: AspectRatio( - aspectRatio: - backgroundImage!.width / backgroundImage!.height, + aspectRatio: backgroundImage!.width / backgroundImage!.height, child: FlutterPainter( controller: controller, ), @@ -206,22 +199,19 @@ class _FlutterPainterExampleState extends State { ), padding: const EdgeInsets.symmetric(horizontal: 15), decoration: const BoxDecoration( - borderRadius: - BorderRadius.vertical(top: Radius.circular(20)), + borderRadius: BorderRadius.vertical(top: Radius.circular(20)), color: Colors.white54, ), child: Column( mainAxisSize: MainAxisSize.min, children: [ - if (controller.freeStyleMode != - FreeStyleMode.none) ...[ + if (controller.freeStyleMode != FreeStyleMode.none) ...[ const Divider(), const Text("Free Style Settings"), // Control free style stroke width Row( children: [ - const Expanded( - flex: 1, child: Text("Stroke Width")), + const Expanded(flex: 1, child: Text("Stroke Width")), Expanded( flex: 3, child: Slider.adaptive( @@ -232,23 +222,18 @@ class _FlutterPainterExampleState extends State { ), ], ), - if (controller.freeStyleMode == - FreeStyleMode.draw) + if (controller.freeStyleMode == FreeStyleMode.draw) Row( children: [ - const Expanded( - flex: 1, child: Text("Color")), + const Expanded(flex: 1, child: Text("Color")), // Control free style color hue Expanded( flex: 3, child: Slider.adaptive( min: 0, max: 359.99, - value: HSVColor.fromColor( - controller.freeStyleColor) - .hue, - activeColor: - controller.freeStyleColor, + value: HSVColor.fromColor(controller.freeStyleColor).hue, + activeColor: controller.freeStyleColor, onChanged: setFreeStyleColor), ), ], @@ -260,16 +245,11 @@ class _FlutterPainterExampleState extends State { // Control text font size Row( children: [ - const Expanded( - flex: 1, child: Text("Font Size")), + const Expanded(flex: 1, child: Text("Font Size")), Expanded( flex: 3, child: Slider.adaptive( - min: 8, - max: 96, - value: - controller.textStyle.fontSize ?? 14, - onChanged: setTextFontSize), + min: 8, max: 96, value: controller.textStyle.fontSize ?? 14, onChanged: setTextFontSize), ), ], ), @@ -283,10 +263,7 @@ class _FlutterPainterExampleState extends State { child: Slider.adaptive( min: 0, max: 359.99, - value: HSVColor.fromColor( - controller.textStyle.color ?? - red) - .hue, + value: HSVColor.fromColor(controller.textStyle.color ?? red).hue, activeColor: controller.textStyle.color, onChanged: setTextColor), ), @@ -300,21 +277,14 @@ class _FlutterPainterExampleState extends State { // Control text color hue Row( children: [ - const Expanded( - flex: 1, child: Text("Stroke Width")), + const Expanded(flex: 1, child: Text("Stroke Width")), Expanded( flex: 3, child: Slider.adaptive( min: 2, max: 25, - value: controller - .shapePaint?.strokeWidth ?? - shapePaint.strokeWidth, - onChanged: (value) => - setShapeFactoryPaint( - (controller.shapePaint ?? - shapePaint) - .copyWith( + value: controller.shapePaint?.strokeWidth ?? shapePaint.strokeWidth, + onChanged: (value) => setShapeFactoryPaint((controller.shapePaint ?? shapePaint).copyWith( strokeWidth: value, ))), ), @@ -330,22 +300,10 @@ class _FlutterPainterExampleState extends State { child: Slider.adaptive( min: 0, max: 359.99, - value: HSVColor.fromColor( - (controller.shapePaint ?? - shapePaint) - .color) - .hue, - activeColor: (controller.shapePaint ?? - shapePaint) - .color, - onChanged: (hue) => - setShapeFactoryPaint( - (controller.shapePaint ?? - shapePaint) - .copyWith( - color: HSVColor.fromAHSV( - 1, hue, 1, 1) - .toColor(), + value: HSVColor.fromColor((controller.shapePaint ?? shapePaint).color).hue, + activeColor: (controller.shapePaint ?? shapePaint).color, + onChanged: (hue) => setShapeFactoryPaint((controller.shapePaint ?? shapePaint).copyWith( + color: HSVColor.fromAHSV(1, hue, 1, 1).toColor(), ))), ), ], @@ -353,24 +311,15 @@ class _FlutterPainterExampleState extends State { Row( children: [ - const Expanded( - flex: 1, child: Text("Fill shape")), + const Expanded(flex: 1, child: Text("Fill shape")), Expanded( flex: 3, child: Center( child: Switch( - value: (controller.shapePaint ?? - shapePaint) - .style == - PaintingStyle.fill, + value: (controller.shapePaint ?? shapePaint).style == PaintingStyle.fill, onChanged: (value) => - setShapeFactoryPaint( - (controller.shapePaint ?? - shapePaint) - .copyWith( - style: value - ? PaintingStyle.fill - : PaintingStyle.stroke, + setShapeFactoryPaint((controller.shapePaint ?? shapePaint).copyWith( + style: value ? PaintingStyle.fill : PaintingStyle.stroke, ))), ), ), @@ -396,9 +345,7 @@ class _FlutterPainterExampleState extends State { IconButton( icon: Icon( PhosphorIcons.eraser, - color: controller.freeStyleMode == FreeStyleMode.erase - ? Theme.of(context).accentColor - : null, + color: controller.freeStyleMode == FreeStyleMode.erase ? Theme.of(context).scaffoldBackgroundColor : null, ), onPressed: toggleFreeStyleErase, ), @@ -406,9 +353,7 @@ class _FlutterPainterExampleState extends State { IconButton( icon: Icon( PhosphorIcons.scribbleLoop, - color: controller.freeStyleMode == FreeStyleMode.draw - ? Theme.of(context).accentColor - : null, + color: controller.freeStyleMode == FreeStyleMode.draw ? Theme.of(context).scaffoldBackgroundColor : null, ), onPressed: toggleFreeStyleDraw, ), @@ -416,9 +361,7 @@ class _FlutterPainterExampleState extends State { IconButton( icon: Icon( PhosphorIcons.textT, - color: textFocusNode.hasFocus - ? Theme.of(context).accentColor - : null, + color: textFocusNode.hasFocus ? Theme.of(context).scaffoldBackgroundColor : null, ), onPressed: addText, ), @@ -459,9 +402,7 @@ class _FlutterPainterExampleState extends State { padding: const EdgeInsets.all(8.0), child: Icon( getShapeIcon(controller.shapeFactory), - color: controller.shapeFactory != null - ? Theme.of(context).accentColor - : null, + color: controller.shapeFactory != null ? Theme.of(context).scaffoldBackgroundColor : null, ), ), ) @@ -469,7 +410,7 @@ class _FlutterPainterExampleState extends State { IconButton( icon: Icon( getShapeIcon(controller.shapeFactory), - color: Theme.of(context).accentColor, + color: Theme.of(context).scaffoldBackgroundColor, ), onPressed: () => selectShape(null), ), @@ -503,15 +444,11 @@ class _FlutterPainterExampleState extends State { } void toggleFreeStyleDraw() { - controller.freeStyleMode = controller.freeStyleMode != FreeStyleMode.draw - ? FreeStyleMode.draw - : FreeStyleMode.none; + controller.freeStyleMode = controller.freeStyleMode != FreeStyleMode.draw ? FreeStyleMode.draw : FreeStyleMode.none; } void toggleFreeStyleErase() { - controller.freeStyleMode = controller.freeStyleMode != FreeStyleMode.erase - ? FreeStyleMode.erase - : FreeStyleMode.none; + controller.freeStyleMode = controller.freeStyleMode != FreeStyleMode.erase ? FreeStyleMode.erase : FreeStyleMode.none; } void addText() { @@ -528,8 +465,7 @@ class _FlutterPainterExampleState extends State { imagesLinks: imageLinks, )); if (imageLink == null) return; - controller.addImage( - await NetworkImage(imageLink).image, const Size(100, 100)); + controller.addImage(await NetworkImage(imageLink).image, const Size(100, 100)); } void setFreeStyleStrokeWidth(double value) { @@ -543,9 +479,8 @@ class _FlutterPainterExampleState extends State { void setTextFontSize(double size) { // Set state is just to update the current UI, the [FlutterPainter] UI updates without it setState(() { - controller.textSettings = controller.textSettings.copyWith( - textStyle: - controller.textSettings.textStyle.copyWith(fontSize: size)); + controller.textSettings = + controller.textSettings.copyWith(textStyle: controller.textSettings.textStyle.copyWith(fontSize: size)); }); } @@ -557,8 +492,7 @@ class _FlutterPainterExampleState extends State { } void setTextColor(double hue) { - controller.textStyle = controller.textStyle - .copyWith(color: HSVColor.fromAHSV(1, hue, 1, 1).toColor()); + controller.textStyle = controller.textStyle.copyWith(color: HSVColor.fromAHSV(1, hue, 1, 1).toColor()); } void selectShape(ShapeFactory? factory) { @@ -567,14 +501,11 @@ class _FlutterPainterExampleState extends State { void renderAndDisplayImage() { if (backgroundImage == null) return; - final backgroundImageSize = Size( - backgroundImage!.width.toDouble(), backgroundImage!.height.toDouble()); + final backgroundImageSize = Size(backgroundImage!.width.toDouble(), backgroundImage!.height.toDouble()); // Render the image // Returns a [ui.Image] object, convert to to byte data and then to Uint8List - final imageFuture = controller - .renderImage(backgroundImageSize) - .then((ui.Image image) => image.pngBytes); + final imageFuture = controller.renderImage(backgroundImageSize).then((ui.Image image) => image.pngBytes); // From here, you can write the PNG image data a file or do whatever you want with it // For example: @@ -585,9 +516,7 @@ class _FlutterPainterExampleState extends State { // I am going to display it using Image.memory // Show a dialog with the image - showDialog( - context: context, - builder: (context) => RenderedImageDialog(imageFuture: imageFuture)); + showDialog(context: context, builder: (context) => RenderedImageDialog(imageFuture: imageFuture)); } void removeSelectedDrawable() { @@ -599,16 +528,14 @@ class _FlutterPainterExampleState extends State { final imageDrawable = controller.selectedObjectDrawable; if (imageDrawable is! ImageDrawable) return; - controller.replaceDrawable( - imageDrawable, imageDrawable.copyWith(flipped: !imageDrawable.flipped)); + controller.replaceDrawable(imageDrawable, imageDrawable.copyWith(flipped: !imageDrawable.flipped)); } } class RenderedImageDialog extends StatelessWidget { final Future imageFuture; - const RenderedImageDialog({Key? key, required this.imageFuture}) - : super(key: key); + const RenderedImageDialog({Key? key, required this.imageFuture}) : super(key: key); @override Widget build(BuildContext context) { @@ -626,8 +553,7 @@ class RenderedImageDialog extends StatelessWidget { if (!snapshot.hasData || snapshot.data == null) { return const SizedBox(); } - return InteractiveViewer( - maxScale: 10, child: Image.memory(snapshot.data!)); + return InteractiveViewer(maxScale: 10, child: Image.memory(snapshot.data!)); }, ), ); @@ -637,8 +563,7 @@ class RenderedImageDialog extends StatelessWidget { class SelectStickerImageDialog extends StatelessWidget { final List imagesLinks; - const SelectStickerImageDialog({Key? key, this.imagesLinks = const []}) - : super(key: key); + const SelectStickerImageDialog({Key? key, this.imagesLinks = const []}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/src/controllers/painter_controller.dart b/lib/src/controllers/painter_controller.dart index f2de522f..4a6371d1 100644 --- a/lib/src/controllers/painter_controller.dart +++ b/lib/src/controllers/painter_controller.dart @@ -4,17 +4,17 @@ import 'dart:ui' as ui; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; -import 'events/selected_object_drawable_removed_event.dart'; + +import '../views/painters/painter.dart'; import '../views/widgets/painter_controller_widget.dart'; import 'actions/actions.dart'; -import 'drawables/image_drawable.dart'; -import 'events/events.dart'; import 'drawables/background/background_drawable.dart'; +import 'drawables/drawable.dart'; +import 'drawables/image_drawable.dart'; import 'drawables/object_drawable.dart'; +import 'events/events.dart'; +import 'events/selected_object_drawable_removed_event.dart'; import 'settings/settings.dart'; -import '../views/painters/painter.dart'; - -import 'drawables/drawable.dart'; /// Controller used to control a [FlutterPainter] widget. /// @@ -56,10 +56,7 @@ class PainterController extends ValueNotifier { PainterSettings settings = const PainterSettings(), List? drawables = const [], BackgroundDrawable? background, - }) : this.fromValue(PainterControllerValue( - settings: settings, - drawables: drawables ?? const [], - background: background)); + }) : this.fromValue(PainterControllerValue(settings: settings, drawables: drawables ?? const [], background: background)); /// Create a [PainterController] from a [PainterControllerValue]. PainterController.fromValue(PainterControllerValue value) @@ -78,13 +75,11 @@ class PainterController extends ValueNotifier { /// that they need to update (it calls [notifyListeners]). For this reason, /// this value should only be set between frames, e.g. in response to user /// actions, not during the build, layout, or paint phases. - set background(BackgroundDrawable? background) => - value = value.copyWith(background: background); + set background(BackgroundDrawable? background) => value = value.copyWith(background: background); /// Queues used to track the actions performed on drawables in the controller. /// This is used to [undo] and [redo] actions. - Queue performedActions = DoubleLinkedQueue(), - unperformedActions = DoubleLinkedQueue(); + Queue performedActions = DoubleLinkedQueue(), unperformedActions = DoubleLinkedQueue(); /// Uses the [PainterControllerWidget] inherited widget to fetch the [PainterController] instance in this context. /// This is used internally in the library to fetch the controller at different widgets. @@ -118,8 +113,7 @@ class PainterController extends ValueNotifier { /// that they need to update (it calls [notifyListeners]). For this reason, /// this method should only be called between frames, e.g. in response to user /// actions, not during the build, layout, or paint phases. - void insertDrawables(int index, Iterable drawables, - {bool newAction = true}) { + void insertDrawables(int index, Iterable drawables, {bool newAction = true}) { final action = InsertDrawablesAction(index, drawables.toList()); action.perform(this); _addAction(action, newAction); @@ -140,8 +134,7 @@ class PainterController extends ValueNotifier { /// actions, not during the build, layout, or paint phases. /// /// [notifyListeners] will not be called if the return value is `false`. - bool replaceDrawable(Drawable oldDrawable, Drawable newDrawable, - {bool newAction = true}) { + bool replaceDrawable(Drawable oldDrawable, Drawable newDrawable, {bool newAction = true}) { final action = ReplaceDrawableAction(oldDrawable, newDrawable); final value = action.perform(this); if (value) _addAction(action, newAction); @@ -290,8 +283,7 @@ class PainterController extends ValueNotifier { /// ``` void addImage(ui.Image image, [Size? size]) { // Calculate the center of the painter - final renderBox = - painterKey.currentContext?.findRenderObject() as RenderBox?; + final renderBox = painterKey.currentContext?.findRenderObject() as RenderBox?; final center = renderBox == null ? Offset.zero : Offset( @@ -304,8 +296,7 @@ class PainterController extends ValueNotifier { if (size == null) { drawable = ImageDrawable(image: image, position: center); } else { - drawable = ImageDrawable.fittedToSize( - image: image, position: center, size: size); + drawable = ImageDrawable.fittedToSize(image: image, position: center, size: size); } addDrawables([drawable]); @@ -324,9 +315,7 @@ class PainterController extends ValueNotifier { background: value.background, ); painter.paint(canvas, size); - return await recorder - .endRecording() - .toImage(size.width.floor(), size.height.floor()); + return await recorder.endRecording().toImage(size.width.floor(), size.height.floor()); } /// The currently selected object drawable. @@ -404,21 +393,16 @@ class PainterControllerValue { PainterControllerValue copyWith({ PainterSettings? settings, List? drawables, - BackgroundDrawable? background = - _NoBackgroundPassedBackgroundDrawable.instance, - ObjectDrawable? selectedObjectDrawable = - _NoObjectPassedBackgroundDrawable.instance, + BackgroundDrawable? background = _NoBackgroundPassedBackgroundDrawable.instance, + ObjectDrawable? selectedObjectDrawable = _NoObjectPassedBackgroundDrawable.instance, }) { return PainterControllerValue( settings: settings ?? this.settings, drawables: drawables ?? _drawables, - background: background == _NoBackgroundPassedBackgroundDrawable.instance - ? this.background - : background, - selectedObjectDrawable: - selectedObjectDrawable == _NoObjectPassedBackgroundDrawable.instance - ? this.selectedObjectDrawable - : selectedObjectDrawable, + background: background == _NoBackgroundPassedBackgroundDrawable.instance ? this.background : background, + selectedObjectDrawable: selectedObjectDrawable == _NoObjectPassedBackgroundDrawable.instance + ? this.selectedObjectDrawable + : selectedObjectDrawable, ); } @@ -433,16 +417,15 @@ class PainterControllerValue { } @override - int get hashCode => hashValues( - hashList(_drawables), background, settings, selectedObjectDrawable); + @override + int get hashCode => Object.hash(Object.hashAll(_drawables), background, settings, selectedObjectDrawable); } /// Private class that is used internally to represent no /// [BackgroundDrawable] argument passed for [PainterControllerValue.copyWith]. class _NoBackgroundPassedBackgroundDrawable extends BackgroundDrawable { /// Single instance. - static const _NoBackgroundPassedBackgroundDrawable instance = - _NoBackgroundPassedBackgroundDrawable._(); + static const _NoBackgroundPassedBackgroundDrawable instance = _NoBackgroundPassedBackgroundDrawable._(); /// Private constructor. const _NoBackgroundPassedBackgroundDrawable._() : super(); @@ -459,8 +442,7 @@ class _NoBackgroundPassedBackgroundDrawable extends BackgroundDrawable { /// [BackgroundDrawable] argument passed for [PainterControllerValue.copyWith]. class _NoObjectPassedBackgroundDrawable extends ObjectDrawable { /// Single instance. - static const _NoObjectPassedBackgroundDrawable instance = - _NoObjectPassedBackgroundDrawable._(); + static const _NoObjectPassedBackgroundDrawable instance = _NoObjectPassedBackgroundDrawable._(); /// Private constructor. const _NoObjectPassedBackgroundDrawable._() @@ -470,12 +452,7 @@ class _NoObjectPassedBackgroundDrawable extends ObjectDrawable { @override ObjectDrawable copyWith( - {bool? hidden, - Set? assists, - ui.Offset? position, - double? rotation, - double? scale, - bool? locked}) { + {bool? hidden, Set? assists, ui.Offset? position, double? rotation, double? scale, bool? locked}) { throw UnimplementedError( "This object drawable is only to hold the default value in the PainterControllerValue copyWith method, and must not be used otherwise."); } diff --git a/lib/src/views/widgets/object_widget.dart b/lib/src/views/widgets/object_widget.dart index ac180c97..df4667b2 100644 --- a/lib/src/views/widgets/object_widget.dart +++ b/lib/src/views/widgets/object_widget.dart @@ -22,17 +22,7 @@ class _ObjectWidget extends StatefulWidget { } class _ObjectWidgetState extends State<_ObjectWidget> { - static Set assistAngles = { - 0, - pi / 4, - pi / 2, - 3 * pi / 4, - pi, - 5 * pi / 4, - 3 * pi / 2, - 7 * pi / 4, - 2 * pi - }; + static Set assistAngles = {0, pi / 4, pi / 2, 3 * pi / 4, pi, 5 * pi / 4, 3 * pi / 2, 7 * pi / 4, 2 * pi}; /// The last controller value in the widget tree. /// Updated by [didChangeDependencies] and used in [dispose]. @@ -45,12 +35,10 @@ class _ObjectWidgetState extends State<_ObjectWidget> { double get objectPadding => 25 / transformationScale; /// Getter for the duration of fade-in and out animations for the object controls. - static Duration get controlsTransitionDuration => - const Duration(milliseconds: 100); + static Duration get controlsTransitionDuration => const Duration(milliseconds: 100); /// Getter for the size of the controls of the selected object. - double get controlsSize => - (settings.enlargeControlsResolver() ? 20 : 10) / transformationScale; + double get controlsSize => (settings.enlargeControlsResolver() ? 20 : 10) / transformationScale; /// Getter for the blur radius of the selected object highlighting. double get selectedBlurRadius => 2 / transformationScale; @@ -72,27 +60,19 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// Keeps track of widgets that have assist lines assigned to them. /// /// This is used to provide haptic feedback when the assist line appears. - Map> assistDrawables = { - for (var e in ObjectDrawableAssist.values) e: {} - }; + Map> assistDrawables = {for (var e in ObjectDrawableAssist.values) e: {}}; /// Keeps track of which controls are being used. /// /// Used to highlight the controls when they are in use. - Map controlsAreActive = { - for (var e in List.generate(8, (index) => index)) e: false - }; + Map controlsAreActive = {for (var e in List.generate(8, (index) => index)) e: false}; /// Subscription to the events coming from the controller. StreamSubscription? controllerEventSubscription; /// Getter for the list of [ObjectDrawable]s in the controller /// to make code more readable. - List get drawables => PainterController.of(context) - .value - .drawables - .whereType() - .toList(); + List get drawables => PainterController.of(context).value.drawables.whereType().toList(); /// A flag on whether to cancel controls animation or not. /// This is used to cancel the animation after the selected object @@ -105,8 +85,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // Listen to the stream of events from the paint controller WidgetsBinding.instance?.addPostFrameCallback((timestamp) { - controllerEventSubscription = - PainterController.of(context).events.listen((event) { + controllerEventSubscription = PainterController.of(context).events.listen((event) { // When an [RemoveDrawableEvent] event is received and removed drawable is the selected object // cancel the animation. if (event is SelectedObjectDrawableRemovedEvent) { @@ -117,9 +96,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { }); // Listen to transformation changes of [InteractiveViewer]. - PainterController.of(context) - .transformationController - .addListener(onTransformUpdated); + PainterController.of(context).transformationController.addListener(onTransformUpdated); }); } @@ -143,9 +120,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { return LayoutBuilder(builder: (context, constraints) { return Stack( children: [ - Positioned.fill( - child: GestureDetector( - onTap: onBackgroundTapped, child: widget.child)), + Positioned.fill(child: GestureDetector(onTap: onBackgroundTapped, child: widget.child)), ...drawables.asMap().entries.map((entry) { final drawable = entry.value; final selected = drawable == controller?.selectedObjectDrawable; @@ -169,16 +144,12 @@ class _ObjectWidgetState extends State<_ObjectWidget> { child: freeStyleSettings.mode != FreeStyleMode.none ? widget : MouseRegion( - cursor: drawable.locked - ? MouseCursor.defer - : SystemMouseCursors.allScroll, + cursor: drawable.locked ? MouseCursor.defer : SystemMouseCursors.allScroll, child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () => tapDrawable(drawable), - onScaleStart: (details) => - onDrawableScaleStart(entry, details), - onScaleUpdate: (details) => - onDrawableScaleUpdate(entry, details), + onScaleStart: (details) => onDrawableScaleStart(entry, details), + onScaleUpdate: (details) => onDrawableScaleUpdate(entry, details), onScaleEnd: (_) => onDrawableScaleEnd(entry), child: AnimatedSwitcher( duration: controlsTransitionDuration, @@ -187,171 +158,108 @@ class _ObjectWidgetState extends State<_ObjectWidget> { children: [ widget, Positioned( - top: objectPadding - - (controlsSize / 2), - bottom: objectPadding - - (controlsSize / 2), - left: objectPadding - - (controlsSize / 2), - right: objectPadding - - (controlsSize / 2), + top: objectPadding - (controlsSize / 2), + bottom: objectPadding - (controlsSize / 2), + left: objectPadding - (controlsSize / 2), + right: objectPadding - (controlsSize / 2), child: Builder( builder: (context) { if (usingHtmlRenderer) { return Container( decoration: BoxDecoration( - border: Border.all( - color: Colors.black, - width: - selectedBorderWidth), + border: Border.all(color: Colors.black, width: selectedBorderWidth), ), child: Container( decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - width: - selectedBorderWidth), + border: Border.all(color: Colors.white, width: selectedBorderWidth), ), ), ); } return Container( decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - width: - selectedBorderWidth), + border: Border.all(color: Colors.white, width: selectedBorderWidth), boxShadow: [ BorderBoxShadow( color: Colors.black, - blurRadius: - selectedBlurRadius, + blurRadius: selectedBlurRadius, ) ]), ); }, ), ), - if (settings - .showScaleRotationControlsResolver()) ...[ + if (settings.showScaleRotationControlsResolver()) ...[ Positioned( top: objectPadding - (controlsSize), - left: - objectPadding - (controlsSize), + left: objectPadding - (controlsSize), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: SystemMouseCursors - .resizeUpLeft, + cursor: SystemMouseCursors.resizeUpLeft, child: GestureDetector( - onPanStart: (details) => - onScaleControlPanStart( - 0, entry, details), + onPanStart: (details) => onScaleControlPanStart(0, entry, details), onPanUpdate: (details) => - onScaleControlPanUpdate( - entry, - details, - constraints, - true), - onPanEnd: (details) => - onScaleControlPanEnd( - 0, entry, details), + onScaleControlPanUpdate(entry, details, constraints, true), + onPanEnd: (details) => onScaleControlPanEnd(0, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[0] ?? - false, + active: controlsAreActive[0] ?? false, ), ), ), ), Positioned( - bottom: - objectPadding - (controlsSize), - left: - objectPadding - (controlsSize), + bottom: objectPadding - (controlsSize), + left: objectPadding - (controlsSize), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: SystemMouseCursors - .resizeDownLeft, + cursor: SystemMouseCursors.resizeDownLeft, child: GestureDetector( - onPanStart: (details) => - onScaleControlPanStart( - 1, entry, details), + onPanStart: (details) => onScaleControlPanStart(1, entry, details), onPanUpdate: (details) => - onScaleControlPanUpdate( - entry, - details, - constraints, - true), - onPanEnd: (details) => - onScaleControlPanEnd( - 1, entry, details), + onScaleControlPanUpdate(entry, details, constraints, true), + onPanEnd: (details) => onScaleControlPanEnd(1, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[1] ?? - false, + active: controlsAreActive[1] ?? false, ), ), ), ), Positioned( top: objectPadding - (controlsSize), - right: - objectPadding - (controlsSize), + right: objectPadding - (controlsSize), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: initialScaleDrawables - .containsKey(entry.key) + cursor: initialScaleDrawables.containsKey(entry.key) ? SystemMouseCursors.grabbing : SystemMouseCursors.grab, child: GestureDetector( - onPanStart: (details) => - onRotationControlPanStart( - 2, entry, details), - onPanUpdate: (details) => - onRotationControlPanUpdate( - entry, details, size), - onPanEnd: (details) => - onRotationControlPanEnd( - 2, entry, details), + onPanStart: (details) => onRotationControlPanStart(2, entry, details), + onPanUpdate: (details) => onRotationControlPanUpdate(entry, details, size), + onPanEnd: (details) => onRotationControlPanEnd(2, entry, details), child: _ObjectControlBox( shape: BoxShape.circle, - active: - controlsAreActive[2] ?? - false, + active: controlsAreActive[2] ?? false, ), ), ), ), Positioned( - bottom: - objectPadding - (controlsSize), - right: - objectPadding - (controlsSize), + bottom: objectPadding - (controlsSize), + right: objectPadding - (controlsSize), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: SystemMouseCursors - .resizeDownRight, + cursor: SystemMouseCursors.resizeDownRight, child: GestureDetector( - onPanStart: (details) => - onScaleControlPanStart( - 3, entry, details), + onPanStart: (details) => onScaleControlPanStart(3, entry, details), onPanUpdate: (details) => - onScaleControlPanUpdate( - entry, - details, - constraints, - false), - onPanEnd: (details) => - onScaleControlPanEnd( - 3, entry, details), + onScaleControlPanUpdate(entry, details, constraints, false), + onPanEnd: (details) => onScaleControlPanEnd(3, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[3] ?? - false, + active: controlsAreActive[3] ?? false, ), ), ), @@ -360,131 +268,72 @@ class _ObjectWidgetState extends State<_ObjectWidget> { if (entry.value is Sized2DDrawable) ...[ Positioned( top: objectPadding - (controlsSize), - left: (size.width / 2) + - objectPadding - - (controlsSize / 2), + left: (size.width / 2) + objectPadding - (controlsSize / 2), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: - SystemMouseCursors.resizeUp, + cursor: SystemMouseCursors.resizeUp, child: GestureDetector( - onPanStart: (details) => - onResizeControlPanStart( - 4, entry, details), + onPanStart: (details) => onResizeControlPanStart(4, entry, details), onPanUpdate: (details) => - onResizeControlPanUpdate( - entry, - details, - constraints, - Axis.vertical, - true), - onPanEnd: (details) => - onResizeControlPanEnd( - 4, entry, details), + onResizeControlPanUpdate(entry, details, constraints, Axis.vertical, true), + onPanEnd: (details) => onResizeControlPanEnd(4, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[4] ?? - false, + active: controlsAreActive[4] ?? false, ), ), ), ), Positioned( - bottom: - objectPadding - (controlsSize), - left: (size.width / 2) + - objectPadding - - (controlsSize / 2), + bottom: objectPadding - (controlsSize), + left: (size.width / 2) + objectPadding - (controlsSize / 2), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: - SystemMouseCursors.resizeDown, + cursor: SystemMouseCursors.resizeDown, child: GestureDetector( - onPanStart: (details) => - onResizeControlPanStart( - 5, entry, details), + onPanStart: (details) => onResizeControlPanStart(5, entry, details), onPanUpdate: (details) => - onResizeControlPanUpdate( - entry, - details, - constraints, - Axis.vertical, - false), - onPanEnd: (details) => - onResizeControlPanEnd( - 5, entry, details), + onResizeControlPanUpdate(entry, details, constraints, Axis.vertical, false), + onPanEnd: (details) => onResizeControlPanEnd(5, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[5] ?? - false, + active: controlsAreActive[5] ?? false, ), ), ), ), Positioned( - left: - objectPadding - (controlsSize), - top: (size.height / 2) + - objectPadding - - (controlsSize / 2), + left: objectPadding - (controlsSize), + top: (size.height / 2) + objectPadding - (controlsSize / 2), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: - SystemMouseCursors.resizeLeft, + cursor: SystemMouseCursors.resizeLeft, child: GestureDetector( - onPanStart: (details) => - onResizeControlPanStart( - 6, entry, details), + onPanStart: (details) => onResizeControlPanStart(6, entry, details), onPanUpdate: (details) => - onResizeControlPanUpdate( - entry, - details, - constraints, - Axis.horizontal, - true), - onPanEnd: (details) => - onResizeControlPanEnd( - 6, entry, details), + onResizeControlPanUpdate(entry, details, constraints, Axis.horizontal, true), + onPanEnd: (details) => onResizeControlPanEnd(6, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[6] ?? - false, + active: controlsAreActive[6] ?? false, ), ), ), ), Positioned( - right: - objectPadding - (controlsSize), - top: (size.height / 2) + - objectPadding - - (controlsSize / 2), + right: objectPadding - (controlsSize), + top: (size.height / 2) + objectPadding - (controlsSize / 2), width: controlsSize, height: controlsSize, child: MouseRegion( - cursor: SystemMouseCursors - .resizeRight, + cursor: SystemMouseCursors.resizeRight, child: GestureDetector( - onPanStart: (details) => - onResizeControlPanStart( - 7, entry, details), + onPanStart: (details) => onResizeControlPanStart(7, entry, details), onPanUpdate: (details) => - onResizeControlPanUpdate( - entry, - details, - constraints, - Axis.horizontal, - false), - onPanEnd: (details) => - onResizeControlPanEnd( - 7, entry, details), + onResizeControlPanUpdate(entry, details, constraints, Axis.horizontal, false), + onPanEnd: (details) => onResizeControlPanEnd(7, entry, details), child: _ObjectControlBox( - active: - controlsAreActive[7] ?? - false, + active: controlsAreActive[7] ?? false, ), ), ), @@ -504,8 +353,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { cancelControlsAnimation = false; return child ?? const SizedBox(); } - return AnimatedSwitcher.defaultLayoutBuilder( - child, previousChildren); + return AnimatedSwitcher.defaultLayoutBuilder(child, previousChildren); }, ), ), @@ -542,15 +390,13 @@ class _ObjectWidgetState extends State<_ObjectWidget> { } /// Getter for the [ObjectSettings] from the controller to make code more readable. - ObjectSettings get settings => - PainterController.of(context).value.settings.object; + ObjectSettings get settings => PainterController.of(context).value.settings.object; /// Getter for the [FreeStyleSettings] from the controller to make code more readable. /// /// This is used to disable object movement, scaling and rotation /// when free-style drawing is enabled. - FreeStyleSettings get freeStyleSettings => - PainterController.of(context).value.settings.freeStyle; + FreeStyleSettings get freeStyleSettings => PainterController.of(context).value.settings.freeStyle; /// Triggers when the user taps an empty space. /// @@ -585,8 +431,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// Callback when the object drawable starts being moved, scaled and/or rotated. /// /// Saves the initial point of interaction and drawable to be used on update events. - void onDrawableScaleStart( - MapEntry entry, ScaleStartDetails details) { + void onDrawableScaleStart(MapEntry entry, ScaleStartDetails details) { if (!widget.interactionEnabled) return; final index = entry.key; @@ -608,8 +453,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { final rotateOffset = Matrix4.rotationZ(drawable.rotationAngle) ..translate(details.localFocalPoint.dx, details.localFocalPoint.dy) ..rotateZ(-drawable.rotationAngle); - drawableInitialLocalFocalPoints[index] = - Offset(rotateOffset[12], rotateOffset[13]); + drawableInitialLocalFocalPoints[index] = Offset(rotateOffset[12], rotateOffset[13]); updateDrawable(drawable, drawable, newAction: true); } @@ -646,8 +490,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// Callback when the object drawable is moved, scaled and/or rotated. /// /// Calculates the next position, scale and rotation of the object depending on the event details. - void onDrawableScaleUpdate( - MapEntry entry, ScaleUpdateDetails details) { + void onDrawableScaleUpdate(MapEntry entry, ScaleUpdateDetails details) { if (!widget.interactionEnabled) return; final index = entry.key; @@ -659,8 +502,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // This causes events from rotated objects to behave incorrectly // So, a [Matrix4] is used to transform the needed event details to be consistent with // the current rotation of the object - final initialLocalFocalPoint = - drawableInitialLocalFocalPoints[index] ?? Offset.zero; + final initialLocalFocalPoint = drawableInitialLocalFocalPoints[index] ?? Offset.zero; if (initialDrawable == null) return; @@ -675,8 +517,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { ..rotateZ(initialRotation) ..translate(details.localFocalPoint.dx, details.localFocalPoint.dy) ..rotateZ(-initialRotation); - final position = - initialPosition + Offset(rotateOffset[12], rotateOffset[13]); + final position = initialPosition + Offset(rotateOffset[12], rotateOffset[13]); // Calculate scale of object reference to the initial object scale final scale = initialDrawable.scale * details.scale; @@ -712,10 +553,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // The set of assists for the object // If layout assist is disabled, it is empty final assists = settings.layoutAssist.enabled - ? assistDrawables.entries - .where((element) => element.value.contains(index)) - .map((e) => e.key) - .toSet() + ? assistDrawables.entries.where((element) => element.value.contains(index)).map((e) => e.key).toSet() : {}; // Do not display the rotational assist if the user is using less that 2 pointers @@ -726,15 +564,12 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // and layout assist is enabled final assistedPosition = Offset( assists.contains(ObjectDrawableAssist.vertical) ? center.dx : position.dx, - assists.contains(ObjectDrawableAssist.horizontal) - ? center.dy - : position.dy, + assists.contains(ObjectDrawableAssist.horizontal) ? center.dy : position.dy, ); // Snap the object rotation to the nearest angle from [assistAngles] if its near it // and layout assist is enabled - final assistedRotation = assists.contains(ObjectDrawableAssist.rotation) && - closestAssistAngle != null + final assistedRotation = assists.contains(ObjectDrawableAssist.rotation) && closestAssistAngle != null ? closestAssistAngle.remainder(pi * 2) : rotation; @@ -749,24 +584,20 @@ class _ObjectWidgetState extends State<_ObjectWidget> { } /// Calculates whether the object entered or exited the horizontal and vertical assist areas. - void calculatePositionalAssists(ObjectLayoutAssistSettings settings, - int index, Offset position, Offset center) { + void calculatePositionalAssists(ObjectLayoutAssistSettings settings, int index, Offset position, Offset center) { // Horizontal // // If the object is within the enter distance from the center dy and isn't marked // as a drawable with a horizontal assist, mark it if ((position.dy - center.dy).abs() < settings.positionalEnterDistance && - !(assistDrawables[ObjectDrawableAssist.horizontal]?.contains(index) ?? - false)) { + !(assistDrawables[ObjectDrawableAssist.horizontal]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.horizontal]?.add(index); settings.hapticFeedback.impact(); } // Otherwise, if the object is outside the exit distance from the center dy and is marked as // as a drawable with a horizontal assist, un-mark it - else if ((position.dy - center.dy).abs() > - settings.positionalExitDistance && - (assistDrawables[ObjectDrawableAssist.horizontal]?.contains(index) ?? - false)) { + else if ((position.dy - center.dy).abs() > settings.positionalExitDistance && + (assistDrawables[ObjectDrawableAssist.horizontal]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.horizontal]?.remove(index); } @@ -775,17 +606,14 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // If the object is within the enter distance from the center dx and isn't marked // as a drawable with a vertical assist, mark it if ((position.dx - center.dx).abs() < settings.positionalEnterDistance && - !(assistDrawables[ObjectDrawableAssist.vertical]?.contains(index) ?? - false)) { + !(assistDrawables[ObjectDrawableAssist.vertical]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.vertical]?.add(index); settings.hapticFeedback.impact(); } // Otherwise, if the object is outside the exit distance from the center dx and is marked as // as a drawable with a vertical assist, un-mark it - else if ((position.dx - center.dx).abs() > - settings.positionalExitDistance && - (assistDrawables[ObjectDrawableAssist.vertical]?.contains(index) ?? - false)) { + else if ((position.dx - center.dx).abs() > settings.positionalExitDistance && + (assistDrawables[ObjectDrawableAssist.vertical]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.vertical]?.remove(index); } } @@ -793,22 +621,16 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// Calculates whether the object entered or exited the rotational assist range. /// /// Returns the angle the object is closest to if it is inside the assist range. - double? calculateRotationalAssist( - ObjectLayoutAssistSettings settings, int index, double rotation) { + double? calculateRotationalAssist(ObjectLayoutAssistSettings settings, int index, double rotation) { // Calculates all angles from [assistAngles] in the exit range of rotational assist - final closeAngles = assistAngles - .where( - (angle) => (rotation - angle).abs() < settings.rotationalExitAngle) - .toList(); + final closeAngles = assistAngles.where((angle) => (rotation - angle).abs() < settings.rotationalExitAngle).toList(); // If the object is close to at least one assist angle if (closeAngles.isNotEmpty) { // If the object is also in the enter range of rotational assist and isn't marked // as a drawable with a rotational assist, mark it - if (closeAngles.any((angle) => - (rotation - angle).abs() < settings.rotationalEnterAngle) && - !(assistDrawables[ObjectDrawableAssist.rotation]?.contains(index) ?? - false)) { + if (closeAngles.any((angle) => (rotation - angle).abs() < settings.rotationalEnterAngle) && + !(assistDrawables[ObjectDrawableAssist.rotation]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.rotation]?.add(index); settings.hapticFeedback.impact(); } @@ -818,9 +640,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { // Otherwise, if the object is not in the exit range of any assist angles, // but is marked as a drawable with rotational assist, un-mark it - if (closeAngles.isEmpty && - (assistDrawables[ObjectDrawableAssist.rotation]?.contains(index) ?? - false)) { + if (closeAngles.isEmpty && (assistDrawables[ObjectDrawableAssist.rotation]?.contains(index) ?? false)) { assistDrawables[ObjectDrawableAssist.rotation]?.remove(index); } @@ -831,10 +651,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// /// Uses the [GlobalKey] for the painter from [controller]. Offset get center { - final renderBox = PainterController.of(context) - .painterKey - .currentContext - ?.findRenderObject() as RenderBox?; + final renderBox = PainterController.of(context).painterKey.currentContext?.findRenderObject() as RenderBox?; final center = renderBox == null ? Offset.zero : Offset( @@ -845,16 +662,13 @@ class _ObjectWidgetState extends State<_ObjectWidget> { } /// Replaces a drawable with a new one. - void updateDrawable(ObjectDrawable oldDrawable, ObjectDrawable newDrawable, - {bool newAction = false}) { + void updateDrawable(ObjectDrawable oldDrawable, ObjectDrawable newDrawable, {bool newAction = false}) { setState(() { - PainterController.of(context) - .replaceDrawable(oldDrawable, newDrawable, newAction: newAction); + PainterController.of(context).replaceDrawable(oldDrawable, newDrawable, newAction: newAction); }); } - void onRotationControlPanStart(int controlIndex, - MapEntry entry, DragStartDetails details) { + void onRotationControlPanStart(int controlIndex, MapEntry entry, DragStartDetails details) { setState(() { controlsAreActive[controlIndex] = true; }); @@ -866,15 +680,13 @@ class _ObjectWidgetState extends State<_ObjectWidget> { )); } - void onRotationControlPanUpdate(MapEntry entry, - DragUpdateDetails details, Size size) { + void onRotationControlPanUpdate(MapEntry entry, DragUpdateDetails details, Size size) { final index = entry.key; final initial = initialScaleDrawables[index]; if (initial == null) return; final initialOffset = Offset((size.width / 2), (-size.height / 2)); final initialAngle = atan2(initialOffset.dx, initialOffset.dy); - final angle = atan2((details.localPosition.dx + initialOffset.dx), - (details.localPosition.dy + initialOffset.dy)); + final angle = atan2((details.localPosition.dx + initialOffset.dx), (details.localPosition.dy + initialOffset.dy)); final rotation = initialAngle - angle; onDrawableScaleUpdate( entry, @@ -886,16 +698,14 @@ class _ObjectWidgetState extends State<_ObjectWidget> { )); } - void onRotationControlPanEnd(int controlIndex, - MapEntry entry, DragEndDetails details) { + void onRotationControlPanEnd(int controlIndex, MapEntry entry, DragEndDetails details) { setState(() { controlsAreActive[controlIndex] = false; }); onDrawableScaleEnd(entry); } - void onScaleControlPanStart(int controlIndex, - MapEntry entry, DragStartDetails details) { + void onScaleControlPanStart(int controlIndex, MapEntry entry, DragStartDetails details) { setState(() { controlsAreActive[controlIndex] = true; }); @@ -907,8 +717,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { )); } - void onScaleControlPanUpdate(MapEntry entry, - DragUpdateDetails details, BoxConstraints constraints, + void onScaleControlPanUpdate(MapEntry entry, DragUpdateDetails details, BoxConstraints constraints, [bool isReversed = true]) { final index = entry.key; final initial = initialScaleDrawables[index]; @@ -916,9 +725,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { final length = details.localPosition.dx * (isReversed ? -1 : 1); final initialSize = initial.getSize(maxWidth: constraints.maxWidth); final initialLength = initialSize.width / 2; - final double scale = initialLength == 0 - ? (length * 2) - : ((length + initialLength) / initialLength); + final double scale = initialLength == 0 ? (length * 2) : ((length + initialLength) / initialLength); onDrawableScaleUpdate( entry, ScaleUpdateDetails( @@ -929,16 +736,14 @@ class _ObjectWidgetState extends State<_ObjectWidget> { )); } - void onScaleControlPanEnd(int controlIndex, - MapEntry entry, DragEndDetails details) { + void onScaleControlPanEnd(int controlIndex, MapEntry entry, DragEndDetails details) { setState(() { controlsAreActive[controlIndex] = false; }); onDrawableScaleEnd(entry); } - void onResizeControlPanStart(int controlIndex, - MapEntry entry, DragStartDetails details) { + void onResizeControlPanStart(int controlIndex, MapEntry entry, DragStartDetails details) { setState(() { controlsAreActive[controlIndex] = true; }); @@ -950,8 +755,8 @@ class _ObjectWidgetState extends State<_ObjectWidget> { )); } - void onResizeControlPanUpdate(MapEntry entry, - DragUpdateDetails details, BoxConstraints constraints, Axis axis, + void onResizeControlPanUpdate( + MapEntry entry, DragUpdateDetails details, BoxConstraints constraints, Axis axis, [bool isReversed = true]) { final index = entry.key; @@ -964,13 +769,10 @@ class _ObjectWidgetState extends State<_ObjectWidget> { if (initial == null) return; final vertical = axis == Axis.vertical; - final length = - ((vertical ? details.localPosition.dy : details.localPosition.dx) * - (isReversed ? -1 : 1)); + final length = ((vertical ? details.localPosition.dy : details.localPosition.dx) * (isReversed ? -1 : 1)); final initialLength = vertical ? initial.size.height : initial.size.width; - final totalLength = (length / initial.scale + initialLength) - .clamp(0, double.infinity) as double; + final totalLength = (length / initial.scale + initialLength).clamp(0, double.infinity) as double; // final double scale = initialLength == 0 ? // (length*2).clamp(0.001, double.infinity) : @@ -1006,8 +808,7 @@ class _ObjectWidgetState extends State<_ObjectWidget> { updateDrawable(drawable, newDrawable); } - void onResizeControlPanEnd(int controlIndex, - MapEntry entry, DragEndDetails details) { + void onResizeControlPanEnd(int controlIndex, MapEntry entry, DragEndDetails details) { setState(() { controlsAreActive[controlIndex] = false; }); @@ -1017,11 +818,9 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// A callback that is called when a transformation occurs in the [InteractiveViewer] in the widget tree. void onTransformUpdated() { setState(() { - final _m4storage = - PainterController.of(context).transformationController.value; - transformationScale = math.sqrt(_m4storage[8] * _m4storage[8] + - _m4storage[9] * _m4storage[9] + - _m4storage[10] * _m4storage[10]); + final _m4storage = PainterController.of(context).transformationController.value; + transformationScale = + math.sqrt(_m4storage[8] * _m4storage[8] + _m4storage[9] * _m4storage[9] + _m4storage[10] * _m4storage[10]); }); } } @@ -1062,7 +861,7 @@ class _ObjectControlBox extends StatelessWidget { Widget build(BuildContext context) { ThemeData? theme = Theme.of(context); if (theme == ThemeData.fallback()) theme = null; - final activeColor = this.activeColor ?? theme?.accentColor ?? Colors.blue; + final activeColor = this.activeColor ?? theme?.scaffoldBackgroundColor ?? Colors.blue; return AnimatedContainer( duration: _ObjectWidgetState.controlsTransitionDuration, decoration: BoxDecoration(