Flutter widgets library crashing after trying to log something?

Issue

I am trying to create a movie details app and this is my code so far for my page:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            expandedHeight: _appBarHeight,
            pinned: true,
            flexibleSpace: FlexibleSpaceBar(
              title: Text(movie.title),
              background: Stack(
                fit: StackFit.expand,
                children: <Widget>[
                  Hero(
                      tag: movie.id,
                      child: Image.network(
                        movie.posterArtUrl,
                        fit: BoxFit.cover,
                        height: _appBarHeight,
                      ))
                ],
              ),
            ),
          ),
          SliverList(
            delegate: SliverChildListDelegate(<Widget>[
              RatingInfo(movie),
              _buildMovieDetails(_movieDetail),
              _buildMovieGenreChips(_movieDetail),
            ]),
          )
        ],
      ),
    );
  }

As you can see, this page is mostly powered by two methods, _buildMovieDetails() and _buildMovieGenreChips(). The _buildMovieDetails() method works just fine and doesn’t return an error when it runs. However, the issue arises when I run the _buildMovieGenreChips() method. This method looks like the following:

Widget _buildMovieGenreChips(MovieDetail movieDetail) {
    if (_isLoading) {
      return Center(
        child: CircularProgressIndicator(),
      );
    } 
    else {
      print(movieDetail.genres.toString());
    }
  }
}

At this point in time, the method does nothing more than log out the value of movieDetail.genres, which is a list of a custom genre object that I created (which consists of a string for the genre name and and int for the genre id). However, when this code is run, my app crashes and the following stack trace is returned:

I/flutter ( 9592): [Instance of 'Genre', Instance of 'Genre', Instance of 'Genre', Instance of 'Genre']
I/flutter ( 9592): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 9592): The following assertion was thrown building _ScrollableScope:
I/flutter ( 9592): 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 291 pos 12: 'child != null': is
I/flutter ( 9592): not true.
I/flutter ( 9592):
I/flutter ( 9592): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 9592): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 9592): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 9592):   https://github.com/flutter/flutter/issues/new
I/flutter ( 9592):
I/flutter ( 9592): When the exception was thrown, this was the stack:
I/flutter ( 9592): #2      SliverChildListDelegate.build (package:flutter/src/widgets/sliver.dart)
I/flutter ( 9592): #3      SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:716:67)
I/flutter ( 9592): #4      _HashMap.putIfAbsent (dart:collection/runtime/libcollection_patch.dart:143:29)
I/flutter ( 9592): #5      SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:716:26)
I/flutter ( 9592): #6      SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:702:69)
I/flutter ( 9592): #7      SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:671:7)
I/flutter ( 9592): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #9      RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4371:32)
I/flutter ( 9592): #10     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4761:17)
I/flutter ( 9592): #11     _ViewportElement.update (package:flutter/src/widgets/viewport.dart:187:11)
I/flutter ( 9592): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #14     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #15     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #17     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #19     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #20     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #21     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #23     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #24     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #25     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #26     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #27     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #29     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #30     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #31     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #33     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #34     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #35     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #38     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #39     StatelessElement.update (package:flutter/src/widgets/framework.dart:3694:5)
I/flutter ( 9592): #40     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #41     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #42     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #43     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #44     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #45     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #46     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #47     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #48     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #49     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #50     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #51     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #52     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #53     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #54     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #55     StatelessElement.update (package:flutter/src/widgets/framework.dart:3694:5)
I/flutter ( 9592): #56     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #57     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #58     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #59     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #60     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #61     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #62     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #63     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #64     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #65     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4371:32)
I/flutter ( 9592): #66     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4761:17)
I/flutter ( 9592): #67     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #68     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #69     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #70     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #71     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #72     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #73     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #74     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #75     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #76     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #77     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #78     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #79     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #80     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #81     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #83     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #84     StatelessElement.update (package:flutter/src/widgets/framework.dart:3694:5)
I/flutter ( 9592): #85     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #86     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4653:14)
I/flutter ( 9592): #87     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #88     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #89     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #90     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #91     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #92     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #93     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #94     StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #95     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #96     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #97     Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #98     ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #99     Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #100    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #101    Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #102    ProxyElement.update (package:flutter/src/widgets/framework.dart:3901:5)
I/flutter ( 9592): #103    Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #104    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #105    Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #106    StatefulElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter ( 9592): #107    Element.updateChild (package:flutter/src/widgets/framework.dart:2691:15)
I/flutter ( 9592): #108    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3645:16)
I/flutter ( 9592): #109    Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 9592): #110    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2234:33)
I/flutter ( 9592): #111    _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:626:20)
I/flutter ( 9592): #112    _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter ( 9592): #113    _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 9592): #114    _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 9592): #115    _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 9592): #116    _invoke (dart:ui/hooks.dart:120:13)
I/flutter ( 9592): #117    _drawFrame (dart:ui/hooks.dart:109:3)
I/flutter ( 9592): (elided 2 frames from class _AssertionError)
I/flutter ( 9592): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/zygote  ( 9592): Do partial code cache collection, code=30KB, data=26KB
I/zygote  ( 9592): After code cache collection, code=30KB, data=26KB
I/zygote  ( 9592): Increasing code cache capacity to 128KB
I/flutter ( 9592): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4031 pos 14: '_dependents.isEmpty': is not true.
I/flutter ( 9592): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 2232 pos 16: '!_dirtyElements[index]._active || _dirtyElements[index]._debugIsInScope(context)': is not true.

As seen in the first line of the stack trace, my print statement works just fine, but my app crashes right after that and it seems as though Flutter’s widgets library crashes. Has anyone run into this issue before?

Solution

Your method is supposed to return a Widget, but when _isLoading is false it returns nothing.

Give this a try.

Widget _buildMovieGenreChips(MovieDetail movieDetail) {
    if (_isLoading) {
      return Center(
        child: CircularProgressIndicator(),
      );
    } 
    else {
      print(movieDetail.genres.toString());
      return Text("some widget");
    }
  }
}

Answered By – Edman

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.