6

I have two screen , first one fetch all post from wordpress last one fetch all videos and i use ScollController with ListView to scroll data

look to my code :

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) { ....

when i tab between screen one to two or screen two to one

i get this error:

    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.)

trace code: image error

Launching lib\main.dart on Android SDK built for x86 in debug mode... Built build\app\outputs\apk\debug\app-debug.apk. D/EGL_emulation( 8157): eglMakeCurrent: 0xeeebd340: ver 3 1 (tinfo 0xeee9b1d0) E/eglCodecCommon( 8157): glUtilsParamSize: unknow param 0x000082da E/eglCodecCommon( 8157): glUtilsParamSize: unknow param 0x000082da I/Choreographer( 8157): Skipped 49 frames! The application may be doing too much work on its main thread. D/EGL_emulation( 8157): eglMakeCurrent: 0xeef21ce0: ver 3 1 (tinfo 0xe6f286b0) D/ ( 8157): HostConnection::get() New Host Connection established 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): ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════ I/flutter ( 8157): The following assertion was thrown while dispatching notifications for ScrollController: I/flutter ( 8157): 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: I/flutter ( 8157): '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): I/flutter ( 8157): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter ( 8157): more information in this error message to help you determine and fix the underlying cause. I/flutter ( 8157): In either case, please report this assertion by filing a bug on GitHub: I/flutter ( 8157): https://github.com/flutter/flutter/issues/new?template=BUG.md I/flutter ( 8157): I/flutter ( 8157): When the exception was thrown, this was the stack: I/flutter ( 8157): #2 State.initState (package:flutter/src/widgets/framework.dart:1003:12) I/flutter ( 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 (package:flutter/src/gestures/monodrag.dart:176:9) I/flutter ( 8157): #15 GestureArenaManager._resolveInFavorOf (package:flutter/src/gestures/arena.dart:263:12) I/flutter ( 8157): #16 GestureArenaManager._resolve (package:flutter/src/gestures/arena.dart:222:9) I/flutter ( 8157): #17 GestureArenaEntry.resolve (package:flutter/src/gestures/arena.dart:52:12) I/flutter ( 8157): #18 OneSequenceGestureRecognizer.resolve (package:flutter/src/gestures/recognizer.dart:166:13) I/flutter ( 8157): #19 DragGestureRecognizer.handleEvent (package:flutter/src/gestures/monodrag.dart:154:11) I/flutter ( 8157): #20 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12) I/flutter ( 8157): #21 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11) I/flutter ( 8157): #22 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19) I/flutter ( 8157): #23 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22) I/flutter ( 8157): #24 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7) I/flutter ( 8157): #25 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7) I/flutter ( 8157): #26 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7) I/flutter ( 8157): #27 _invoke1 (dart:ui/hooks.dart:168:13) I/flutter ( 8157): #28 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5) I/flutter ( 8157): (elided 2 frames from class _AssertionError) I/flutter ( 8157): I/flutter ( 8157): The ScrollController sending notification was: I/flutter ( 8157): ScrollController#bcc47(one client, offset 21.4) I/flutter ( 8157): ════════════════════════════════════════════════════════════════════════════════════════════════════ I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/chatty ( 8157): uid=10083(com.example.flutterwp2019) 1.ui identical 16 lines I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/zygote ( 8157): Do partial code cache collection, code=29KB, data=23KB I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/chatty ( 8157): uid=10083(com.example.flutterwp2019) 1.ui identical 1 line I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/zygote ( 8157): After code cache collection, code=29KB, data=23KB I/zygote ( 8157): Increasing code cache capacity to 128KB I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/chatty ( 8157): uid=10083(com.example.flutterwp2019) 1.ui identical 11 lines I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/zygote ( 8157): Do partial code cache collection, code=59KB, data=40KB I/zygote ( 8157): After code cache collection, code=59KB, data=40KB I/zygote ( 8157): Increasing code cache capacity to 256KB I/flutter ( 8157): 30.00837053571422 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 42.86551339285711 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 55.72265625 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 71.41741071428567 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 88.56863839285711 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 105.71986607142856 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 120.24285714285713 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 117.38013392857141 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 110.24843749999997 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 93.09720982142858 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 63.0888392857143 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 23.11116071428569 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 0.0 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 1.4313616071428896 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 8.58816964285711 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 24.006696428571445 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 41.15792410714289 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 64.00948660714289 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 85.4296875 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 108.28125 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 120.24285714285713 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 2.8376116071428896 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 7.131696428571445 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 11.42578125 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 18.557477678571445 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 24.28292410714289 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 39.977678571428555 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 57.12890625 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 77.14285714285717 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 97.13169642857144 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 115.71428571428572 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): 120.24285714285713 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): _morePages: false I/flutter ( 8157): statusCode: 200 I/flutter ( 8157): _morePages: false I/flutter ( 8157): statusCode: 400 I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/chatty ( 8157): uid=10083(com.example.flutterwp2019) 1.ui identical 22 lines I/flutter ( 8157): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1003 pos 12: '_debugLifecycleState == _StateLifecycle.created': is not true. I/flutter ( 8157): _morePages: false I/flutter ( 8157): statusCode: 200

image error

Thanks Advance

3
  • What line points the stack trace to as cause for the exception? Commented Jan 14, 2019 at 15:24
  • How make a trace code by flutter run -v or what? Commented Jan 15, 2019 at 13:24
  • There shouldn't be anything to do. Just post the full error output. Commented Jan 15, 2019 at 13:32

2 Answers 2

8

super.initState() is on the wrong location

@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
    });

  }
Sign up to request clarification or add additional context in comments.

8 Comments

Can you please update your answer with the code you have now. The old code is definitely wrong because super.initState() there is only called when _scrollController calls the listener.
what about dispose @override void dispose() { _scrollController.dispose(); super.dispose(); }
Looks fine to me.
Thanks Günter Zöchbauer, now it work fine ,But I want to ask if you should override dispose method to dispose state and ScrollController or not ?
If this answer fixes your issue please mark it as correct so that future users who face the same issue can easily find it.
|
0

Add this into the widget where you are initializing the scroll controller:

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

and move the super.init() above the intialization

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.