From c036d518d721e9dafc7c02e999045d9983399bb9 Mon Sep 17 00:00:00 2001 From: hemang Date: Sun, 17 Dec 2023 16:20:52 +0530 Subject: [PATCH] -Updated flutter version [3.16.4] & Dart[3.2.3] -[breaking change]Remove the colon-syntax for default values ,to make project compatible for Dart 3 and above Reported issue: https://github.com/dart-lang/language/issues/2357 --- lib/pull_to_refresh.dart | 1 + lib/src/indicator/bezier_indicator.dart | 26 ++-- lib/src/indicator/classic_indicator.dart | 35 ++--- lib/src/indicator/custom_indicator.dart | 10 +- lib/src/indicator/link_indicator.dart | 10 +- lib/src/indicator/material_indicator.dart | 20 ++- lib/src/indicator/twolevel_indicator.dart | 18 +-- lib/src/indicator/waterdrop_header.dart | 15 +- lib/src/internals/indicator_wrap.dart | 28 ++-- lib/src/internals/refresh_localizations.dart | 1 - lib/src/internals/refresh_physics.dart | 5 +- lib/src/internals/slivers.dart | 2 +- lib/src/smart_refresher.dart | 148 +++++++++---------- pubspec.yaml | 3 +- 14 files changed, 152 insertions(+), 170 deletions(-) diff --git a/lib/pull_to_refresh.dart b/lib/pull_to_refresh.dart index 4ce6465a..ad1be163 100644 --- a/lib/pull_to_refresh.dart +++ b/lib/pull_to_refresh.dart @@ -12,6 +12,7 @@ export 'src/indicator/waterdrop_header.dart'; export 'src/indicator/custom_indicator.dart'; export 'src/internals/refresh_physics.dart'; export "src/internals/indicator_wrap.dart"; +export 'src/internals/slivers.dart'; export 'src/indicator/link_indicator.dart'; export 'src/indicator/material_indicator.dart'; export 'src/indicator/bezier_indicator.dart'; diff --git a/lib/src/indicator/bezier_indicator.dart b/lib/src/indicator/bezier_indicator.dart index f067c3a7..07e8922c 100644 --- a/lib/src/indicator/bezier_indicator.dart +++ b/lib/src/indicator/bezier_indicator.dart @@ -4,15 +4,11 @@ * Time: 2019-08-02 19:20 */ -import 'package:flutter/animation.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart' hide RefreshIndicator, RefreshIndicatorState; -import 'package:pull_to_refresh/src/internals/indicator_wrap.dart'; import 'dart:math' as math; import 'package:flutter/physics.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; enum BezierDismissType { None, RectSpread, ScaleToCenter } @@ -38,15 +34,15 @@ class BezierHeader extends RefreshIndicator { final double rectHeight; BezierHeader( - {this.child: const Text(""), + {this.child = const Text(""), this.onOffsetChange, this.onModeChange, this.readyRefresh, - this.enableChildOverflow: false, + this.enableChildOverflow = false, this.endRefresh, this.onResetValue, - this.dismissType: BezierDismissType.RectSpread, - this.rectHeight: 70, + this.dismissType = BezierDismissType.RectSpread, + this.rectHeight = 70, this.bezierColor}) : super(refreshStyle: RefreshStyle.UnFollow, height: rectHeight); @@ -306,12 +302,12 @@ class BezierCircleHeader extends StatefulWidget { BezierCircleHeader( {this.bezierColor, - this.rectHeight: 70, - this.circleColor: Colors.white, - this.enableChildOverflow: false, - this.dismissType: BezierDismissType.RectSpread, - this.circleType: BezierCircleType.Progress, - this.circleRadius: 12}); + this.rectHeight = 70, + this.circleColor = Colors.white, + this.enableChildOverflow = false, + this.dismissType = BezierDismissType.RectSpread, + this.circleType = BezierCircleType.Progress, + this.circleRadius = 12}); @override State createState() { diff --git a/lib/src/indicator/classic_indicator.dart b/lib/src/indicator/classic_indicator.dart index c88ce2c5..fbbc07dc 100644 --- a/lib/src/indicator/classic_indicator.dart +++ b/lib/src/indicator/classic_indicator.dart @@ -6,10 +6,7 @@ import 'package:flutter/material.dart' hide RefreshIndicator, RefreshIndicatorState; -import 'package:flutter/widgets.dart'; import '../../pull_to_refresh.dart'; -import '../internals/indicator_wrap.dart'; -import '../smart_refresher.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -59,11 +56,11 @@ class ClassicHeader extends RefreshIndicator { const ClassicHeader({ Key? key, - RefreshStyle refreshStyle: RefreshStyle.Follow, - double height: 60.0, - Duration completeDuration: const Duration(milliseconds: 600), + RefreshStyle refreshStyle = RefreshStyle.Follow, + double height = 60.0, + Duration completeDuration = const Duration(milliseconds: 600), this.outerBuilder, - this.textStyle: const TextStyle(color: Colors.grey), + this.textStyle = const TextStyle(color: Colors.grey), this.releaseText, this.refreshingText, this.canTwoLevelIcon, @@ -72,11 +69,11 @@ class ClassicHeader extends RefreshIndicator { this.completeText, this.failedText, this.idleText, - this.iconPos: IconPosition.left, - this.spacing: 15.0, + this.iconPos = IconPosition.left, + this.spacing = 15.0, this.refreshingIcon, - this.failedIcon: const Icon(Icons.error, color: Colors.grey), - this.completeIcon: const Icon(Icons.done, color: Colors.grey), + this.failedIcon = const Icon(Icons.error, color: Colors.grey), + this.completeIcon = const Icon(Icons.done, color: Colors.grey), this.idleIcon = const Icon(Icons.arrow_downward, color: Colors.grey), this.releaseIcon = const Icon(Icons.refresh, color: Colors.grey), }) : super( @@ -217,22 +214,22 @@ class ClassicFooter extends LoadIndicator { const ClassicFooter({ Key? key, VoidCallback? onClick, - LoadStyle loadStyle: LoadStyle.ShowAlways, - double height: 60.0, + LoadStyle loadStyle = LoadStyle.ShowAlways, + double height = 60.0, this.outerBuilder, - this.textStyle: const TextStyle(color: Colors.grey), + this.textStyle = const TextStyle(color: Colors.grey), this.loadingText, this.noDataText, this.noMoreIcon, this.idleText, this.failedText, this.canLoadingText, - this.failedIcon: const Icon(Icons.error, color: Colors.grey), - this.iconPos: IconPosition.left, - this.spacing: 15.0, - this.completeDuration: const Duration(milliseconds: 300), + this.failedIcon = const Icon(Icons.error, color: Colors.grey), + this.iconPos = IconPosition.left, + this.spacing = 15.0, + this.completeDuration = const Duration(milliseconds: 300), this.loadingIcon, - this.canLoadingIcon: const Icon(Icons.autorenew, color: Colors.grey), + this.canLoadingIcon = const Icon(Icons.autorenew, color: Colors.grey), this.idleIcon = const Icon(Icons.arrow_upward, color: Colors.grey), }) : super( key: key, diff --git a/lib/src/indicator/custom_indicator.dart b/lib/src/indicator/custom_indicator.dart index 4e9b563a..5db9a0c5 100644 --- a/lib/src/indicator/custom_indicator.dart +++ b/lib/src/indicator/custom_indicator.dart @@ -70,9 +70,9 @@ class CustomHeader extends RefreshIndicator { this.onOffsetChange, this.onModeChange, this.onResetValue, - double height: 60.0, - Duration completeDuration: const Duration(milliseconds: 600), - RefreshStyle refreshStyle: RefreshStyle.Follow, + double height = 60.0, + Duration completeDuration = const Duration(milliseconds: 600), + RefreshStyle refreshStyle = RefreshStyle.Follow, }) : super( key: key, completeDuration: completeDuration, @@ -147,12 +147,12 @@ class CustomFooter extends LoadIndicator { const CustomFooter({ Key? key, - double height: 60.0, + double height = 60.0, this.onModeChange, this.onOffsetChange, this.readyLoading, this.endLoading, - LoadStyle loadStyle: LoadStyle.ShowAlways, + LoadStyle loadStyle = LoadStyle.ShowAlways, required this.builder, Function? onClick, }) : super( diff --git a/lib/src/indicator/link_indicator.dart b/lib/src/indicator/link_indicator.dart index e32b9eb4..c84ce97f 100644 --- a/lib/src/indicator/link_indicator.dart +++ b/lib/src/indicator/link_indicator.dart @@ -3,8 +3,8 @@ * Email: peng8350@gmail.com * Time: 2019-06-26 13:17 */ -import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter/widgets.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; /// enable header link other header place outside the viewport class LinkHeader extends RefreshIndicator { @@ -14,9 +14,9 @@ class LinkHeader extends RefreshIndicator { const LinkHeader( {Key? key, required this.linkKey, - double height: 0.0, + double height = 0.0, RefreshStyle? refreshStyle, - Duration completeDuration: const Duration(milliseconds: 200)}) + Duration completeDuration = const Duration(milliseconds: 200)}) : super( height: height, refreshStyle: refreshStyle, @@ -81,8 +81,8 @@ class LinkFooter extends LoadIndicator { const LinkFooter( {Key? key, required this.linkKey, - double height: 0.0, - LoadStyle loadStyle: LoadStyle.ShowAlways}) + double height = 0.0, + LoadStyle loadStyle = LoadStyle.ShowAlways}) : super(height: height, loadStyle: loadStyle, key: key); @override diff --git a/lib/src/indicator/material_indicator.dart b/lib/src/indicator/material_indicator.dart index e4386b3f..60897615 100644 --- a/lib/src/indicator/material_indicator.dart +++ b/lib/src/indicator/material_indicator.dart @@ -4,10 +4,8 @@ * Time: 2019/5/19 下午9:23 */ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart' hide RefreshIndicator, RefreshIndicatorState; -import 'package:flutter/widgets.dart'; import '../internals/indicator_wrap.dart'; import '../smart_refresher.dart'; @@ -34,12 +32,12 @@ class MaterialClassicHeader extends RefreshIndicator { const MaterialClassicHeader({ Key? key, - double height: 80.0, + double height = 80.0, this.semanticsLabel, this.semanticsValue, this.color, - double offset: 0, - this.distance: 50.0, + double offset = 0, + this.distance = 50.0, this.backgroundColor, }) : super( key: key, @@ -95,7 +93,7 @@ class _MaterialClassicHeaderState @override void didUpdateWidget(covariant MaterialClassicHeader oldWidget) { // TODO: implement didUpdateWidget - _position = Scrollable.of(context)!.position; + _position = Scrollable.of(context).position; super.didUpdateWidget(oldWidget); } @@ -113,7 +111,7 @@ class _MaterialClassicHeaderState alignment: Alignment.topCenter, child: RefreshProgressIndicator( semanticsLabel: widget.semanticsLabel ?? - MaterialLocalizations?.of(context) + MaterialLocalizations.of(context) .refreshIndicatorSemanticLabel, semanticsValue: widget.semanticsValue, value: floating ? null : _valueAni.value, @@ -157,7 +155,7 @@ class _MaterialClassicHeaderState @override void didChangeDependencies() { final ThemeData theme = Theme.of(context); - _position = Scrollable.of(context)!.position; + _position = Scrollable.of(context).position; _valueColor = _positionController.drive( ColorTween( begin: (widget.color ?? theme.primaryColor).withOpacity(0.0), @@ -195,10 +193,10 @@ class WaterDropMaterialHeader extends MaterialClassicHeader { const WaterDropMaterialHeader({ Key? key, String? semanticsLabel, - double distance: 60.0, - double offset: 0, + double distance = 60.0, + double offset = 0, String? semanticsValue, - Color color: Colors.white, + Color color = Colors.white, Color? backgroundColor, }) : super( key: key, diff --git a/lib/src/indicator/twolevel_indicator.dart b/lib/src/indicator/twolevel_indicator.dart index a6f2c536..b0a666bc 100644 --- a/lib/src/indicator/twolevel_indicator.dart +++ b/lib/src/indicator/twolevel_indicator.dart @@ -5,8 +5,6 @@ */ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter/widgets.dart'; import 'classic_indicator.dart'; import '../smart_refresher.dart'; @@ -89,11 +87,11 @@ class TwoLevelHeader extends StatelessWidget { const TwoLevelHeader( {Key? key, - this.height: 80.0, + this.height = 80.0, this.decoration, - this.displayAlignment: TwoLevelDisplayAlignment.fromBottom, - this.completeDuration: const Duration(milliseconds: 600), - this.textStyle: const TextStyle(color: const Color(0xff555555)), + this.displayAlignment = TwoLevelDisplayAlignment.fromBottom, + this.completeDuration = const Duration(milliseconds: 600), + this.textStyle = const TextStyle(color: const Color(0xff555555)), this.releaseText, this.refreshingText, this.canTwoLevelIcon, @@ -101,11 +99,11 @@ class TwoLevelHeader extends StatelessWidget { this.completeText, this.failedText, this.idleText, - this.iconPos: IconPosition.left, - this.spacing: 15.0, + this.iconPos = IconPosition.left, + this.spacing = 15.0, this.refreshingIcon, - this.failedIcon: const Icon(Icons.error, color: Colors.grey), - this.completeIcon: const Icon(Icons.done, color: Colors.grey), + this.failedIcon = const Icon(Icons.error, color: Colors.grey), + this.completeIcon = const Icon(Icons.done, color: Colors.grey), this.idleIcon = const Icon(Icons.arrow_downward, color: Colors.grey), this.releaseIcon = const Icon(Icons.refresh, color: Colors.grey), this.twoLevelWidget}); diff --git a/lib/src/indicator/waterdrop_header.dart b/lib/src/indicator/waterdrop_header.dart index cecca80d..5ffd67c3 100644 --- a/lib/src/indicator/waterdrop_header.dart +++ b/lib/src/indicator/waterdrop_header.dart @@ -7,12 +7,9 @@ import 'dart:async'; import 'package:flutter/material.dart' hide RefreshIndicatorState, RefreshIndicator; -import 'package:flutter/widgets.dart'; import 'package:flutter/foundation.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; -import '../internals/indicator_wrap.dart'; import 'package:flutter/cupertino.dart'; -import '../smart_refresher.dart'; /// QQ ios refresh header effect class WaterDropHeader extends RefreshIndicator { @@ -35,10 +32,10 @@ class WaterDropHeader extends RefreshIndicator { Key? key, this.refresh, this.complete, - Duration completeDuration: const Duration(milliseconds: 600), + Duration completeDuration = const Duration(milliseconds: 600), this.failed, - this.waterDropColor: Colors.grey, - this.idleIcon: const Icon( + this.waterDropColor = Colors.grey, + this.idleIcon = const Icon( Icons.autorenew, size: 15, color: Colors.white, @@ -165,17 +162,17 @@ class _WaterDropHeaderState extends RefreshIndicatorState ), ), quarterTurns: - Scrollable.of(context)!.axisDirection == AxisDirection.up + Scrollable.of(context).axisDirection == AxisDirection.up ? 10 : 0, ), Container( alignment: - Scrollable.of(context)!.axisDirection == AxisDirection.up + Scrollable.of(context).axisDirection == AxisDirection.up ? Alignment.bottomCenter : Alignment.topCenter, margin: - Scrollable.of(context)!.axisDirection == AxisDirection.up + Scrollable.of(context).axisDirection == AxisDirection.up ? EdgeInsets.only(bottom: 12.0) : EdgeInsets.only(top: 12.0), child: widget.idleIcon, diff --git a/lib/src/internals/indicator_wrap.dart b/lib/src/internals/indicator_wrap.dart index b3bfc221..7c29a298 100644 --- a/lib/src/internals/indicator_wrap.dart +++ b/lib/src/internals/indicator_wrap.dart @@ -35,10 +35,10 @@ abstract class RefreshIndicator extends StatefulWidget { const RefreshIndicator( {Key? key, - this.height: 60.0, - this.offset: 0.0, - this.completeDuration: const Duration(milliseconds: 500), - this.refreshStyle: RefreshStyle.Follow}) + this.height = 60.0, + this.offset = 0.0, + this.completeDuration = const Duration(milliseconds: 500), + this.refreshStyle = RefreshStyle.Follow}) : super(key: key); } @@ -56,8 +56,8 @@ abstract class LoadIndicator extends StatefulWidget { const LoadIndicator( {Key? key, this.onClick, - this.loadStyle: LoadStyle.ShowAlways, - this.height: 60.0}) + this.loadStyle = LoadStyle.ShowAlways, + this.height = 60.0}) : super(key: key); } @@ -257,7 +257,7 @@ abstract class RefreshIndicatorState the _onOffsetChange didn't callback,it will keep failed or success state. 2. As FrontStyle,when user dragging in 0~100 in refreshing state,it should be reset after the state change */ - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { if (!mounted) { return; } @@ -287,7 +287,7 @@ abstract class RefreshIndicatorState } else if (mode == RefreshStatus.twoLevelOpening) { floating = true; refresherState!.setCanDrag(false); - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { if (!mounted) return; activity!.resetActivity(); _position! @@ -333,7 +333,7 @@ abstract class RefreshIndicatorState child: RotatedBox( child: buildContent(context, mode), quarterTurns: needReverseAll() && - Scrollable.of(context)!.axisDirection == AxisDirection.up + Scrollable.of(context).axisDirection == AxisDirection.up ? 10 : 0, ), @@ -389,8 +389,8 @@ abstract class LoadIndicatorState extends State } // this line for patch bug temporary:indicator disappears fastly when load more complete - if (mounted) Scrollable.of(context)!.position.correctBy(0.00001); - WidgetsBinding.instance!.addPostFrameCallback((_) { + if (mounted) Scrollable.of(context).position.correctBy(0.00001); + WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted && _position?.outOfRange == true) { activity!.delegate.goBallistic(0); } @@ -624,7 +624,7 @@ mixin IndicatorStateMixin on State { RefreshNotifier? newMode = V == RefreshStatus ? refresher!.controller.headerMode as RefreshNotifier? : refresher!.controller.footerMode as RefreshNotifier?; - final ScrollPosition newPosition = Scrollable.of(context)!.position; + final ScrollPosition newPosition = Scrollable.of(context).position; if (newMode != _mode) { _mode?.removeListener(_handleModeChange); _mode = newMode; @@ -686,7 +686,7 @@ mixin IndicatorStateMixin on State { } /// head Indicator exposure interface -abstract class RefreshProcessor { +mixin RefreshProcessor { /// out of edge offset callback void onOffsetChange(double offset) {} @@ -708,7 +708,7 @@ abstract class RefreshProcessor { } /// footer Indicator exposure interface -abstract class LoadingProcessor { +mixin LoadingProcessor { void onOffsetChange(double offset) {} void onModeChange(LoadStatus? mode) {} diff --git a/lib/src/internals/refresh_localizations.dart b/lib/src/internals/refresh_localizations.dart index 49680492..3ff45106 100644 --- a/lib/src/internals/refresh_localizations.dart +++ b/lib/src/internals/refresh_localizations.dart @@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; /// Implementation of localized strings for the [ClassicHeader],[ClassicFooter],[TwoLevelHeader] /// diff --git a/lib/src/internals/refresh_physics.dart b/lib/src/internals/refresh_physics.dart index 3ba5857c..0e56ee7d 100644 --- a/lib/src/internals/refresh_physics.dart +++ b/lib/src/internals/refresh_physics.dart @@ -5,13 +5,12 @@ */ // ignore_for_file: INVALID_USE_OF_PROTECTED_MEMBER // ignore_for_file: INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER -import 'package:flutter/physics.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'dart:math' as math; import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'package:pull_to_refresh/src/internals/slivers.dart'; + /// a scrollPhysics for config refresh scroll effect,enable viewport out of edge whatever physics it is /// in [ClampingScrollPhysics], it doesn't allow to flip out of edge,but in RefreshPhysics,it will allow to do that, @@ -297,7 +296,7 @@ class RefreshPhysics extends ScrollPhysics { controller!.headerMode!.value == RefreshStatus.twoLeveling ? 0.0 : position.maxScrollExtent, - tolerance: tolerance, + tolerance: Tolerance.defaultTolerance, ); } return super.createBallisticSimulation(position, velocity); diff --git a/lib/src/internals/slivers.dart b/lib/src/internals/slivers.dart index e004286b..e7949cc8 100644 --- a/lib/src/internals/slivers.dart +++ b/lib/src/internals/slivers.dart @@ -182,7 +182,7 @@ class RenderSliverRefresh extends RenderSliverSingleBoxAdapter { if (_updateFlag) { // ignore_for_file: INVALID_USE_OF_PROTECTED_MEMBER // ignore_for_file: INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER - Scrollable.of(context)!.position.activity!.applyNewDimensions(); + Scrollable.of(context).position.activity!.applyNewDimensions(); _updateFlag = false; } // The new layout extent this sliver should now have. diff --git a/lib/src/smart_refresher.dart b/lib/src/smart_refresher.dart index af8fecce..e6b5b038 100644 --- a/lib/src/smart_refresher.dart +++ b/lib/src/smart_refresher.dart @@ -4,12 +4,10 @@ createTime:2018-05-01 11:39 */ +import 'package:pull_to_refresh/src/internals/slivers.dart'; import 'package:flutter/gestures.dart'; -import 'package:flutter/physics.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter/foundation.dart'; -import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'package:pull_to_refresh/src/internals/slivers.dart'; import 'internals/indicator_wrap.dart'; import 'internals/refresh_physics.dart'; import 'indicator/classic_indicator.dart'; @@ -213,9 +211,9 @@ class SmartRefresher extends StatefulWidget { this.child, this.header, this.footer, - this.enablePullDown: true, - this.enablePullUp: false, - this.enableTwoLevel: false, + this.enablePullDown = true, + this.enablePullUp = false, + this.enableTwoLevel = false, this.onRefresh, this.onLoading, this.onTwoLevel, @@ -241,9 +239,9 @@ class SmartRefresher extends StatefulWidget { Key? key, required this.controller, required this.builder, - this.enablePullDown: true, - this.enablePullUp: false, - this.enableTwoLevel: false, + this.enablePullDown = true, + this.enablePullUp = false, + this.enableTwoLevel = false, this.onRefresh, this.onLoading, this.onTwoLevel, @@ -424,36 +422,35 @@ class SmartRefresherState extends State { dragStartBehavior: dragStartBehavior ?? DragStartBehavior.start, reverse: reverse ?? false, ); - } else if (childView is Scrollable) { - body = Scrollable( - physics: _getScrollPhysics( - conf, childView.physics ?? AlwaysScrollableScrollPhysics()), - controller: childView.controller, - axisDirection: childView.axisDirection, - semanticChildCount: childView.semanticChildCount, - dragStartBehavior: childView.dragStartBehavior, - viewportBuilder: (context, offset) { - Viewport viewport = - childView.viewportBuilder(context, offset) as Viewport; - if (widget.enablePullDown) { - viewport.children.insert( - 0, - widget.header ?? - (conf?.headerBuilder != null - ? conf?.headerBuilder!() - : null) ?? - defaultHeader); - } - //insert header or footer - if (widget.enablePullUp) { - viewport.children.add(widget.footer ?? - (conf?.footerBuilder != null ? conf?.footerBuilder!() : null) ?? - defaultFooter); - } - return viewport; - }, - ); - } + } else body = Scrollable( + physics: _getScrollPhysics( + conf, childView.physics ?? AlwaysScrollableScrollPhysics()), + controller: childView.controller, + axisDirection: childView.axisDirection, + semanticChildCount: childView.semanticChildCount, + dragStartBehavior: childView.dragStartBehavior, + viewportBuilder: (context, offset) { + Viewport viewport = + childView.viewportBuilder(context, offset) as Viewport; + if (widget.enablePullDown) { + viewport.children.insert( + 0, + widget.header ?? + (conf?.headerBuilder != null + ? conf?.headerBuilder!() + : null) ?? + defaultHeader); + } + //insert header or footer + if (widget.enablePullUp) { + viewport.children.add(widget.footer ?? + (conf?.footerBuilder != null ? conf?.footerBuilder!() : null) ?? + defaultFooter); + } + return viewport; + }, + ); + return body; } @@ -510,7 +507,7 @@ class SmartRefresherState extends State { void initState() { // TODO: implement initState if (widget.controller.initialRefresh) { - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { // if mounted,it avoid one situation: when init done,then dispose the widget before build. // this situation mostly TabBarView if (mounted) widget.controller.requestRefresh(); @@ -596,7 +593,7 @@ class RefreshController { /// /// initialLoadStatus: footerMode default value RefreshController( - {this.initialRefresh: false, + {this.initialRefresh = false, RefreshStatus? initialRefreshStatus, LoadStatus? initialLoadStatus}) { this.headerMode = @@ -651,10 +648,10 @@ class RefreshController { /// make the header enter refreshing state,and callback onRefresh Future? requestRefresh( - {bool needMove: true, - bool needCallback: true, - Duration duration: const Duration(milliseconds: 500), - Curve curve: Curves.linear}) { + {bool needMove = true, + bool needCallback = true, + Duration duration = const Duration(milliseconds: 500), + Curve curve = Curves.linear}) { assert(position != null, 'Try not to call requestRefresh() before build,please call after the ui was rendered'); if (isRefresh) return Future.value(); @@ -666,6 +663,7 @@ class RefreshController { if (needMove && _refresherState!.mounted) _refresherState!.setCanDrag(false); + if (needMove) { return Future.delayed(const Duration(milliseconds: 50)).then((_) async { // - 0.0001 is for NestedScrollView. @@ -687,7 +685,7 @@ class RefreshController { }); }); } else { - Future.value().then((_) { + return Future.value().then((_) { headerMode!.value = RefreshStatus.refreshing; }); } @@ -695,8 +693,8 @@ class RefreshController { /// make the header enter refreshing state,and callback onRefresh Future requestTwoLevel( - {Duration duration: const Duration(milliseconds: 300), - Curve curve: Curves.linear}) { + {Duration duration = const Duration(milliseconds: 300), + Curve curve = Curves.linear}) { assert(position != null, 'Try not to call requestRefresh() before build,please call after the ui was rendered'); headerMode!.value = RefreshStatus.twoLevelOpening; @@ -708,10 +706,10 @@ class RefreshController { /// make the footer enter loading state,and callback onLoading Future? requestLoading( - {bool needMove: true, - bool needCallback: true, - Duration duration: const Duration(milliseconds: 300), - Curve curve: Curves.linear}) { + {bool needMove = true, + bool needCallback = true, + Duration duration = const Duration(milliseconds: 300), + Curve curve = Curves.linear}) { assert(position != null, 'Try not to call requestLoading() before build,please call after the ui was rendered'); if (isLoading) return Future.value(); @@ -750,7 +748,7 @@ class RefreshController { /// request complete,the header will enter complete state, /// /// resetFooterState : it will set the footer state from noData to idle - void refreshCompleted({bool resetFooterState: false}) { + void refreshCompleted({bool resetFooterState = false}) { headerMode?.value = RefreshStatus.completed; if (resetFooterState) { resetNoData(); @@ -759,10 +757,10 @@ class RefreshController { /// end twoLeveling,will return back first floor Future? twoLevelComplete( - {Duration duration: const Duration(milliseconds: 500), - Curve curve: Curves.linear}) { + {Duration duration = const Duration(milliseconds: 500), + Curve curve = Curves.linear}) { headerMode?.value = RefreshStatus.twoLevelClosing; - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { position! .animateTo(0.0, duration: duration, curve: curve) .whenComplete(() { @@ -785,7 +783,7 @@ class RefreshController { /// after data returned,set the footer state to idle void loadComplete() { // change state after ui update,else it will have a bug:twice loading - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { footerMode?.value = LoadStatus.idle; }); } @@ -793,14 +791,14 @@ class RefreshController { /// If catchError happen,you may call loadFailed indicate fetch data from network failed void loadFailed() { // change state after ui update,else it will have a bug:twice loading - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { footerMode?.value = LoadStatus.failed; }); } /// load more success without error,but no data returned void loadNoData() { - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { footerMode?.value = LoadStatus.noMore; }); } @@ -905,29 +903,29 @@ class RefreshConfiguration extends InheritedWidget { required this.child, this.headerBuilder, this.footerBuilder, - this.dragSpeedRatio: 1.0, + this.dragSpeedRatio = 1.0, this.shouldFooterFollowWhenNotFull, - this.enableScrollWhenTwoLevel: true, - this.enableLoadingWhenNoData: false, - this.enableBallisticRefresh: false, - this.springDescription: const SpringDescription( + this.enableScrollWhenTwoLevel = true, + this.enableLoadingWhenNoData = false, + this.enableBallisticRefresh = false, + this.springDescription = const SpringDescription( mass: 2.2, stiffness: 150, damping: 16, ), - this.enableScrollWhenRefreshCompleted: false, - this.enableLoadingWhenFailed: true, - this.twiceTriggerDistance: 150.0, - this.closeTwoLevelDistance: 80.0, - this.skipCanRefresh: false, + this.enableScrollWhenRefreshCompleted = false, + this.enableLoadingWhenFailed = true, + this.twiceTriggerDistance = 150.0, + this.closeTwoLevelDistance = 80.0, + this.skipCanRefresh = false, this.maxOverScrollExtent, - this.enableBallisticLoad: true, + this.enableBallisticLoad = true, this.maxUnderScrollExtent, - this.headerTriggerDistance: 80.0, - this.footerTriggerDistance: 15.0, - this.hideFooterWhenNotFull: false, - this.enableRefreshVibrate: false, - this.enableLoadMoreVibrate: false, + this.headerTriggerDistance = 80.0, + this.footerTriggerDistance = 15.0, + this.hideFooterWhenNotFull = false, + this.enableRefreshVibrate = false, + this.enableLoadMoreVibrate = false, this.topHitBoundary, this.bottomHitBoundary}) : assert(headerTriggerDistance > 0), diff --git a/pubspec.yaml b/pubspec.yaml index 0c256250..e0b7e331 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,8 +4,7 @@ version: 2.0.0 homepage: https://github.com/peng8350/flutter_pulltorefresh environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=2.0.0" + sdk: '>=3.2.3 <4.0.0' dependencies: flutter: