我有一个使用RefreshIndicator的布局。它的 child 是CustomScrollView。但是,在调用onRefresh处理程序时,它将引发异常
[ERROR:../../lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (21060): NoSuchMethodError: The method 'call' was called on null.
E/flutter (21060): Receiver: null
E/flutter (21060): Tried calling: call()
E/flutter (21060): #0 Object._noSuchMethod (dart:core-patch/object_patch.dart:43)
E/flutter (21060): #1 Object.noSuchMethod (dart:core-patch/object_patch.dart:47)
E/flutter (21060): #2 new Future.sync (dart:async/future.dart:222)
E/flutter (21060): #3 MyHomePageState.handleRefresh (file:///home/swav/Git/flutter/status-app/lib/state/state.dart:49)
E/flutter (21060): #4 RefreshIndicatorState._show.<anonymous closure> (package:flutter/src/material/refresh_indicator.dart:319)
E/flutter (21060): #5 _RootZone.runUnary (dart:async/zone.dart:1371)
E/flutter (21060): #6 _FutureListener.handleValue (dart:async/future_impl.dart:129)
E/flutter (21060): #7 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:636)
E/flutter (21060): #8 _Future._propagateToListeners (dart:async/future_impl.dart:665)
E/flutter (21060): #9 _Future._completeWithValue (dart:async/future_impl.dart:478)
E/flutter (21060): #10 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:510)
E/flutter (21060): #11 _microtaskLoop (dart:async/schedule_microtask.dart:41)
E/flutter (21060): #12 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
有趣的是onRefresh成功完成。
同样,当RefreshIndicator的直接子代是Flex时,它也不会抱怨。
最佳答案
很难调试问题,因为您没有提供代码,但是从堆栈跟踪中可以看到,在handleRefresh
方法的state.dart的第49行中,您正在调用new Future.sync(null)
,它试图将null
作为功能。
当您需要完整的new Future.value(null)
和值Future
时,请尝试使用null
代替。但是,当返回的Future立即完成时,RefreshIndicator
并没有做很多事情。您可能想看看此example以获得有关如何使用RefreshIndicator
的灵感。
当 child 是Flex
时,可能没有抱怨,因为Flex
不会滚动。
关于dart - NoSuchMethod on RefreshIndicator,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44560641/