Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_debugUltimatePreviousSiblingOf(after, equals: _firstChild) is not true. #11895

Closed
megamattron opened this issue Sep 1, 2017 · 77 comments · Fixed by #21350
Closed

_debugUltimatePreviousSiblingOf(after, equals: _firstChild) is not true. #11895

megamattron opened this issue Sep 1, 2017 · 77 comments · Fixed by #21350
Assignees
Labels
c: crash Stack traces logged to the console customer: crowd Affects or could affect many people, though not necessarily a specific customer. customer: mulligan (g3) f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. waiting for PR to land (fixed) A fix is in flight

Comments

@megamattron
Copy link

Steps to Reproduce

I have a PageView that contains the top level widgets for my app, with switching between them controlled by a BottomNavBar. As per @Hixie's advice in the chat, I am adding AutomaticKeepAliveClientMixin to these top level widgets so the PageView won't recycle them and will preserve state. After I added this to the main widget that contains a network loaded ListView, on occasion when switching back to this ListView from another tab I get this failed assertion in the framework.

Logs

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building NotificationListener<KeepAliveNotification>:
'package:flutter/src/rendering/object.dart': Failed assertion: line 3031 pos 14:
'_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new
When the exception was thrown, this was the stack:
#2      RenderSliver&ContainerRenderObjectMixin._insertIntoChildList (package:flutter/src/rendering/object.dart:3031:14)
#3      RenderSliver&ContainerRenderObjectMixin.insert (package:flutter/src/rendering/object.dart:3065:5)
#4      RenderSliverMultiBoxAdaptor.insert (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:193:17)
#5      SliverMultiBoxAdaptorElement.insertChildRenderObject (package:flutter/src/widgets/sliver.dart:840:18)
#6      RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:4380:35)
#7      RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4151:5)
#8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4515:16)
#9      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2882:14)
#10     Element.updateChild (package:flutter/src/widgets/framework.dart:2685:12)
#11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#12     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#13     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3514:5)
#14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3509:5)
#15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2882:14)
#16     Element.updateChild (package:flutter/src/widgets/framework.dart:2685:12)
#17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#18     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#19     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3514:5)
#20     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3509:5)
#21     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:3827:16)
#22     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2882:14)
#23     Element.updateChild (package:flutter/src/widgets/framework.dart:2685:12)
#24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#25     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#26     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3514:5)
#27     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3652:22)
#28     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3509:5)
#29     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2882:14)
#30     Element.updateChild (package:flutter/src/widgets/framework.dart:2685:12)
#31     SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:696:34)
#32     SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:665:7)
#33     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#34     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4250:32)
#35     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4631:17)
#36     _ViewportElement.update (package:flutter/src/widgets/viewport.dart:150:17)
#37     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#38     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#39     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#40     ProxyElement.update (package:flutter/src/widgets/framework.dart:3781:5)
#41     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#42     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4523:14)
#43     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#44     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4523:14)
#45     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#46     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4523:14)
#47     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#48     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#49     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#50     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#51     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#52     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#53     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#54     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#55     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#56     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#57     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#58     StatelessElement.update (package:flutter/src/widgets/framework.dart:3596:5)
#59     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#60     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#61     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#62     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#63     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#64     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#65     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#66     ProxyElement.update (package:flutter/src/widgets/framework.dart:3781:5)
#67     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#68     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4250:32)
#69     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4631:17)
#70     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#71     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#72     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#73     ProxyElement.update (package:flutter/src/widgets/framework.dart:3781:5)
#74     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#75     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#76     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#77     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#78     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#79     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4523:14)
#80     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#81     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#82     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#83     StatelessElement.update (package:flutter/src/widgets/framework.dart:3596:5)
#84     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#85     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4523:14)
#86     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#87     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#88     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#89     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#90     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#91     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#92     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#93     StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#94     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#95     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#96     Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#97     ProxyElement.update (package:flutter/src/widgets/framework.dart:3781:5)
#98     Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#99     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#100    Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#101    ProxyElement.update (package:flutter/src/widgets/framework.dart:3781:5)
#102    Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#103    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#104    Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#105    StatefulElement.update (package:flutter/src/widgets/framework.dart:3671:5)
#106    Element.updateChild (package:flutter/src/widgets/framework.dart:2674:15)
#107    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3546:16)
#108    Element.rebuild (package:flutter/src/widgets/framework.dart:3435:5)
#109    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2260:33)
#110    BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:503:20)
#111    BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:189:5)
#112    BindingBase&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:695:15)
#113    BindingBase&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:643:9)
#114    _invoke (file:///b/build/slave/Mac_Engine/build/src/flutter/lib/ui/hooks.dart:86)
#115    _drawFrame (file:///b/build/slave/Mac_Engine/build/src/flutter/lib/ui/hooks.dart:75)
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 3031 pos 14: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 3031 pos 14: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3437 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
Analyzing /Users/matt/code/flutter/kudos...
  lint • Don't import implementation files from another package at lib/feed.dart:5:8 • implementation_imports
  lint • Close instances of `dart.core.Sink` at lib/feed.dart:26:26 • close_sinks
  lint • Don't explicitly initialize variables to null at lib/loading_list_view.dart:23:5 • avoid_init_to_null
  lint • Don't import implementation files from another package at lib/post.dart:3:8 • implementation_imports
  hint • Unused import at lib/application.dart:4:8 • unused_import
  hint • Unused import at lib/feed.dart:2:8 • unused_import
  hint • Unused import at lib/feed.dart:5:8 • unused_import
  hint • Unused import at lib/feed.dart:7:8 • unused_import
  hint • Unused import at lib/feed.dart:12:8 • unused_import
  hint • Unused import at lib/feed.dart:13:8 • unused_import
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/feed.dart:29:8 • must_call_super
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/feed.dart:40:8 • must_call_super
  hint • The type parameter 'widgetAdapter' is annotated with @required but only named parameters without default value can be annotated with it at lib/loading_list_view.dart:23:5 • invalid_required_param
  hint • Unused import at lib/main.dart:6:8 • unused_import
  hint • The value of the field '_counter' isn't used at lib/main.dart:56:7 • unused_field
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/main.dart:63:8 • must_call_super
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/main.dart:71:8 • must_call_super
  hint • The method '_incrementCounter' isn't used at lib/main.dart:76:8 • unused_element
  hint • Unused import at lib/post.dart:7:8 • unused_import
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/post.dart:10:7 • must_be_immutable
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/post.dart:34:7 • must_be_immutable
  hint • The value of the local variable 'plainText' isn't used at lib/post.dart:71:10 • unused_local_variable
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/post.dart:112:7 • must_be_immutable
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/post.dart:160:7 • must_be_immutable
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/profile.dart:10:7 • must_be_immutable
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/profile.dart:27:10 • must_call_super
  hint • This class inherits from a class marked as @immutable, and therefore should be immutable (all instance fields must be final) at lib/profile.dart:145:7 • must_be_immutable
  hint • The class '_KudosEarned' isn't used at lib/profile.dart:218:7 • unused_element
  hint • Unused import at lib/send_photo.dart:5:8 • unused_import
  hint • Unused import at lib/usersearch.dart:6:8 • unused_import
  hint • Unused import at lib/usersearch.dart:7:8 • unused_import
  hint • This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method at lib/usersearch.dart:25:10 • must_call_super
32 issues found.

Flutter Doctor

[✓] Flutter (on Mac OS X 10.12.6 16G29, locale en-US, channel alpha)
    • Flutter at /Users/matt/code/flutter/flutter
    • Framework revision b156a0f054 (3 weeks ago), 2017-08-11 22:01:40 -0700
    • Engine revision fef7d827d6
    • Tools Dart version 1.25.0-dev.9.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
    • Android SDK at /Users/matt/code/android/android
    • Platform android-25, build-tools 25.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] iOS toolchain - develop for iOS devices (Xcode 8.3.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 8.3.3, Build version 8E3004b
    • ios-deploy 1.9.1
    • CocoaPods version 1.3.1

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2017.2.2)
    • Flutter plugin version 16.0
    • Dart plugin version 172.3757.55

[✓] Connected devices
    • iPhone 6s • 3DF999CB-1CD6-4649-8187-DDEFBDB14DFA • ios • iOS 10.3 (simulator)

For more information about diagnosing and reporting Flutter bugs, please see https://flutter.io/bug-reports/.

@Hixie Hixie added this to the 4: Next milestone milestone Sep 1, 2017
@Hixie Hixie added f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. labels Sep 1, 2017
@Hixie
Copy link
Contributor

Hixie commented Sep 1, 2017

