Skip to content

Commit

Permalink
add multi highlight example
Browse files Browse the repository at this point in the history
  • Loading branch information
BakerJQ committed Oct 14, 2020
1 parent a297865 commit f75b86e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions example/lib/guide_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class _GuidePopupState extends State<GuidePopup> {
return 'Click here to show dropdown menu.';
case 1:
return 'Click here to show guide.';
case 2:
return 'Click here to show multi highlight guide.';
}
return '';
}
Expand Down
49 changes: 46 additions & 3 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class Home extends StatefulWidget {
}

class _HomeState extends State<Home> {
GlobalKey key1 = new GlobalKey(), key2 = new GlobalKey();
GlobalKey key1 = new GlobalKey(),
key2 = new GlobalKey(),
key3 = new GlobalKey();

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,7 +53,22 @@ class _HomeState extends State<Home> {
color: Colors.blueAccent,
alignment: Alignment.center,
child: Text(
'ShowHighLightPopup',
'ShowGuidePopup',
style: TextStyle(color: Colors.white),
),
),
),
GestureDetector(
key: key3,
behavior: HitTestBehavior.opaque,
onTap: _showMultiHighlightsGuidePopup,
child: Container(
width: 200,
height: 50,
color: Colors.blueAccent,
alignment: Alignment.center,
child: Text(
'ShowMultiHighlightPopup',
style: TextStyle(color: Colors.white),
),
),
Expand Down Expand Up @@ -82,7 +99,33 @@ class _HomeState extends State<Home> {
];
EasyPopup.show(
context,
GuidePopup([key1, key2]),
GuidePopup([key1, key2, key3]),
cancelable: false,
highlights: highlights,
duration: Duration(milliseconds: 100),
);
}

_showMultiHighlightsGuidePopup() {
List<GlobalKey> keys = [key1, key2, key3];
List<RRect> highlights = [];
for (GlobalKey key in keys) {
RenderBox box = key.currentContext.findRenderObject();
Offset offset = box.localToGlobal(Offset.zero);
double left = offset.dx - 5;
double top = offset.dy - 5;
double width = box.size.width + 10;
double height = box.size.height + 10;
highlights.add(
RRect.fromRectAndRadius(
Rect.fromLTWH(left, top, width, height),
Radius.circular(10),
),
);
}
EasyPopup.show(
context,
GuidePopup([key1]),
cancelable: false,
highlights: highlights,
duration: Duration(milliseconds: 100),
Expand Down

0 comments on commit f75b86e

Please sign in to comment.