Skip to content

Commit

Permalink
✨ add overlay padding
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsaltanna authored and BirjuVachhani committed Jun 1, 2021
1 parent b47e695 commit 166a8cb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 31 deletions.
Binary file modified example/assets/simform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ShowCaseWidget(
onStart: (index, key) {
Expand Down Expand Up @@ -56,6 +57,7 @@ class _MailPageState extends State<MailPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SafeArea(
child: ListView(
children: <Widget>[
Expand Down Expand Up @@ -98,6 +100,7 @@ class _MailPageState extends State<MailPage> {
),
),
Showcase(
overlayPadding: EdgeInsets.all(5),
key: _two,
title: 'Profile',
description:
Expand Down
29 changes: 20 additions & 9 deletions lib/src/get_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ import 'package:flutter/material.dart';

class GetPosition {
final GlobalKey? key;
final EdgeInsets padding;
final double? screenWidth;
final double? screenHeight;

GetPosition({this.key});
GetPosition(
{this.key,
this.padding = EdgeInsets.zero,
this.screenWidth,
this.screenHeight});

Rect getRect() {
final box = key!.currentContext!.findRenderObject() as RenderBox;
Expand All @@ -40,10 +47,14 @@ class GetPosition {
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));

final rect = Rect.fromLTRB(
topLeft.dx,
topLeft.dy,
bottomRight.dx,
bottomRight.dy,
topLeft.dx - padding.left < 0 ? 0 : topLeft.dx - padding.left,
topLeft.dy - padding.top < 0 ? 0 : topLeft.dy - padding.top,
bottomRight.dx + padding.right > screenWidth!
? screenWidth!
: bottomRight.dx + padding.right,
bottomRight.dy + padding.bottom > screenHeight!
? screenHeight!
: bottomRight.dy + padding.bottom,
);
return rect;
}
Expand All @@ -53,29 +64,29 @@ class GetPosition {
final box = key!.currentContext!.findRenderObject() as RenderBox;
final bottomRight =
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
return bottomRight.dy;
return bottomRight.dy + padding.bottom;
}

///Get the top position of the widget
double getTop() {
final box = key!.currentContext!.findRenderObject() as RenderBox;
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
return topLeft.dy;
return topLeft.dy - padding.top;
}

///Get the left position of the widget
double getLeft() {
final box = key!.currentContext!.findRenderObject() as RenderBox;
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
return topLeft.dx;
return topLeft.dx - padding.left;
}

///Get the right position of the widget
double getRight() {
final box = key!.currentContext!.findRenderObject() as RenderBox;
final bottomRight =
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
return bottomRight.dx;
return bottomRight.dx + padding.right;
}

double getHeight() {
Expand Down
51 changes: 29 additions & 22 deletions lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,29 @@ class Showcase extends StatefulWidget {
final VoidCallback? onTargetClick;
final bool? disposeOnTap;
final bool disableAnimation;
final EdgeInsets overlayPadding;

const Showcase({
required this.key,
required this.child,
this.title,
required this.description,
this.shapeBorder,
this.overlayColor = Colors.black,
this.overlayOpacity = 0.75,
this.titleTextStyle,
this.descTextStyle,
this.showcaseBackgroundColor = Colors.white,
this.textColor = Colors.black,
this.showArrow = true,
this.onTargetClick,
this.disposeOnTap,
this.animationDuration = const Duration(milliseconds: 2000),
this.disableAnimation = false,
this.contentPadding = const EdgeInsets.symmetric(vertical: 8),
this.onToolTipClick,
}) : height = null,
const Showcase(
{required this.key,
required this.child,
this.title,
required this.description,
this.shapeBorder,
this.overlayColor = Colors.black,
this.overlayOpacity = 0.75,
this.titleTextStyle,
this.descTextStyle,
this.showcaseBackgroundColor = Colors.white,
this.textColor = Colors.black,
this.showArrow = true,
this.onTargetClick,
this.disposeOnTap,
this.animationDuration = const Duration(milliseconds: 2000),
this.disableAnimation = false,
this.contentPadding = const EdgeInsets.symmetric(vertical: 8),
this.onToolTipClick,
this.overlayPadding = EdgeInsets.zero})
: height = null,
width = null,
container = null,
assert(overlayOpacity >= 0.0 && overlayOpacity <= 1.0,
Expand Down Expand Up @@ -116,6 +118,7 @@ class Showcase extends StatefulWidget {
this.animationDuration = const Duration(milliseconds: 2000),
this.disableAnimation = false,
this.contentPadding = const EdgeInsets.symmetric(vertical: 8),
this.overlayPadding = EdgeInsets.zero,
}) : showArrow = false,
onToolTipClick = null,
assert(overlayOpacity >= 0.0 && overlayOpacity <= 1.0,
Expand Down Expand Up @@ -154,8 +157,6 @@ class _ShowcaseState extends State<Showcase> with TickerProviderStateMixin {
parent: _slideAnimationController,
curve: Curves.easeInOut,
);

position = GetPosition(key: widget.key);
}

@override
Expand All @@ -167,6 +168,12 @@ class _ShowcaseState extends State<Showcase> with TickerProviderStateMixin {
@override
void didChangeDependencies() {
super.didChangeDependencies();
position ??= GetPosition(
key: widget.key,
padding: widget.overlayPadding,
screenWidth: MediaQuery.of(context).size.width,
screenHeight: MediaQuery.of(context).size.height,
);
showOverlay();
}

Expand Down

0 comments on commit 166a8cb

Please sign in to comment.