我有一个使用RefreshIndicator的布局。它的孩子是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时,它没有抱怨。
答案 0 :(得分:1)
很难调试你的问题,因为你没有提供你的代码,但是从堆栈跟踪中我可以看到,在handleRefresh
方法中,在state.dart的第49行,你正在调用{{1试图调用new Future.sync(null)
作为函数。
当您需要值null
的已完成new Future.value(null)
时,请尝试使用Future
。但是当返回的Future立即完成时,null
并没有做太多。您可能需要查看此example,了解如何使用RefreshIndicator
。
当孩子是RefreshIndicator
时,可能没有抱怨,因为Flex
不会滚动。