Skip to content

Commit

Permalink
#33_first_part
Browse files Browse the repository at this point in the history
* Anim speed factor and refactoring code

* Updated readme

* Changed assert
  • Loading branch information
AadumKhor committed May 1, 2020
1 parent fdf49fd commit 2020275
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,17 @@ If you do not want the opacity transition of child then set `showChildOpacityTra

### LiquidPullToRefresh Class

| Dart attribute | Datatype | Description | Default Value |
| :------------------------------------ | :-------------------------- | :----------------------------------------------------------- | :-------------------: |
| child | ScrollView | The widget below this widget in the tree. | @required |
| onRefresh | RefreshCallback | A function that's called when the refreshing of page takes place. | @required |
| height | double | The distance from the child's top or bottom edge to where the box will settle after the spring effect. | 100.0 |
| springAnimationDurationInMilliseconds | int | Duration in milliseconds of springy effect that occurs when we leave dragging after full drag. | 1000 |
| borderWidth | double | Border width of progressing circle in Progressing Indicator. | 2.0 |
| showChildOpacityTransition | bool | Whether to show child opacity transition or not. | true |
| color | Color | The progress indicator's foreground color. | ThemeData.accentColor |
| backgroundColor | Color | The progress indicator's background color. | ThemeData.canvasColor |
| notificationPredicate | ScrollNotificationPredicate | A check that specifies whether a `ScrollNotification` should be handled by this widget. | null |
| scrollController | ScrollController | Controls the `ScrollView` child. | null |
| Dart attribute | Datatype | Description | Default Value |
| :------------------------------------ | :-------------- | :----------------------------------------------------------------------------------------------------- | :-------------------: |
| child | ScrollView | The widget below this widget in the tree. | @required |
| onRefresh | RefreshCallback | A function that's called when the refreshing of page takes place. | @required |
| height | double | The distance from the child's top or bottom edge to where the box will settle after the spring effect. | 100.0 |
| springAnimationDurationInMilliseconds | int | Duration in milliseconds of springy effect that occurs when we leave dragging after full drag. | 1000 |
| borderWidth | double | Border width of progressing circle in Progressing Indicator. | 2.0 |
| showChildOpacityTransition | bool | Whether to show child opacity transition or not. | true |
| color | Color | The progress indicator's foreground color. | ThemeData.accentColor |
| backgroundColor | Color | The progress indicator's background color. | ThemeData.canvasColor |
| animSpeedFactor | double | Controls the speed of the animation after refresh. Used to hasten the ending animation. | 1.0 |

For help on editing package code, view the [flutter documentation](https://flutter.io/developing-packages/).

Expand Down
56 changes: 30 additions & 26 deletions lib/liquid_pull_to_refresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const double _kDragSizeFactorLimit = 1.5;

// When the scroll ends, the duration of the progress indicator's animation
// to the LiquidPullToRefresh's displacement.
const Duration _kIndicatorSnapDuration = Duration(milliseconds: 150);
// const Duration _kIndicatorSnapDuration = Duration(milliseconds: 150);

// The duration of the ScaleTransitionIn of box that starts when the
// refresh action has completed.
Expand Down Expand Up @@ -47,19 +47,18 @@ enum _LiquidPullToRefreshMode {
class LiquidPullToRefresh extends StatefulWidget {
const LiquidPullToRefresh({
Key key,
this.animSpeedFactor = 1.0,
@required this.child,
@required this.onRefresh,
this.color,
this.backgroundColor,
this.notificationPredicate = defaultScrollNotificationPredicate,
this.height,
this.springAnimationDurationInMilliseconds = 1000,
this.borderWidth = 2.0,
this.showChildOpacityTransition = true,
this.scrollController,
}) : assert(child != null),
assert(onRefresh != null),
assert(notificationPredicate != null),
assert(animSpeedFactor >= 1.0),
super(key: key);

/// The widget below this widget in the tree.
Expand All @@ -82,6 +81,12 @@ class LiquidPullToRefresh extends StatefulWidget {
/// default to 1000
final int springAnimationDurationInMilliseconds;

/// To regulate the "speed of the animation" towards the end.
/// To hasten it give a value > 1.0 and vice versa.
///
/// default to 1.0
final double animSpeedFactor;

/// Border width of progressing circle in Progressing Indicator
///
/// default to 2.0
Expand All @@ -105,17 +110,6 @@ class LiquidPullToRefresh extends StatefulWidget {
/// [ThemeData.canvasColor] by default.
final Color backgroundColor;

/// A check that specifies whether a [ScrollNotification] should be
/// handled by this widget.
///
/// By default, checks whether `notification.depth == 0`. Set it to something
/// else for more complicated layouts.
final ScrollNotificationPredicate notificationPredicate;

/// Controls the [ScrollView] child.
/// [null] by default.
final ScrollController scrollController;

@override
LiquidPullToRefreshState createState() => LiquidPullToRefreshState();
}
Expand Down Expand Up @@ -262,7 +256,6 @@ class LiquidPullToRefreshState extends State<LiquidPullToRefresh>
}

bool _handleScrollNotification(ScrollNotification notification) {
if (!widget.notificationPredicate(notification)) return false;
if (notification is ScrollStartNotification &&
notification.metrics.extentBefore == 0.0 &&
_mode == null &&
Expand Down Expand Up @@ -356,43 +349,54 @@ class LiquidPullToRefreshState extends State<LiquidPullToRefresh>
// progress ring disappear animation
_ringDisappearController.animateTo(1.0,
duration: Duration(
milliseconds: widget.springAnimationDurationInMilliseconds),
milliseconds: (widget.springAnimationDurationInMilliseconds /
widget.animSpeedFactor)
.round()),
curve: Curves.linear);

// indicator translate out
_indicatorMoveWithPeakController.animateTo(0.0,
duration: Duration(
milliseconds: widget.springAnimationDurationInMilliseconds),
milliseconds: (widget.springAnimationDurationInMilliseconds /
widget.animSpeedFactor)
.round()),
curve: Curves.linear);
_indicatorTranslateInOutController.animateTo(0.0,
duration: Duration(
milliseconds: widget.springAnimationDurationInMilliseconds),
milliseconds: (widget.springAnimationDurationInMilliseconds /
widget.animSpeedFactor)
.round()),
curve: Curves.linear);

//initial value of controller is 1.0
await _showPeakController.animateTo(0.3,
duration: Duration(
milliseconds:
(widget.springAnimationDurationInMilliseconds).round()),
milliseconds: (widget.springAnimationDurationInMilliseconds /
widget.animSpeedFactor)
.round()),
curve: Curves.linear);

_radiusController.animateTo(0.0,
duration: Duration(
milliseconds:
(widget.springAnimationDurationInMilliseconds / 5).round()),
milliseconds: (widget.springAnimationDurationInMilliseconds /
(widget.animSpeedFactor * 5))
.round()),
curve: Curves.linear);

_showPeakController.value = 0.175;
await _showPeakController.animateTo(0.1,
duration: Duration(
milliseconds:
(widget.springAnimationDurationInMilliseconds / 5).round()),
milliseconds: (widget.springAnimationDurationInMilliseconds /
(widget.animSpeedFactor * 5))
.round()),
curve: Curves.easeOut);
_showPeakController.value = 0.0;

await _positionController.animateTo(0.0,
duration: Duration(
milliseconds: _kIndicatorSnapDuration.inMilliseconds * 2));
milliseconds: (widget.springAnimationDurationInMilliseconds /
widget.animSpeedFactor)
.round()));
break;

case _LiquidPullToRefreshMode.canceled:
Expand Down

0 comments on commit 2020275

Please sign in to comment.