Skip to content

Commit

Permalink
* Added animation when dismissing #6
Browse files Browse the repository at this point in the history
* Fix borderWidth=0 not honoured #7
* Added [hideOnTooltipTap] capability, requested #5
* Updated README
* Other fixes
  • Loading branch information
victorevox committed May 9, 2020
1 parent d7454ae commit 5ebe6f0
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 203 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [0.1.7] - 9/05/20.

* Added animation when dismissing https://github.com/victorevox/simple_tooltp/issues/6
* Fix borderWidth=0 not honoured https://github.com/victorevox/simple_tooltp/issues/7
* Added [hideOnTooltipTap] capability, requested https://github.com/victorevox/simple_tooltp/issues/5
* Updated README
* Other fixes

## [0.1.6] - 9/05/20.

* Ensure tooltip is hidden when dispossing (fix: https://github.com/victorevox/simple_tooltp/issues/9)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,16 @@ SimpleTooltip(
/// defaults to `const BoxShadow(color: const Color(0x45222222), blurRadius: 8, spreadRadius: 2),`
final List<BoxShadow> customShadows;
///
/// Set a handler for listening to a `tap` event on the tooltip (This is the recommended way to put your logic for dismissing the tooltip)
final Function() tooltipTap;
///
/// If you want to automatically dismiss the tooltip whenever a user taps on it, set this flag to [true]
/// For more control on when to dismiss the tooltip please rely on the [show] property and [tooltipTap] handler
/// defaults to [false]
final bool hideOnTooltipTap;
```

## Screenshots
Expand Down
153 changes: 153 additions & 0 deletions example/lib/animated_example_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:simple_tooltip/simple_tooltip.dart';

class AnimatedExamplePage extends StatefulWidget {
AnimatedExamplePage({Key key, this.title}) : super(key: key);

final String title;

@override
_AnimatedExamplePageState createState() => _AnimatedExamplePageState();
}

class _AnimatedExamplePageState extends State<AnimatedExamplePage> {
AnimationStatus _marginAnimationStatus;

int _restartCount = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MarginTransition(
animationStatusChange: (status) {
setState(() {
_marginAnimationStatus = status;
if (status == AnimationStatus.forward) {
_restartCount++;
}
if (_restartCount > 4) {
_restartCount = 0;
}
});
},
child: Container(
width: 280,
height: 120,
child: Placeholder(),
),
builder: (context, margin, child) {
// print(_marginAnimationStatus);
return Container(
margin: _marginAnimationStatus == AnimationStatus.forward
? EdgeInsets.only(left: margin)
: EdgeInsets.only(right: margin),
child: SimpleTooltip(
tooltipTap: () {
print("tooltip tap ${Random().nextDouble()}");
},
backgroundColor:
_marginAnimationStatus == AnimationStatus.forward
? Colors.white
: Colors.blue[300],
borderColor:
_marginAnimationStatus == AnimationStatus.forward
? Colors.purple
: Colors.orange,
show: true,
arrowTipDistance: 10,
tooltipDirection: _restartCount > 2
? _marginAnimationStatus == AnimationStatus.reverse
? TooltipDirection.up
: TooltipDirection.down
: _marginAnimationStatus == AnimationStatus.reverse
? TooltipDirection.right
: TooltipDirection.left,
child: child,
content: Text(
"Some text example!!!!",
style: TextStyle(
color: Colors.black,
fontSize: 18,
decoration: TextDecoration.none,
),
),
),
);
},
),
],
),
),
);
}
}

class MarginTransition extends StatefulWidget {
final Widget child;
final Widget Function(BuildContext, double margin, Widget child) builder;
final ValueChanged<AnimationStatus> animationStatusChange;

MarginTransition({
Key key,
@required this.child,
@required this.builder,
this.animationStatusChange,
}) : assert(builder != null),
super(key: key);

@override
_MarginTransitionState createState() => _MarginTransitionState();
}

class _MarginTransitionState extends State<MarginTransition>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation<double> _animation;

@override
void initState() {
super.initState();
_animationController =
AnimationController(vsync: this, duration: Duration(seconds: 4));
_animationController.forward();
_animation =
Tween<double>(begin: 10, end: 300).animate(_animationController)
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_animationController.reverse();
} else if (status == AnimationStatus.dismissed) {
_animationController.forward();
}

if (widget.animationStatusChange != null) {
widget.animationStatusChange(_animationController.status);
}
});
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animation,
child: widget.child,
builder: (context, child) {
return widget.builder(context, _animation.value, child);
},
);
}

@override
void dispose() {
_animationController.dispose();
super.dispose();
}
}
90 changes: 90 additions & 0 deletions example/lib/basics_example_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import 'package:simple_tooltip/simple_tooltip.dart';

class BasicsExamplePage extends StatefulWidget {
const BasicsExamplePage({Key key}) : super(key: key);

@override
_BasicsExamplePageState createState() => _BasicsExamplePageState();
}

class _BasicsExamplePageState extends State<BasicsExamplePage> {
bool _show = false;
bool hideOnTap = false;
TooltipDirection _direction = TooltipDirection.up;
bool _changeBorder = false;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Basics"),
),
body: Center(
child: Container(
child: Column(
children: <Widget>[
RaisedButton(
child: Text("change direction"),
onPressed: () {
setState(() {
switch (_direction) {
case TooltipDirection.up:
_direction = TooltipDirection.right;
break;
case TooltipDirection.right:
_direction = TooltipDirection.down;
break;
case TooltipDirection.down:
_direction = TooltipDirection.left;
break;
case TooltipDirection.left:
_direction = TooltipDirection.up;
break;
default:
}
});
},
),
RaisedButton(
child: Text("toogle: $_show"),
onPressed: () {
setState(() {
_show = !_show;
});
},
),
RaisedButton(
child: Text("hideOnTap: $hideOnTap"),
onPressed: () {
setState(() {
hideOnTap = !hideOnTap;
});
},
),
RaisedButton(
child: Text("change border: $hideOnTap"),
onPressed: () {
setState(() {
_changeBorder = !_changeBorder;
});
},
),
SimpleTooltip(
show: _show,
tooltipDirection: _direction,
hideOnTooltipTap: hideOnTap,
borderWidth: _changeBorder? 0 : 3,
child: Container(
color: Colors.cyan,
width: 80,
height: 80,
),
)
],
),
),
),
);
}
}
Loading

0 comments on commit 5ebe6f0

Please sign in to comment.