Skip to content

Commit

Permalink
Merge pull request #6 from Adityapanther/master
Browse files Browse the repository at this point in the history
version -2.1.2
  • Loading branch information
Adityapanther authored Jan 27, 2021
2 parents 48d9a8b + 20c9013 commit 56ed691
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 153 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# touch_ripple_effect changelog

## 2.1.2

* documantation bug fixed fixed

* `onTap` method delayed till ripple effect duration

## 2.1.1

* width and height properties added to TouchRippleEffect widget
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A new flutter package for any flutter widgets to add touch ripple effect and tou
pubsec.yaml:

```bash
touch_ripple_effect: 2.1.1
touch_ripple_effect: 2.1.2
```

2 ) open command prompt in project dir and run
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.1.1"
version: "2.1.2"
typed_data:
dependency: transitive
description:
Expand Down
150 changes: 85 additions & 65 deletions lib/src/touch_feedback.dart
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
import 'package:flutter/material.dart';

class TouchFeedback extends StatefulWidget {

/// [child] user child widget
/// [rippleColor] touch ripple color of widget
/// [backgroundColor] of widget container
/// if you have border of child widget then you should apply [borderRadius]
/// [feedbackDuration] will be animation duration.
/// [onTap] is for user click or tap handle.
/// user child widget [child]
final Widget child;

/// touch feedback color of widget [rippleColor]
final Color rippleColor;

/// background color of TouchFeedback widget [backgroundColor]
final Color backgroundColor;

/// border radius of TouchFeedback widget [borderRadius]
final BorderRadius borderRadius;

/// feedback animation duration. [feedbackDuration]
final Duration feedbackDuration;

/// user click listener or tap handler. [onTap]
final void Function() onTap;
TouchFeedback({
this.child, this.rippleColor, this.borderRadius,
this.backgroundColor, this.feedbackDuration,
this.onTap
});

TouchFeedback(
{this.child,
this.rippleColor,
this.borderRadius,
this.backgroundColor,
this.feedbackDuration,
this.onTap});

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

class _TouchFeedbackState extends State<TouchFeedback> {
/// private [_globalKey] global variable initialized
// private [_globalKey] global variable initialized
GlobalKey _globalKey = GlobalKey();

/// private [_rippleWidget] global variable initialized
// private [_rippleWidget] global variable initialized
Widget _rippleWidget;

/// user tap private [_dx] x-axis global variable initalized
// user tap private [_dx] x-axis global variable initalized
double _dx;
/// user tap private [_dy] y-axis global variable initalized

// user tap private [_dy] y-axis global variable initalized
double _dy;

double _mWidth;
Expand All @@ -43,75 +50,83 @@ class _TouchFeedbackState extends State<TouchFeedback> {
double _animWidth;
double _animHeight;

/// private [_defaultDuration] duration of animation if user not assign
// private [_defaultDuration] duration of animation if user not assign
Duration _defaultDuration = Duration(milliseconds: 200);

void _generateRipple(){

void _generateRipple() {
setState(() {
_rippleWidget = Opacity(
opacity: 0.2,
child: AnimatedContainer(
width: _animWidth == _mWidth? 10: _animWidth,
height: _animWidth == _mHeight ? 10: _animHeight,
width: _animWidth == _mWidth ? 10 : _animWidth,
height: _animWidth == _mHeight ? 10 : _animHeight,
alignment: Alignment.center,
decoration: BoxDecoration(color: widget.rippleColor, borderRadius: BorderRadius.circular(5)),
duration: widget.feedbackDuration != null ? widget.feedbackDuration: _defaultDuration,
decoration: BoxDecoration(
color: widget.rippleColor,
borderRadius: BorderRadius.circular(5)),
duration: widget.feedbackDuration != null
? widget.feedbackDuration
: _defaultDuration,
curve: Curves.easeInQuint,
),
),
);
});
milisecons();
// resetting axis after animation
_dx= 0;
_dy =0;
_dx = 0;
_dy = 0;
}

void milisecons(){
void milisecons() {
setState(() {
for(double i = 0; _mWidth> i; i++){
_animWidth = i;
for (double i = 0; _mWidth > i; i++) {
_animWidth = i;
}
for(double i = 0; _mHeight > i; i++){
for (double i = 0; _mHeight > i; i++) {
_animHeight = i;
}

});
});
}

void _setChildSize(){
void _setChildSize() {
setState(() {
/// sets child widget width to [_mWidth]
// sets child widget width to [_mWidth]
_mWidth = _globalKey.currentContext.size.width;
/// sets child widget Height to [_mHeight]

// sets child widget Height to [_mHeight]
_mHeight = _globalKey.currentContext.size.height;
/// setting [_mWidth] and [_mHeight] to [_animWidth] and [_animHeight]

// setting [_mWidth] and [_mHeight] to [_animWidth] and [_animHeight]
_animWidth = _mWidth;
_animHeight = _mHeight;
});
}

/// hide rippleWidget when time-up
// hide rippleWidget when time-up

void _timeOut(){
void _timeOut() {
Future.delayed(
widget.feedbackDuration != null ? widget.feedbackDuration : _defaultDuration,
(){
setState(() {
_rippleWidget = null;
});
}
);
widget.feedbackDuration != null
? widget.feedbackDuration
: _defaultDuration, () {
setState(() {
_rippleWidget = null;
});
});
}



@override
Widget build(BuildContext context) {

return GestureDetector(
onTap: widget.onTap,
onTapDown: (taped){
onTap: () {
// delaying onTap till feedback effect
Future.delayed(
widget.feedbackDuration == null
? _defaultDuration
: widget.feedbackDuration,
() => widget.onTap);
},
onTapDown: (taped) {
_dx = taped.localPosition.dx;
_dy = taped.localPosition.dy;
_setChildSize();
Expand All @@ -123,21 +138,26 @@ class _TouchFeedbackState extends State<TouchFeedback> {
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: widget.borderRadius,
color: widget.backgroundColor == null ? Colors.transparent: widget.backgroundColor,
color: widget.backgroundColor == null
? Colors.transparent
: widget.backgroundColor,
),
child: Stack(
clipBehavior: Clip.antiAlias,
children: [
widget.child == null
? throw Exception("touch ripple effect Child == null")
: widget.child,
Container(
width: _mWidth == null ? 10 : _mWidth,
height: _mHeight == null ? 10 : _mHeight,
color: Colors.transparent,
padding: EdgeInsets.fromLTRB(
_dx == null ? 0 : _dx, _dy == null ? 0 : _dy, 0, 0),
child: _rippleWidget,
),
],
),
child: Stack(
clipBehavior: Clip.antiAlias,
children: [
widget.child == null ? throw Exception("touch ripple effect Child == null"): widget.child,
Container(
width: _mWidth == null ? 10: _mWidth,
height: _mHeight== null ? 10: _mHeight,
color: Colors.transparent,
padding: EdgeInsets.fromLTRB(_dx == null ? 0:_dx, _dy == null ?0 : _dy, 0, 0),
child: _rippleWidget,
),
],
),
),
);
}
Expand Down
Loading

0 comments on commit 56ed691

Please sign in to comment.