refactor(notes): Improve code formatting and replace platform-specific refresh controls
This commit is contained in:
@@ -433,23 +433,77 @@ class LoadingButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Refresh indicator with Conduit styling
|
||||
/// Refresh indicator with Conduit styling.
|
||||
///
|
||||
/// Uses platform-appropriate refresh controls:
|
||||
/// - iOS: Native Cupertino-style refresh control (when child is CustomScrollView)
|
||||
/// - Android/Other: Material RefreshIndicator
|
||||
///
|
||||
/// Set [edgeOffset] to position the indicator below an app bar or other
|
||||
/// overlay. For example, use `MediaQuery.of(context).padding.top + kToolbarHeight`
|
||||
/// to position below a transparent/floating app bar.
|
||||
///
|
||||
/// Note: On iOS with a CustomScrollView child, [edgeOffset] is ignored since
|
||||
/// CupertinoSliverRefreshControl naturally positions itself based on scroll
|
||||
/// content. The scroll view's existing padding should handle app bar clearance.
|
||||
class ConduitRefreshIndicator extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Future<void> Function() onRefresh;
|
||||
|
||||
/// The distance from the top of the scroll view where the refresh indicator
|
||||
/// will appear. Useful for positioning below a floating/transparent app bar.
|
||||
///
|
||||
/// Note: This is only effective on Android/non-iOS platforms, or on iOS when
|
||||
/// the child is not a CustomScrollView. For iOS with CustomScrollView, the
|
||||
/// refresh control naturally positions based on scroll content.
|
||||
final double edgeOffset;
|
||||
|
||||
const ConduitRefreshIndicator({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.onRefresh,
|
||||
this.edgeOffset = 0.0,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// On iOS, try to use CupertinoSliverRefreshControl for native feel
|
||||
// when the child is directly a CustomScrollView
|
||||
if (Platform.isIOS && child is CustomScrollView) {
|
||||
final csv = child as CustomScrollView;
|
||||
return CustomScrollView(
|
||||
key: csv.key,
|
||||
controller: csv.controller,
|
||||
scrollDirection: csv.scrollDirection,
|
||||
reverse: csv.reverse,
|
||||
primary: csv.primary,
|
||||
physics: csv.physics,
|
||||
shrinkWrap: csv.shrinkWrap,
|
||||
cacheExtent: csv.cacheExtent,
|
||||
keyboardDismissBehavior: csv.keyboardDismissBehavior,
|
||||
clipBehavior: csv.clipBehavior,
|
||||
center: csv.center,
|
||||
anchor: csv.anchor,
|
||||
semanticChildCount: csv.semanticChildCount,
|
||||
dragStartBehavior: csv.dragStartBehavior,
|
||||
restorationId: csv.restorationId,
|
||||
slivers: [
|
||||
// CupertinoSliverRefreshControl naturally positions itself based on
|
||||
// scroll content; the scroll view's existing padding handles app bar
|
||||
// clearance, so no edgeOffset adjustment is needed here.
|
||||
CupertinoSliverRefreshControl(onRefresh: onRefresh),
|
||||
...csv.slivers,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// For Android, other platforms, or when child is not a CustomScrollView,
|
||||
// use Material RefreshIndicator which works with any scrollable
|
||||
return RefreshIndicator(
|
||||
onRefresh: onRefresh,
|
||||
color: context.conduitTheme.buttonPrimary,
|
||||
backgroundColor: context.conduitTheme.surfaceBackground,
|
||||
edgeOffset: edgeOffset,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user