Yikes, that's not a good sign.

@TonyDowney
Copy link

TonyDowney commented Sep 15, 2017

Also encountered this today. Seemed to be linked to putting focus on a node that was currently offscreen. This main.dart file should reproduce it:

import 'package:flutter/material.dart';

void main() {
  runApp(new Test11895Body());
}

class Test11895Body extends StatefulWidget{
  Test11895BodyState createState() => new Test11895BodyState();
}

class Test11895BodyState extends State<Test11895Body>{
  List<String> model = ['Focus on this textfield', 'Keep focused on the first textfield', 'Scroll down and continue adding more cards with the button below'];

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Bug #11895'),
        ),
        body: new ListView(
          primary:true,
          children: buildNoteCards(),
        ),
      ),
    );
  }

  List<Widget> buildNoteCards(){
    List<Widget> notes = new List<Widget>();
    for (int i = 0; i < model.length; i++){
      notes.add(new Card(
        child: new Container(
          constraints: new BoxConstraints(minHeight: 150.0),
          child: new TextField(
            controller: new TextEditingController(text: model[i]),
            maxLines: 5,
          ),
        ),
      )
      );
    }

    notes.add(
      new GestureDetector(
        onTap: _generateNewNote,
        child: new Container(
          child: new Card(
            child: new Icon(Icons.note_add, size:30.0),
          ),
        ),
      ),
    );
    return notes;
  }

  void _generateNewNote(){
    setState((){
      model.add('Keep going... note # ${model.length + 1}');
    });
  }

}

@Hixie
Copy link
Contributor

Hixie commented Jun 12, 2018

See also https://gist.github.com/rmarau/baa31a9c4032de388a2b7777c8bae27e for another repro.

@Hixie
Copy link
Contributor

Hixie commented Jun 12, 2018

I'm marking it customer critical because so many people are hitting it.

@Hixie Hixie added the customer: crowd Affects or could affect many people, though not necessarily a specific customer. label Jun 12, 2018
@bdytx5
Copy link

bdytx5 commented Jun 27, 2018

Anyone figure this out? I'm experiencing it with the tab bar, textfield, and listview....

@hillelcoren
Copy link
Member

I also ran into problems using AutomaticKeepAliveClientMixin with more than two tabs. In the end we replaced it by lifting our state higher in the widget hierarchy. You can read more about it here. Hope it helps...

@mralexsaavedra
Copy link

Any solution?

@jonasbark
Copy link

@mralexsaavedra is the error only occuring when the keyboard is opened / a textfield is focused?
If so, there's a workaround here: #12317 (comment)

@mralexsaavedra
Copy link

@jonasbark In my case the problem is the following:
I have a tabview with three tabs. Each tab has its own key but since the tabview is intaned twice it gives me an error of multiple GlobalKey.

@SteveAlexander
Copy link

I'm seeing this when using AutomaticKeepAliveClientMixin with several tabs. If I tap on neighbour tabs — the tabs immediately to the left or right of the one currently selected — then it doesn't crash. But if I go to a non-neighbour, say tab 1 to tab 3, then it reliably crashes.

@hillelcoren
Copy link
Member

@SteveAlexander I see the exact same problem, I had created a separate issue for it (#18350) but it looks like it's the same problem.

@SteveAlexander
Copy link

Here's a minimal example that reproduces the crash for me:
https://gist.github.com/SteveAlexander/92a2f11584456e529f67e1453dd18063

To reproduce, run the app, tap the "baz" tab, then tap back to "foo".

@Hixie
Copy link
Contributor

Hixie commented Jul 3, 2018

cc @HansMuller since this occurs with tabs in particular

@dnfield
Copy link
Contributor

dnfield commented Aug 31, 2018

Root cause of remaining issue is that RenderSliverList is losing track of leading children that are or come before a kept alive child. Have a more focused repro, working on the fix.

@nailgilaziev
Copy link

nailgilaziev commented Sep 1, 2018

I read a thread and can't find a solution. Does it exist for this issue?
If you switch to a last tab after app start, error occur.

import 'package:flutter/material.dart';

void main() => runApp(new TabBarDemo());

class TabBarDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 4,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(text: "1"),
                Tab(text: "2"),
                Tab(text: "3"),
                Tab(text: "4"),
              ],
            ),
            title: Text('Select last tab'),
          ),
          body: TabBarView(
            children: [
              TabContent(),
              TabContent(),
              TabContent(),
              TabContent(),
            ],
          ),
        ),
      ),
    );
  }
}

