Skip to content

Commit

Permalink
feat: Indicator add [triggerWhenReach] [#348](#348). Trigger immediat…
Browse files Browse the repository at this point in the history
…ely when reaching the [triggerOffset].
  • Loading branch information
xuelongqy committed Jul 14, 2022
1 parent 26a0fe3 commit c9c87b6
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change log
## V 3.0.2
> feat: Indicator add [triggerWhenReach] [#348](https://github.com/xuelongqy/flutter_easy_refresh/pull/348). Trigger immediately when reaching the [triggerOffset].
> feat: CupertinoIndicator support horizontal.
## V 3.0.1+1
> fix: CupertinoActivityIndicator radius == 0.
Expand Down
1 change: 1 addition & 0 deletions example/lib/l10n/translations/en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ const en = {
'Tron chain, TRX, USDT, USDC and other tokens',
'Dogecoin donation': 'Dogecoin donation',
'%s copied!': '%s copied!',
'Trigger immediately': 'Trigger immediately',
};
1 change: 1 addition & 0 deletions example/lib/l10n/translations/zh_cn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ const zhCN = {
'Tron chain, TRX, USDT, USDC and other tokens': '波场链,TRX、USDT、USDC及其他代币',
'Dogecoin donation': '狗狗币捐赠',
'%s copied!': '%s 已复制!',
'Trigger immediately': '立即触发',
};
14 changes: 14 additions & 0 deletions example/lib/page/style/classical_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class _ClassicPageState extends State<ClassicPage> {
showMessage: _headerProperties.message,
showText: _headerProperties.text,
infiniteOffset: _headerProperties.infinite ? 70 : null,
triggerWhenReach: _headerProperties.immediately,
dragText: 'Pull to refresh'.tr,
armedText: 'Release ready'.tr,
readyText: 'Refreshing...'.tr,
Expand All @@ -80,6 +81,7 @@ class _ClassicPageState extends State<ClassicPage> {
showMessage: _footerProperties.message,
showText: _footerProperties.text,
infiniteOffset: _footerProperties.infinite ? 70 : null,
triggerWhenReach: _footerProperties.immediately,
dragText: 'Pull to load'.tr,
armedText: 'Release ready'.tr,
readyText: 'Loading...'.tr,
Expand Down Expand Up @@ -290,6 +292,17 @@ class _ClassicPageState extends State<ClassicPage> {
),
),
),
ListTile(
title: Text('Trigger immediately'.tr),
trailing: Switch(
value: properties.immediately,
onChanged: (value) {
setState(() {
properties.immediately = value;
});
},
),
),
ListTile(
title: Text('Infinite'.tr),
trailing: Switch(
Expand Down Expand Up @@ -351,6 +364,7 @@ class _CIProperties {
bool message = true;
bool text = true;
bool infinite;
bool immediately = false;

_CIProperties({
required this.name,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: EasyRefresh example.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 3.0.0+45
version: 3.0.2+47

environment:
sdk: ">=2.13.0 <3.0.0"
Expand Down
9 changes: 9 additions & 0 deletions lib/src/indicator/footer/footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class Footer extends Indicator {
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -48,6 +49,7 @@ abstract class Footer extends Indicator {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);
}

Expand Down Expand Up @@ -80,6 +82,7 @@ class BuilderFooter extends Footer {
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -103,6 +106,7 @@ class BuilderFooter extends Footer {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down Expand Up @@ -136,6 +140,7 @@ class ListenerFooter extends Footer {
double? secondaryDimension,
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -159,6 +164,7 @@ class ListenerFooter extends Footer {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down Expand Up @@ -203,6 +209,7 @@ abstract class SecondaryFooter extends Footer {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: footer.notifyWhenInvisible,
listenable: listenable ?? footer.listenable,
triggerWhenReach: footer.triggerWhenReach,
);

@override
Expand Down Expand Up @@ -300,6 +307,7 @@ class OverrideFooter extends Footer {
double? secondaryCloseTriggerOffset,
bool? notifyWhenInvisible,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset ?? footer.triggerOffset,
clamping: clamping ?? footer.clamping,
Expand Down Expand Up @@ -328,6 +336,7 @@ class OverrideFooter extends Footer {
notifyWhenInvisible:
notifyWhenInvisible ?? footer.notifyWhenInvisible,
listenable: listenable ?? footer.listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down
9 changes: 9 additions & 0 deletions lib/src/indicator/header/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class Header extends Indicator {
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -48,6 +49,7 @@ abstract class Header extends Indicator {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);
}

Expand Down Expand Up @@ -80,6 +82,7 @@ class BuilderHeader extends Header {
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -103,6 +106,7 @@ class BuilderHeader extends Header {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down Expand Up @@ -136,6 +140,7 @@ class ListenerHeader extends Header {
double? secondaryDimension,
double secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
bool notifyWhenInvisible = false,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset,
clamping: clamping,
Expand All @@ -159,6 +164,7 @@ class ListenerHeader extends Header {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: notifyWhenInvisible,
listenable: listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down Expand Up @@ -203,6 +209,7 @@ abstract class SecondaryHeader extends Header {
secondaryCloseTriggerOffset: secondaryCloseTriggerOffset,
notifyWhenInvisible: header.notifyWhenInvisible,
listenable: listenable ?? header.listenable,
triggerWhenReach: header.triggerWhenReach,
);

@override
Expand Down Expand Up @@ -300,6 +307,7 @@ class OverrideHeader extends Header {
double? secondaryCloseTriggerOffset,
bool? notifyWhenInvisible,
IndicatorStateListenable? listenable,
bool triggerWhenReach = false,
}) : super(
triggerOffset: triggerOffset ?? header.triggerOffset,
clamping: clamping ?? header.clamping,
Expand Down Expand Up @@ -328,6 +336,7 @@ class OverrideHeader extends Header {
notifyWhenInvisible:
notifyWhenInvisible ?? header.notifyWhenInvisible,
listenable: listenable ?? header.listenable,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down
4 changes: 4 additions & 0 deletions lib/src/indicator/indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ abstract class Indicator {
/// Monitor state changes in real time.
final IndicatorStateListenable? listenable;

/// Trigger immediately when reaching the [triggerOffset].
final bool triggerWhenReach;

const Indicator({
required this.triggerOffset,
required this.clamping,
Expand All @@ -362,6 +365,7 @@ abstract class Indicator {
this.secondaryCloseTriggerOffset = kDefaultSecondaryCloseTriggerOffset,
this.notifyWhenInvisible = false,
this.listenable,
this.triggerWhenReach = false,
}) : hitOver = hitOver ?? infiniteOffset != null,
infiniteHitOver = infiniteHitOver ?? infiniteOffset == null,
assert(infiniteOffset == null || infiniteOffset >= 0,
Expand Down
28 changes: 19 additions & 9 deletions lib/src/notifier/indicator_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,17 @@ abstract class IndicatorNotifier extends ChangeNotifier {
}
} else if (_offset == actualTriggerOffset) {
// Must be exceeded to trigger the task
_mode = userOffsetNotifier.value
? (_releaseOffset > actualTriggerOffset
if (userOffsetNotifier.value) {
if (_indicator.triggerWhenReach) {
_mode = IndicatorMode.processing;
} else {
_mode = (_releaseOffset > actualTriggerOffset
? IndicatorMode.ready
: IndicatorMode.armed)
: IndicatorMode.processing;
: IndicatorMode.armed);
}
} else {
_mode = IndicatorMode.processing;
}
} else if (_offset > actualTriggerOffset) {
if (hasSecondary &&
_offset >= actualSecondaryTriggerOffset &&
Expand All @@ -577,11 +583,15 @@ abstract class IndicatorNotifier extends ChangeNotifier {
// Process
// If the user is scrolling
// (the task is not executed if it is not released)
_mode = userOffsetNotifier.value
? IndicatorMode.armed
: (_releaseOffset > actualTriggerOffset
? IndicatorMode.ready
: IndicatorMode.armed);
if (userOffsetNotifier.value) {
_mode = _indicator.triggerWhenReach
? IndicatorMode.processing
: IndicatorMode.armed;
} else {
_mode = (_releaseOffset > actualTriggerOffset
? IndicatorMode.ready
: IndicatorMode.armed);
}
}
}
// Execute the task.
Expand Down
2 changes: 2 additions & 0 deletions lib/src/styles/classic/footer/classic_footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ClassicFooter extends Footer {
bool? hitOver,
bool? infiniteHitOver,
bool hapticFeedback = false,
bool triggerWhenReach = false,
this.mainAxisAlignment = MainAxisAlignment.start,
this.backgroundColor,
this.dragText,
Expand Down Expand Up @@ -146,6 +147,7 @@ class ClassicFooter extends Footer {
infiniteHitOver: infiniteHitOver,
position: position,
hapticFeedback: hapticFeedback,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/src/styles/classic/header/classic_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ClassicHeader extends Header {
bool? hitOver,
bool? infiniteHitOver,
bool hapticFeedback = false,
bool triggerWhenReach = false,
this.mainAxisAlignment = MainAxisAlignment.center,
this.backgroundColor,
this.dragText,
Expand Down Expand Up @@ -146,6 +147,7 @@ class ClassicHeader extends Header {
infiniteHitOver: infiniteHitOver,
position: position,
hapticFeedback: hapticFeedback,
triggerWhenReach: triggerWhenReach,
);

@override
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: easy_refresh
description: A flutter widget that provides pull-down refresh and pull-up load.
version: 3.0.1+1
version: 3.0.2
homepage: https://xuelongqy.github.io/flutter_easy_refresh
repository: https://github.com/xuelongqy/flutter_easy_refresh
issue_tracker: https://github.com/xuelongqy/flutter_easy_refresh/issues
Expand Down

0 comments on commit c9c87b6

Please sign in to comment.