From c9958c68e9811aa2181b1be8998524aef63e6351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonc=CC=A7alo=20Palma?= Date: Wed, 17 Jul 2019 10:06:25 +0100 Subject: [PATCH] Changed the way the offset is calculated in function on the shape of the target Fix for #6 --- .gitignore | 6 ++++ example/pubspec.lock | 2 +- lib/tutorial_coach_mark_widget.dart | 47 +++++++++++++++++------------ pubspec.lock | 14 ++++----- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 446ed0d..c0d88dd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,9 @@ build/ ios/.generated/ ios/Flutter/Generated.xcconfig ios/Runner/GeneratedPluginRegistrant.* + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ diff --git a/example/pubspec.lock b/example/pubspec.lock index aac2f1d..7da0c74 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -127,7 +127,7 @@ packages: path: ".." relative: true source: path - version: "0.1.1" + version: "0.2.0" typed_data: dependency: transitive description: diff --git a/lib/tutorial_coach_mark_widget.dart b/lib/tutorial_coach_mark_widget.dart index d20d500..53c6cda 100644 --- a/lib/tutorial_coach_mark_widget.dart +++ b/lib/tutorial_coach_mark_widget.dart @@ -19,15 +19,15 @@ class TutorialCoachMarkWidget extends StatefulWidget { final String textSkip; const TutorialCoachMarkWidget( {Key key, - this.targets, - this.finish, - this.paddingFocus = 10, - this.clickTarget, - this.alignSkip = Alignment.bottomRight, - this.textSkip = "SKIP", - this.clickSkip, - this.colorShadow = Colors.black, - this.opacityShadow = 0.8}) + this.targets, + this.finish, + this.paddingFocus = 10, + this.clickTarget, + this.alignSkip = Alignment.bottomRight, + this.textSkip = "SKIP", + this.clickSkip, + this.colorShadow = Colors.black, + this.opacityShadow = 0.8}) : super(key: key); @override @@ -100,10 +100,19 @@ class _TutorialCoachMarkWidgetState extends State { TargetPosition target = getTargetCurrent(currentTarget); var positioned = Offset(target.offset.dx + target.size.width / 2, target.offset.dy + target.size.height / 2); - var sizeCircle = target.size.width > target.size.height - ? target.size.width - : target.size.height; - sizeCircle = sizeCircle * 0.6 + widget.paddingFocus; + double haloWidth; + double haloHeight; + if (currentTarget.shape == ShapeLightFocus.Circle) { + haloWidth = target.size.width > target.size.height + ? target.size.width + : target.size.height; + haloHeight = haloWidth; + } else { + haloWidth = target.size.width; + haloHeight = target.size.height; + } + haloWidth = haloWidth * 0.6 + widget.paddingFocus; + haloHeight = haloHeight * 0.6 + widget.paddingFocus; double weight = 0.0; double top; @@ -116,7 +125,7 @@ class _TutorialCoachMarkWidgetState extends State { { weight = MediaQuery.of(context).size.width; left = 0; - top = positioned.dy + sizeCircle; + top = positioned.dy + haloHeight; bottom = null; } break; @@ -125,22 +134,22 @@ class _TutorialCoachMarkWidgetState extends State { weight = MediaQuery.of(context).size.width; left = 0; top = null; - bottom = sizeCircle + + bottom = haloHeight + (MediaQuery.of(context).size.height - positioned.dy); } break; case AlignContent.left: { - weight = positioned.dx - sizeCircle; + weight = positioned.dx - haloWidth; left = 0; - top = positioned.dy - target.size.height / 2 - sizeCircle; + top = positioned.dy - target.size.height / 2 - haloHeight; bottom = null; } break; case AlignContent.right: { - left = positioned.dx + sizeCircle; - top = positioned.dy - target.size.height / 2 - sizeCircle; + left = positioned.dx + haloWidth; + top = positioned.dy - target.size.height / 2 - haloHeight; bottom = null; weight = MediaQuery.of(context).size.width - left; } diff --git a/pubspec.lock b/pubspec.lock index a1e8431..484030c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,5 +1,5 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -66,14 +66,14 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.8.0+1" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -120,7 +120,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.4" + version: "0.2.5" typed_data: dependency: transitive description: @@ -136,4 +136,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.0 <3.0.0" + dart: ">=2.2.2 <3.0.0"