我正在使用此包装。 该软件包是提供给flutter滚动组件下拉刷新和拉升负载的小部件。支持android和ios 打包网址为https://pub.dartlang.org/packages/pull_to_refresh 但是这个软件包有一个错误!
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class Example1 extends StatefulWidget {
@override
_Example1State createState() => new _Example1State();
}
class _Example1State extends State<Example1> {
// RefreshMode refreshing = RefreshMode.idle;
// LoadMode loading = LoadMode.idle;
RefreshController _refreshController;
List<Widget> data = [];
void _getDatas() {
for (int i = 0; i < 14; i++) {
data.add(new Card(
margin:
new EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
child: new Center(
child: new Text('Data $i'),
),
));
}
}
void enterRefresh() {
_refreshController.requestRefresh(true);
}
void _onOffsetCallback(bool isUp, double offset) {
// if you want change some widgets state ,you should rewrite the callback
}
@override
void initState() {
// TODO: implement initState
_getDatas();
_refreshController = new RefreshController();
super.initState();
}
Widget _headerCreate(BuildContext context, int mode) {
return new ClassicIndicator(
mode: mode,
refreshingText: "",
idleIcon: new Container(),
idleText: "Load more...",
);
}
// Widget _footerCreate(BuildContext context,int mode){
// return new ClassicIndicator(mode: mode);
// }
@override
Widget build(BuildContext context) {
return new Container(
child: new SmartRefresher(
enablePullDown: true,
enablePullUp: true,
controller: _refreshController,
onRefresh: (up) {
if (up)
new Future.delayed(const Duration(milliseconds: 2009))
.then((val) {
data.add(new Card(
margin: new EdgeInsets.only(
left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
child: new Center(
child: new Text('Data '),
),
));
_refreshController.scrollTo(_refreshController.scrollController.offset+100.0);
_refreshController.sendBack(true, RefreshStatus.idle);
setState(() {});
// refresher.sendStatus(RefreshStatus.completed);
});
else {
new Future.delayed(const Duration(milliseconds: 2009))
.then((val) {
data.add(new Card(
margin: new EdgeInsets.only(
left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
child: new Center(
child: new Text('Data '),
),
));
setState(() {});
_refreshController.sendBack(false, RefreshStatus.idle);
});
}
},
onOffsetChange: _onOffsetCallback,
child: new ListView.builder(
reverse: true,
itemExtent: 100.0,
itemCount: data.length,
itemBuilder: (context, index) => new Item(),
)));
}
}
class Item extends StatefulWidget {
@override
_ItemState createState() => new _ItemState();
}
class _ItemState extends State<Item> {
@override
Widget build(BuildContext context) {
return new Card(
margin:
new EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
child: new Center(
child: new Text('Data'),
),
);
}
@override
void dispose() {
// TODO: implement dispose
print("销毁");
super.dispose();
}
}
当我点击状态栏时,无法滚动到顶部! 我尝试调试此程序包,发现在smart_refresher.dart文件的第344行中,只需注释控制器属性并滚动回顶部,就像这样
但是下拉刷新操作会出现错误。
flutter: ══╡ EXCEPTION CAUGHT BY ANIMATION LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown while notifying listeners for AnimationController:
flutter: ScrollController not attached to any scroll views.
flutter: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12:
flutter: '_positions.isNotEmpty'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:110:12)
flutter: #3 ScrollController.offset (package:flutter/src/widgets/scroll_controller.dart:118:24)
flutter: #4 _SmartRefresherState._buildWrapperByConfig.<anonymous closure> (package:pull_to_refresh/src/smart_refresher.dart:291:42)
flutter: #5 RefreshWrapperState._handleOffsetCallBack (package:pull_to_refresh/src/internals/indicator_wrap.dart:163:14)
flutter: #6 _AnimationController&Animation&AnimationEagerListenerMixin&AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:124:19)
flutter: #7 AnimationController.value= (package:flutter/src/animation/animation_controller.dart:351:5)
flutter: #8 RefreshWrapperState._handleModeChange (package:pull_to_refresh/src/internals/indicator_wrap.dart:171:25)
flutter: #9 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:208:21)
flutter: #10 ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:264:5)
flutter: #11 Wrapper.mode= (package:pull_to_refresh/src/internals/indicator_wrap.dart:31:43)
flutter: #12 RefreshWrapperState.onDragEnd (package:pull_to_refresh/src/internals/indicator_wrap.dart:157:14)
flutter: #13 _SmartRefresherState._handleScrollEnd (package:pull_to_refresh/src/smart_refresher.dart:120:40)
flutter: #14 _SmartRefresherState._dispatchScrollEvent (package:pull_to_refresh/src/smart_refresher.dart:133:16)
flutter: #15 NotificationListener._dispatch (package:flutter/src/widgets/notification_listener.dart:125:27)
flutter: #16 Notification.visitAncestor (package:flutter/src/widgets/notification_listener.dart:45:20)
flutter: #17 _ScrollNotification&LayoutChangedNotification&ViewportNotificationMixin.visitAncestor (package:flutter/src/widgets/scroll_notification.dart:31:18)
flutter: #18 Element.visitAncestorElements (package:flutter/src/widgets/framework.dart:3344:39)
flutter: #19 Notification.dispatch (package:flutter/src/widgets/notification_listener.dart:59:12)
flutter: #20 ScrollActivity.dispatchScrollUpdateNotification (package:flutter/src/widgets/scroll_activity.dart:96:92)
flutter: #21 ScrollPosition.didUpdateScrollPositionBy (package:flutter/src/widgets/scroll_position.dart:654:14)
flutter: #22 ScrollPosition.setPixels (package:flutter/src/widgets/scroll_position.dart:219:9)
flutter: #23 ScrollPositionWithSingleContext.setPixels (package:flutter/src/widgets/scroll_position_with_single_context.dart:84:18)
flutter: #24 BallisticScrollActivity.applyMoveTo (package:flutter/src/widgets/scroll_activity.dart:547:21)
flutter: #25 BallisticScrollActivity._tick (package:flutter/src/widgets/scroll_activity.dart:534:10)
flutter: #26 _AnimationController&Animation&AnimationEagerListenerMixin&AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:124:19)
flutter: #27 AnimationController._tick (package:flutter/src/animation/animation_controller.dart:697:5)
flutter: #28 Ticker._tick (package:flutter/src/scheduler/ticker.dart:228:5)
flutter: #29 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #30 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:906:11)
flutter: #31 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:370:8)
flutter: #32 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:904:17)
flutter: #33 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:834:5)
flutter: #34 _invoke1 (dart:ui/hooks.dart:168:13)
flutter: #35 _beginFrame (dart:ui/hooks.dart:138:3)
flutter: (elided 2 frames from class _AssertionError)
flutter:
flutter: The AnimationController notifying listeners was:
flutter: AnimationController#96484(⏭ 1.000; paused)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: ScrollController not attached to any scroll views.
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.
#0 _AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:36:5)
#2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:110:12)
#3 ScrollController.offset (package:flutter/src/widgets/scroll_controller.dart:118:24)
#4 _Example1State.build.<anonymous closure>.<anonymous closure> (package:example/ui/Example1.dart:76:83)
#5 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#6 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#8 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#9 Future._complete (dart:as<…>
相关医生信息:
[✓] Flutter(在Mac OS X 10.13.6 17G65上为Channel dev,v0.11.6,语言环境
zh-Hans-CN)[✓] Android工具链-为Android设备开发
(Android SDK 28.0.3)[✓] iOS工具链-为iOS设备开发
(Xcode 10.1)[✓] Android Studio(3.2版)
[✓] VS代码(版本> 1.29.1)
[✓]已连接的设备(1个可用)
请帮助我解决此错误,谢谢。