-
-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
296 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'package:easy_refresh/easy_refresh.dart'; | ||
import 'package:example/widget/skeleton_item.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class CupertinoIndicatorPage extends StatefulWidget { | ||
const CupertinoIndicatorPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<CupertinoIndicatorPage> createState() => _CupertinoIndicatorPageState(); | ||
} | ||
|
||
class _CupertinoIndicatorPageState extends State<CupertinoIndicatorPage> { | ||
int _count = 10; | ||
late EasyRefreshController _controller; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_controller = EasyRefreshController( | ||
controlFinishRefresh: true, | ||
controlFinishLoad: true, | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Material( | ||
child: CupertinoPageScaffold( | ||
child: EasyRefresh( | ||
controller: _controller, | ||
header: const CupertinoHeader( | ||
position: IndicatorPosition.locator, | ||
safeArea: false, | ||
), | ||
footer: const CupertinoFooter( | ||
position: IndicatorPosition.locator, | ||
), | ||
onRefresh: () async { | ||
await Future.delayed(const Duration(seconds: 2)); | ||
if (!mounted) { | ||
return; | ||
} | ||
setState(() { | ||
_count = 10; | ||
}); | ||
_controller.finishRefresh(); | ||
_controller.resetFooter(); | ||
}, | ||
onLoad: () async { | ||
await Future.delayed(const Duration(seconds: 2)); | ||
if (!mounted) { | ||
return; | ||
} | ||
setState(() { | ||
_count += 5; | ||
}); | ||
_controller.finishLoad(_count >= 20 | ||
? IndicatorResult.noMore | ||
: IndicatorResult.success); | ||
}, | ||
child: CustomScrollView( | ||
slivers: [ | ||
const CupertinoSliverNavigationBar( | ||
largeTitle: Text('iOS Cupertino'), | ||
), | ||
const HeaderLocator.sliver(), | ||
SliverList( | ||
delegate: SliverChildBuilderDelegate( | ||
(context, index) { | ||
return const SkeletonItem(); | ||
}, | ||
childCount: _count, | ||
), | ||
), | ||
const FooterLocator.sliver(), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
part of easy_refresh; | ||
|
||
const double _kDefaultCupertinoIndicatorRadius = 14.0; | ||
|
||
/// Cupertino indicator. | ||
/// Base widget for [CupertinoHeader] and [CupertinoFooter]. | ||
class _CupertinoIndicator extends StatefulWidget { | ||
/// Indicator properties and state. | ||
final IndicatorState state; | ||
|
||
/// True for up and left. | ||
/// False for down and right. | ||
final bool reverse; | ||
|
||
const _CupertinoIndicator({ | ||
Key? key, | ||
required this.state, | ||
required this.reverse, | ||
}) : super(key: key); | ||
|
||
@override | ||
State<_CupertinoIndicator> createState() => _CupertinoIndicatorState(); | ||
} | ||
|
||
class _CupertinoIndicatorState extends State<_CupertinoIndicator> { | ||
IndicatorMode get _mode => widget.state.mode; | ||
double get _offset => widget.state.offset; | ||
double get _actualTriggerOffset => widget.state.actualTriggerOffset; | ||
|
||
double get _radius => _kDefaultCupertinoIndicatorRadius; | ||
|
||
Widget _buildIndicator() { | ||
final scale = (_offset / _actualTriggerOffset).clamp(0.0, 1.0); | ||
switch (_mode) { | ||
case IndicatorMode.drag: | ||
case IndicatorMode.armed: | ||
const Curve opacityCurve = Interval( | ||
0.0, | ||
0.8, | ||
curve: Curves.easeInOut, | ||
); | ||
return Opacity( | ||
opacity: opacityCurve.transform(scale), | ||
child: CupertinoActivityIndicator.partiallyRevealed( | ||
radius: _radius, | ||
progress: math.min(scale, 0.99), | ||
), | ||
); | ||
case IndicatorMode.ready: | ||
case IndicatorMode.processing: | ||
case IndicatorMode.processed: | ||
return CupertinoActivityIndicator( | ||
radius: _radius, | ||
); | ||
case IndicatorMode.done: | ||
return CupertinoActivityIndicator( | ||
radius: _radius * scale, | ||
); | ||
default: | ||
return Container(); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Stack( | ||
alignment: Alignment.center, | ||
children: [ | ||
SizedBox( | ||
height: _offset, | ||
width: double.infinity, | ||
), | ||
Positioned( | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
child: Container( | ||
alignment: Alignment.center, | ||
height: _actualTriggerOffset, | ||
width: double.infinity, | ||
child: _buildIndicator(), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
part of easy_refresh; | ||
|
||
class CupertinoFooter extends Footer { | ||
final Key? key; | ||
|
||
const CupertinoFooter({ | ||
this.key, | ||
double triggerOffset = 60, | ||
bool clamping = false, | ||
IndicatorPosition position = IndicatorPosition.behind, | ||
Duration processedDuration = Duration.zero, | ||
SpringDescription? spring, | ||
SpringBuilder? readySpringBuilder, | ||
bool springRebound = true, | ||
FrictionFactor? frictionFactor, | ||
bool safeArea = true, | ||
double? infiniteOffset = 60, | ||
bool? hitOver, | ||
bool? infiniteHitOver, | ||
bool hapticFeedback = false, | ||
}) : super( | ||
triggerOffset: triggerOffset, | ||
clamping: clamping, | ||
processedDuration: processedDuration, | ||
spring: spring, | ||
readySpringBuilder: readySpringBuilder, | ||
springRebound: springRebound, | ||
frictionFactor: frictionFactor, | ||
safeArea: safeArea, | ||
infiniteOffset: infiniteOffset, | ||
hitOver: hitOver, | ||
infiniteHitOver: infiniteHitOver, | ||
position: position, | ||
hapticFeedback: hapticFeedback, | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context, IndicatorState state) { | ||
assert(state.axis == Axis.vertical, | ||
'CupertinoFooter does not support horizontal scrolling.'); | ||
return _CupertinoIndicator( | ||
key: key, | ||
state: state, | ||
reverse: state.reverse, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
part of easy_refresh; | ||
|
||
class CupertinoHeader extends Header { | ||
final Key? key; | ||
|
||
const CupertinoHeader({ | ||
this.key, | ||
double triggerOffset = 60, | ||
bool clamping = false, | ||
IndicatorPosition position = IndicatorPosition.behind, | ||
Duration processedDuration = const Duration(seconds: 1), | ||
SpringDescription? spring, | ||
SpringBuilder? readySpringBuilder, | ||
bool springRebound = false, | ||
FrictionFactor? frictionFactor, | ||
bool safeArea = true, | ||
double? infiniteOffset, | ||
bool? hitOver, | ||
bool? infiniteHitOver, | ||
bool hapticFeedback = false, | ||
}) : super( | ||
triggerOffset: triggerOffset, | ||
clamping: clamping, | ||
processedDuration: processedDuration, | ||
spring: spring, | ||
readySpringBuilder: readySpringBuilder, | ||
springRebound: springRebound, | ||
frictionFactor: frictionFactor, | ||
safeArea: safeArea, | ||
infiniteOffset: infiniteOffset, | ||
hitOver: hitOver, | ||
infiniteHitOver: infiniteHitOver, | ||
position: position, | ||
hapticFeedback: hapticFeedback, | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context, IndicatorState state) { | ||
assert(state.axis == Axis.vertical, | ||
'CupertinoHeader does not support horizontal scrolling.'); | ||
return _CupertinoIndicator( | ||
key: key, | ||
state: state, | ||
reverse: state.reverse, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.