class TabContent extends StatefulWidget {

  @override
  _TabContentState createState() => _TabContentState();
}

class _TabContentState extends State<TabContent>
    with AutomaticKeepAliveClientMixin<TabContent>
{
  @override
  bool get wantKeepAlive => true;


  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

error stacktrace here https://pastebin.com/gAU5gyYn

flutter version

Flutter 0.7.3-pre.27 • channel master • https://github.com/flutter/flutter.git
Framework • revision 11d49a2db4 (3 days ago) • 2018-09-01 04:06:46 -0700
Engine • revision 017dafd426
Tools • Dart 2.1.0-dev.3.0.flutter-760a9690c2

@nailgilaziev
Copy link

previous code example is simplified, so if you wonder, why I use stateful widget for a Container only, here is a code example that uses stateful capabilities:
https://pastebin.com/D50LvsGE

@dnfield
Copy link
Contributor

dnfield commented Sep 4, 2018

@nailgilaziev - the PR I linked to this seems to resolve the issue, althrough I'm still seeing an exception get thrown.. Will look into it.

@krmao
Copy link

krmao commented Sep 7, 2018

  • it seems everything is work after some key changed, both android and ios @nailgilaziev may try my code bellow
import 'package:flutter/material.dart';

import './deal/deal.dart';
import './home/home.dart';
import './mine/mine.dart';
import './stockrights/stockrights.dart';

void main() => runApp(new App());

class App extends StatefulWidget {
  @override
  createState() => new AppState();
}

class AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        backgroundColor: Colors.white,
        body: new SafeArea(
          child: new MainTabWidget(),
          bottom: true,
        ),
      ),
      theme: new ThemeData(primaryColor: Colors.black, accentColor: Colors.lightBlue, primaryColorBrightness: Brightness.light, hintColor: Color(0xffdddddd), highlightColor: Color(0xffeeeeee), inputDecorationTheme: new InputDecorationTheme(labelStyle: new TextStyle(color: Color(0xffdddddd)))),
    );
  }
}

class MainTabWidget extends StatefulWidget {
  @override
  createState() => new MainTabWidgetState();
}

class MainTabWidgetState extends State<MainTabWidget> {
  PageController controller;
  var pages = [HomePage(), StockRightsPage(), DealPage(), MinePage()];
  var currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    controller = new PageController(initialPage: 0);
    return new Scaffold(
      body: new PageView.builder(
        itemBuilder: (BuildContext context, int index) {
          return pages[index];
        },
        itemCount: pages.length,
        onPageChanged: (index) {
          print("onPageChanged:$index");
          if (currentIndex != index) {
            setState(() {
              currentIndex = index;
            });
          }
        },
        controller: controller,
      ),
      bottomNavigationBar: bottomNavigationBar(),
    );
  }

  Widget bottomNavigationBar() {
    return new BottomNavigationBar(
      items: [
        new BottomNavigationBarItem(
            icon: new ImageIcon(
              new AssetImage("images/home_menu_home.png"),
              size: 48.0,
              color: currentIndex == 0 ? Color(0xff0c0435) : Color(0xffb6b6b6),
            ),
            title: new Container()),
        new BottomNavigationBarItem(
            icon: new ImageIcon(
              new AssetImage("images/home_menu_guquan.png"),
              size: 48.0,
              color: currentIndex == 1 ? Color(0xff0c0435) : Color(0xffb6b6b6),
            ),
            title: new Container()),
        new BottomNavigationBarItem(
            icon: new ImageIcon(
              new AssetImage("images/home_menu_deal.png"),
              size: 48.0,
              color: currentIndex == 2 ? Color(0xff0c0435) : Color(0xffb6b6b6),
            ),
            title: new Container()),
        new BottomNavigationBarItem(
            icon: new ImageIcon(
              new AssetImage("images/home_menu_mine.png"),
              size: 48.0,
              color: currentIndex == 3 ? Color(0xff0c0435) : Color(0xffb6b6b6),
            ),
            title: new Container())
      ],
      onTap: (index) {
        print("onTap:$index");
        controller.animateToPage(index, duration: Duration(milliseconds: 300), curve: Curves.linear);
      },
      currentIndex: 0,
      type: BottomNavigationBarType.fixed,
      fixedColor: Color(0xff0c0435),
    );
  }
}
  • the key is
