首页 > 解决方案 > Scrollcontroller in flutter error 发生异常

问题描述

我有两个屏幕,第一个从 wordpress 获取所有帖子,最后一个获取所有视频,我使用 ScollController 和 ListView 滚动数据

查看我的代码:

ScrollController _scrollController;

@override
  void initState() {
    _scrollController = new ScrollController();
    _scrollController.addListener(() {
      print(_scrollController.position.pixels);
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent - 10) {
        // if we are the bottom of the page
        fetchPosts();
        //millisecs += 1500;
        //super.initState();
      }
      super.initState();
    });
  }

  @override
  void dispose() {
    _scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) { ....

当我在屏幕一到二或屏幕二到一之间切换时

我收到此错误:

    Exception has occurred.
FlutterError (A ScrollController was used after being disposed.
Once you have called dispose() on a ScrollController, it can no longer be used.)

跟踪代码: 图像错误

在调试模式下在为 x86 构建的 Android SDK 上启动 lib\main.dart... 构建 build\app\outputs\apk\debug\app-debug.apk。D/EGL_emulation(8157):eglMakeCurrent:0xeeebd340:ver 3 1(tinfo 0xeee9b1d0)E/eglCodecCommon(8157):glUtilsParamSize:未知参数0x000082da E/eglCodecCommon(8157):glUtilsParamSize:未知参数0x200008 0x200008 49帧!应用程序可能在其主线程上做了太多工作。D/EGL_emulation(8157):eglMakeCurrent:0xeef21ce0:ver 3 1(tinfo 0xe6f286b0)D/(8157):HostConnection::get()新主机连接建立0xe7123880,tid 8184 D/EGL_emulation(8157):eglMakeCurrent:0xeeebd340:ver 3 1 (tinfo 0xe7103370) I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 200 I/flutter (8157): ══╡基金会图书馆捕获的例外╞═════════════════════════════════════════ ═══════════════ I/flutter(8157):在调度 ScrollController 的通知时引发以下断言:I/flutter(8157):'package:flutter/src/widgets/framework .dart':断言失败:第 1003 行 pos 12:I/flutter(8157):'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): I/flutter (8157): 要么断言表明框架本身有错误,要么我们应该提供大量 I/flutter (8157): 此错误消息中的更多信息可帮助您确定和修复根本原因。I/flutter (8157):在任何一种情况下,请通过在 GitHub 上提交错误报告此断言:I/flutter (8157):为 ScrollController 分派通知时引发了以下断言:I/flutter (8157): 'package:flutter/src/widgets/framework.dart': 断言失败: line 1003 pos 12: I/flutter (8157): '_debugLifecycleState = = _StateLifecycle.created':不正确。I/flutter (8157): I/flutter (8157): 要么断言表明框架本身有错误,要么我们应该提供大量 I/flutter (8157): 此错误消息中的更多信息可帮助您确定和修复根本原因。I/flutter (8157):在任何一种情况下,请通过在 GitHub 上提交错误报告此断言:I/flutter (8157):为 ScrollController 分派通知时引发了以下断言:I/flutter (8157): 'package:flutter/src/widgets/framework.dart': 断言失败: line 1003 pos 12: I/flutter (8157): '_debugLifecycleState = = _StateLifecycle.created':不正确。I/flutter (8157): I/flutter (8157): 要么断言表明框架本身有错误,要么我们应该提供大量 I/flutter (8157): 此错误消息中的更多信息可帮助您确定和修复根本原因。I/flutter (8157):在任何一种情况下,请通过在 GitHub 上提交错误报告此断言:I/flutter (8157):_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): I/flutter (8157): 要么断言表明框架本身有错误,要么我们应该提供大量 I/flutter (8157): 此错误消息中的更多信息可帮助您确定和修复根本原因。I/flutter (8157):在任何一种情况下,请通过在 GitHub 上提交错误报告此断言:I/flutter (8157):_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): I/flutter (8157): 要么断言表明框架本身有错误,要么我们应该提供大量 I/flutter (8157): 此错误消息中的更多信息可帮助您确定和修复根本原因。I/flutter (8157):在任何一种情况下,请通过在 GitHub 上提交错误报告此断言:I/flutter (8157): https://github.com/flutter/flutter/issues/new?template=BUG.md I/flutter (8157): I/flutter (8157): 当异常被抛出时,这是堆栈: I/flutter (8157): #2 State.initState (package:flutter/src/widgets/framework.dart: 1003:12)我/颤振(8157):#3 _PostsPage.initState。(package:flutter_wp2019/ui/PostsLatest.dart:42:13) I/flutter (8157): #4 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:208:21) I/flutter (8157) : #5 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:208:21) I/flutter (8157): #6 ScrollPosition.notifyListeners (package:flutter/src/widgets/scroll_position.dart:692: 11) I/flutter (8157): #7 ScrollPosition.setPixels (package:flutter/src/widgets/scroll_position.dart:218:9) I/flutter (8157): #8 ScrollPositionWithSingleContext.setPixels (package:flutter/src/widgets/scroll_position_with_single_context.dart:84:18) I/flutter (8157): #9 ScrollPositionWithSingleContext.applyUserOffset (package:flutter/src/widgets/scroll_position_with_single_context.dart:127:5 ) I/flutter (8157): #10 ScrollDragController.update (package:flutter/src/widgets/scroll_activity.dart:373:14) I/flutter (8157): #11 ScrollableState._handleDragUpdate (package:flutter/src/widgets /scrollable.dart:470:12) I/flutter (8157): #12 DragGestureRecognizer.acceptGesture。(package:flutter/src/gestures/monodrag.dart:176:48) I/flutter (8157): #13 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24) I/flutter ( 8157):#14 DragGestureRecognizer.acceptGesture(包:ui/hooks.dart:168:13) I/flutter (8157): #28 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5) I/flutter (8157): (从 _AssertionError 类中省略 2 帧) I/ flutter (8157): I/flutter (8157): ScrollController 发送通知是: I/flutter (8157): ScrollController#bcc47(one client, offset 21.4) I/flutter (8157): ════════ ══════════════════════════════════════════════════ ═════════════════════════════════════════════15/7╕:抛出异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 16 行 I/flutter (8157): 另一个异常被抛出:'package: flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/zygote (8157): 做部分代码缓存收集,code=29KB, data=23KB I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 断言失败: line 1003 位置 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 1 行 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 失败断言:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/zygote (8157): 代码缓存收集后, code=29KB, data=23KB I/zygote (8157): 将代码缓存容量增加到 128KB I/flutter(8157):引发另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':是不对。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 11 行 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 失败断言:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/zygote (8157):做部分代码缓存收集,code=59KB,data=40KB I/zygote(8157):代码缓存收集后,code=59KB,data=40KB I/zygote(8157):增加代码缓存容量至 256KB I/颤动(8157):30.00837053571422 I/颤动(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):42.86551339285711 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):55.72265625 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter (8157): 71.41741071428567 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework. dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):88.56863839285711 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):105.71986607142856 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):120.24285714285713 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:' _debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):117.38013392857141 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):110.24843749999997 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):93.09720982142858 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' :不是真的。I/flutter(8157):63.0888392857143 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):23.11116071428569 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):0.0 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。我/颤振(8157):1。4313616071428896 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):8.58816964285711 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):24.006696428571445 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/颤动(8157):41.15792410714289 I/颤动(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):64.00948660714289 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):85.4296875 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter (8157): 108.28125 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart' :断言失败:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):120.24285714285713 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):2.8376116071428896 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):7.131696428571445 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:' _debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):11.42578125 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):18.557477678571445 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):24.28292410714289 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):39.977678571428555 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):57.12890625 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):77.14285714285717 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/颤动(8157):97.13169642857144 I/颤动(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter(8157):115.71428571428572 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter(8157):120.24285714285713 I/flutter(8157):引发了另一个异常:'package:flutter/src/widgets/framework.dart':断言失败:第 1003 行 pos 12:'_debugLifecycleState == _StateLifecycle.created' : 不是真的。I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 200 I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 400 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 断言失败: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle .created':不是真的。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 22 行 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 失败断言:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 200 _debugLifecycleState == _StateLifecycle.created':不正确。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 22 行 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 失败断言:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 200 _debugLifecycleState == _StateLifecycle.created':不正确。I/chatty (8157): uid=10083(com.example.flutterwp2019) 1.ui 相同的 22 行 I/flutter (8157): 另一个异常被抛出:'package:flutter/src/widgets/framework.dart': 失败断言:第 1003 行第 12 行:'_debugLifecycleState == _StateLifecycle.created':不正确。I/flutter (8157): _morePages: false I/flutter (8157): statusCode: 200

图像错误

谢谢提前

标签: dartflutter

解决方案


super.initState()在错误的位置

@override
  void initState() {
    super.initState(); // <<< added

    _scrollController = new ScrollController();
    _scrollController.addListener(() {
      print(_scrollController.position.pixels);
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent - 10) {
        // if we are the bottom of the page
        fetchPosts();
        //millisecs += 1500;
        //super.initState();
      }
      // super.initState(); // <<< removed
    });

  }

推荐阅读