controller.animateToPage(index, duration: Duration(milliseconds: 300), curve: Curves.linear);

@dnfield
Copy link
Contributor

dnfield commented Sep 7, 2018

I've fixed the exception issue in the linked PR, it's just still being reviewed/refined.

@krmao that's probably a good workaround for most cases, as I think it should force the cause of this bug to not happen - but it wouldn't necessarily work for some cases with larger listviews.

@krmao
Copy link

krmao commented Sep 7, 2018

that's really great ! I will wait the new version of flutter . @dnfield

@ejabu
Copy link

ejabu commented Sep 8, 2018

I made sample repository here

https://github.com/ejabu/slidable_redux_flutter

cropped

@Eder87rh
Copy link

This bug has been fixed in v0.8.2-pre.26, just update your flutter version

@7IXKTUIV1
Copy link

7IXKTUIV1 commented Oct 4, 2018

I'm running 0.8.2 and I'm facing the same error:

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
          body: new GridView.count(
            primary: false,
            padding: const EdgeInsets.all(5.0),
            crossAxisSpacing: 1.0,
            childAspectRatio: 1.0,
            crossAxisCount: 3,
            mainAxisSpacing: 8.0,
            children: <Widget>[
               Expanded(
                child: Image.network("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", fit:BoxFit.cover),
              ),
              Image.network("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"),
              const Text('Google'),
            ],
          ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Search',
        child: new Icon(Icons.search),
        backgroundColor: PrimaryColor2,
        foregroundColor: Color(0xFFFFFFFF),
      ),
    );
  }

@zoechi
Copy link
Contributor

zoechi commented Oct 4, 2018

@super94i I'd suggest to create a new issue with a properly filled issue template and a minimal but runnable reproduction.

@Eder87rh
Copy link

Eder87rh commented Oct 4, 2018

Sorry guys, the problem was still there. But I think I've finally found a solution. This bug is triggered when we click on the save button and the keyboard is still in screen. My workaround is hide the keyboard before to call _submitForm method like this:

Widget _buildSubmitButton() {
    return ScopedModelDescendant<MainModel>(
      builder: (BuildContext context, Widget child, MainModel model) {
        return model.isLoading
            ? Center(child: CircularProgressIndicator())
            : RaisedButton(
                child: Text('Save'),
                textColor: Colors.white,
                onPressed: () async {
                  SystemChannels.textInput.invokeMethod('TextInput.hide');
                  await Future.delayed(const Duration(milliseconds: 100)); 
 
                  _submitForm(model.addProduct, model.updateProduct,
                      model.selectProduct, model.selectedProductIndex);
                },
              );
      },
    );
  }

@dnfield
Copy link
Contributor

dnfield commented Oct 4, 2018

@Eder87rh this definitely seems like a different issue - can you open a separate issue (feel free to tag me in it) with a minimal reproduction?

@dnfield
Copy link
Contributor

dnfield commented Oct 4, 2018

@super94i yours also seems different, but again please feel free to open a separate issue and tag me in it if you like.

@mohamedHassanKa
Copy link

I had the same error and its from the keyboard if you hide they keyboard before submitting the form .it will work . but i want to know is there any solution to go over this probleme

@dnfield
Copy link
Contributor

dnfield commented Nov 9, 2018

@mohamedHassanKa please open a new issue with a sample and instructions to reproduce your issue.

@davidlahuta
Copy link

davidlahuta commented Oct 15, 2020

I encountered this issue in current beta.

✓] Flutter (Channel beta, 1.22.1, on Mac OS X 10.15.7 19H2, locale en-CZ)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 4.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.50.1)
[✓] Connected device (3 available)

Here is my workaround code.

When tabs are changing, it will unfocus any active widget.

final controller = TabController(length: 3, vsync: this, initialIndex: 1);
controller.addListener(() {
  FocusScopeNode currentFocus = FocusScope.of(context);

  if (currentFocus.hasFocus) {
    currentFocus.unfocus();
  }
); 

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: crash Stack traces logged to the console customer: crowd Affects or could affect many people, though not necessarily a specific customer. customer: mulligan (g3) f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. waiting for PR to land (fixed) A fix is in flight
Projects
Scrolling Refactor
Awaiting triage