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

TextOverflow property throwing exception #76709

Closed
hannahgrinton opened this issue Feb 24, 2021 · 12 comments
Closed

TextOverflow property throwing exception #76709

hannahgrinton opened this issue Feb 24, 2021 · 12 comments
Labels
r: invalid Issue is closed as not valid

Comments

@hannahgrinton
Copy link

Adding overflow: TextOverflow.ellipsis to Text() object throws this exception.
Here's the error from the runtime:

flutter: ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during a scheduler callback:
flutter: Updated layout information required for RenderIndexedSemantics#a7892 NEEDS-LAYOUT to calculate
flutter: semantics.
flutter: 'package:flutter/src/rendering/object.dart':
flutter: Failed assertion: line 2647 pos 12: '!_needsLayout'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2647:12)
flutter: #3 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #4 Iterable.forEach (dart:core/iterable.dart:283:30)
flutter: #5 RenderSliverVariableSizeBoxAdaptor.visitChildren (package:flutter_staggered_grid_view/src/rendering/sliver_variable_size_box_adaptor.dart:294:29)
flutter: #6 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #7 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #8 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #9 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #10 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #11 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #12 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #13 Iterable.forEach (dart:core/iterable.dart:283:30)
flutter: #14 RenderViewportBase.visitChildrenForSemantics (package:flutter/src/rendering/viewport.dart:219:10)
flutter: #15 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #16 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #17 RenderIgnorePointer.visitChildrenForSemantics (package:flutter/src/rendering/proxy_box.dart:3127:14)
flutter: #18 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #19 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #20 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #21 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #22 RenderSemanticsAnnotations.visitChildrenForSemantics (package:flutter/src/rendering/proxy_box.dart:4456:11)
flutter: #23 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #24 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #25 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #26 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #27 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #28 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #29 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #30 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #31 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #32 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #33 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #34 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #35 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #36 RenderObject._getSemanticsForParent. (package:flutter/src/rendering/object.dart:2669:61)
flutter: #37 RenderObjectWithChildMixin.visitChildren (package:flutter/src/rendering/object.dart:3042:14)
flutter: #38 RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2754:5)
flutter: #39 RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2664:5)
flutter: #40 RenderObject._updateSemantics (package:flutter/src/rendering/object.dart:2625:41)
flutter: #41 PipelineOwner.flushSemantics (package:flutter/src/rendering/object.dart:1081:16)
flutter: #42 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:441:21)
flutter: #43 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:914:13)
flutter: #44 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
flutter: #45 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
flutter: #46 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
flutter: #47 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)
flutter: #51 _invoke (dart:ui/hooks.dart:251:10)
flutter: #52 _drawFrame (dart:ui/hooks.dart:209:3)
flutter: (elided 5 frames from class _AssertionError and dart:async)

Here's a snippet of the code:

child: Text(
card.title,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.start,
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: titleFontSize),
),

@aminedakhlii
Copy link
Contributor

Could you please share the whole source file so that we can check the parent widgets

@hannahgrinton
Copy link
Author

Sure, here you go:

import 'package:SesameStreetApp/constants.dart';
import 'package:SesameStreetApp/core/utils/AppUtils.dart';
import 'package:SesameStreetApp/di/Injection.dart';
import 'package:SesameStreetApp/feature/favorites/presentation/favorites_bloc.dart';
import 'package:SesameStreetApp/feature/favorites/presentation/widget/FavoriteIcon.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:domain/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'LoggedInWidgetWrapper.dart';

class Card extends StatefulWidget {
final ScreenItem card;
final bool smallTile;

Card({@required this.card, @required this.smallTile});

@OverRide
State createState() => CardState(card, smallTile);
}

class CardState extends State {
final double imageAspectRation = 1.33;
final double iconCategorySize = 70;
final double borderRadius = 8;
final double titleFontSize = 18;
final double primaryTitlePaddingRight = 70;
final double titlePaddingRight = 40;
final ScreenItem card;
final bool smallTile;
final favoritesBloc = getIt();

CardState(this.card, this.smallTile);

@OverRide
void dispose() {
super.dispose();
favoritesBloc.close();
}

renderIcon() {
switch (card.type) {
case 'game':
return Image(
width: iconCategorySize, image: AssetImage(ImagePaths.gameTileImg));
break;
case 'video':
return Image(
width: iconCategorySize, image: AssetImage(ImagePaths.playTileImg));
break;
default:
return Container();
}
}

renderInfoButton(BuildContext context) {
return Offstage(
offstage: card.type == "screen",
child: InkWell(
onTap: () => Navigator.pushNamed(context, Routes.info,
arguments: {AppStrings.screenItem: card}),
child: Image(
width: smallTile ? card.primary ? 34 : 24 : 34,
image: AssetImage(ImagePaths.cardDetailsImg),
),
),
);
}

@OverRide
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => AppUtils.screenCardClicked(context, card),
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(8),
bottomRight: Radius.circular(8),
topLeft: Radius.circular(4),
topRight: Radius.circular(4),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 0.0,
blurRadius: 3.0,
offset: Offset(0, 3),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
overflow: Overflow.visible,
children: [
OrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
return Center(
child: LayoutBuilder(
builder: (BuildContext context,
BoxConstraints constraints) =>
AspectRatio(
aspectRatio: imageAspectRation,
child: CachedNetworkImage(
fit: BoxFit.fitHeight,
width: constraints.maxWidth,
imageUrl: orientation == Orientation.portrait
? card.image.portrait
: card.image.landscape,
placeholder: (context, url) => Container(
height: 100,
color: AppColor.loadingCardBackground,
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
Colors.white),
),
),
),
errorWidget: (context, url, error) => Container(
child: Center(
child: Icon(Icons.error),
),
),
),
),
),
);
}),
(card.id != null)
? LoggedInWidgetWrapper(_renderFavoritesButton)
: SizedBox.shrink(),
Positioned(
bottom: -30,
right: -5,
child: renderIcon(),
),
Positioned(
top: 6,
right: 6,
child: renderInfoButton(context),
)
],
),
Padding(
padding: EdgeInsets.only(
left: 5,
right: card.primary
? primaryTitlePaddingRight
: titlePaddingRight,
top: card.primary ? 15 : 18,
bottom: 15,
),
child: Text(
card.title,
overflow: TextOverflow.ellipsis,
maxLines: 2,
textAlign: TextAlign.start,
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: titleFontSize),
),
)
],
)),
);
}

Widget _renderFavoritesButton(BuildContext context) {
bool iconSmall = smallTile ? card.primary ? false : true : false;
return Positioned(
left: 2,
top: 2,
child: Container(
child: BlocProvider(
create: (BuildContext context) => favoritesBloc,
child: FavoriteIcon(card.id, iconSmall),
),
),
);
}
}

@aminedakhlii
Copy link
Contributor

Is it showing an overflow in the screen or the widgets are not even rendered ?
if it's showing an overflow you should wrap the padding widget in an Expanded and that Expanded should be wrapped in a Row as follows :
Row(
children: [
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 5,
right: card.primary
? primaryTitlePaddingRight
: titlePaddingRight,
top: card.primary ? 15 : 18,
bottom: 15,),
child: Text(card.title,
overflow: TextOverflow.ellipsis,
maxLines: 2,
textAlign: TextAlign.start,
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: titleFontSize),
),
),
),
],
),

@hannahgrinton
Copy link
Author

There's actually no visible render error in the app, everything looks like it's working fine, so I'm really not sure why I'm getting the error. Removing that overflow property is enough to make the error go away again.

@hannahgrinton
Copy link
Author

Tried adding Row and Expanded the way you demonstrated, and got the same error in the console, but again, no visible error.

@aminedakhlii
Copy link
Contributor

In order to be able to reproduce the error I need the source file where you call the Card widgets, could you please share it

@hannahgrinton
Copy link
Author

import 'dart:ui';

import 'package:SesameStreetApp/constants.dart';
import 'package:SesameStreetApp/feature/list_content/presentation/bloc/bloc.dart';
import 'package:SesameStreetApp/feature/list_content/presentation/widgets/Card.dart';
import 'package:SesameStreetApp/feature/list_content/presentation/widgets/LoadingEllipse.dart';
import 'package:SesameStreetApp/feature/list_content/presentation/widgets/NoNetworkWidget.dart';
import 'package:SesameStreetApp/feature/list_content/presentation/widgets/OfflineCard.dart';
import 'package:SesameStreetApp/feature/menu_navigation/presentation/bloc/MenuNavigationBloc.dart';
import 'package:SesameStreetApp/feature/menu_navigation/presentation/bloc/bloc.dart'
hide Loaded, Error, Loading;
import 'package:SesameStreetApp/feature/menu_navigation/presentation/widgets/Drawer.dart';
import 'package:domain/service.dart';
import 'package:flutter/material.dart' hide Card;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class ListContentPage extends StatefulWidget {
ListContentBloc contentBloc;
MenuNavigationBloc menuBloc;
LocalStorageService localStorageService;
ValueNotifier offline = ValueNotifier(false);

ListContentPage(
{@required this.contentBloc, @required this.menuBloc, @required this.localStorageService});

@OverRide
_ListContentPageState createState() => _ListContentPageState();
}

class _ListContentPageState extends State {
ValueNotifier isDrawerOpened = ValueNotifier(false);
final GlobalKey _drawerKey = GlobalKey();
ScrollController controller = ScrollController();

void toggleDrawer() async {
if (_drawerKey.currentState.isDrawerOpen) {
_drawerKey.currentState.openEndDrawer();
} else {
_drawerKey.currentState.openDrawer();
}
}

@OverRide
Widget build(BuildContext context) {
widget.contentBloc.add(GetListContent(depth: 1, offset: 0));
widget.menuBloc.add(GetMainMenuEvent());

Widget showNoNetwork() {
  return NoNetworkWidget(() {
    widget.contentBloc.add(GetListContent(depth: 1, offset: 0));
    widget.menuBloc.add(GetMainMenuEvent());
  });
}

return MultiBlocProvider(
  providers: [
    BlocProvider<ListContentBloc>(
      create: (BuildContext context) => widget.contentBloc,
    ),
    BlocProvider<MenuNavigationBloc>(
      create: (BuildContext context) => widget.menuBloc,
    ),
  ],
  child: BlocBuilder<ListContentBloc, ListContentState>(
    builder: (context, state) {
      if (state is Loaded) widget.offline.value = (state.state == NetworkContentState.OFFLINE);
      return Scaffold(
        appBar: AppBar(
          automaticallyImplyLeading: false,
          leading: ValueListenableBuilder(
            valueListenable: widget.offline,
            builder: (BuildContext context, bool value, Widget child) {
              return Visibility(
                visible: !value,
                child: InkWell(
                  onTap: toggleDrawer,
                  child: Semantics(
                    enabled: true,
                    label: SemanticsStrings.menu,
                    onTapHint: SemanticsStrings.menu_tap_hint,
                    child: Image(
                      image: AssetImage(ImagePaths.hamburgerIcon),
                      height: 22,
                      width: 26,
                    ),
                  ),
                ),
              );
            }
          ),
          backgroundColor: Colors.white,
          centerTitle: true,
          title: ExcludeSemantics(
            child: ValueListenableBuilder(
              valueListenable: widget.offline,
              builder: (BuildContext context, bool value, Widget child) {
                return value
                  ? Text(AppStrings.offlineGames,
                    style: TextStyle(
                      color: AppColor.darkerTextColor,
                      fontFamily: FontFamilies.vagRoundedStd,
                      fontSize: Fonts.title,
                      fontWeight: FontWeight.bold,
                  ))
                  : Image(
                    image: AssetImage(ImagePaths.appLogoImg),
                    height: 36,
                    width: 95,
                  );
              }
            ),
          ),
        ),
        body: Scaffold(
          backgroundColor: AppColor.yellowTheme,
          key: _drawerKey,
          drawer: Drawer(
            child: BlocBuilder<MenuNavigationBloc, MenuNavigationState>(
              builder: (BuildContext context, state) =>
                SideDrawer(state: state, drawerKey: _drawerKey, menuBloc: widget.menuBloc),
            ),
          ),
          body: state is Loading
          ? LoadingEllipse()
          : state is Error
          ? Center(child: Text(state.message))
          : state is Loaded
          ? OrientationBuilder(
              builder: (BuildContext context, Orientation orientation) =>
              SingleChildScrollView(
                child: Column(
                  children: [
                    state.state == NetworkContentState.OFFLINE
                      ? showNoNetwork()
                      : SizedBox.shrink(),
                    Container(
                      width: MediaQuery.of(context).size.width,
                      height: MediaQuery.of(context).size.height,
                      color: AppColor.defaultBackgroundColor,
                      child: StaggeredGridView.countBuilder(
                        padding: EdgeInsets.all(11),
                        controller: controller,
                        crossAxisCount: 4,
                        itemCount: state.screen.itemsTotal,
                        itemBuilder: (BuildContext context, int index) {
                          return state.screen.title == "offline"
                          ? OfflineCard(card: state.screen.items[index])
                          : Card(card: state.screen.items[index], smallTile: !state.screen.items[index].primary);
                        },
                        staggeredTileBuilder: (index) =>
                          StaggeredTile.fit(state.screen.items[index].primary ? 4 : 2),
                        mainAxisSpacing: 11.0,
                        crossAxisSpacing: 11.0,
                      ),
                    ),
                  ],
                ),
              )
            )
          : Container()
        ),
      );
    }
  ),
);

}
}

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Feb 25, 2021
@darshankawar
Copy link
Member

@hannahgrinton
Your question is better suited for StackOverflow. Please see https://flutter.dev/community for resources and if you need help with your code, please see https://www.reddit.com/r/flutterhelp/

Closing from here, as this seems to be an issue with code implementation rather than bug in framework. If you disagree or think otherwise, write in comments and I'll reopen it.

@darshankawar darshankawar added r: invalid Issue is closed as not valid and removed in triage Presently being triaged by the triage team labels Feb 25, 2021
@aminedakhlii
Copy link
Contributor

@darshankawar I tried to reproduce the error with stable v 1.22.5 and the issue did not appear so I believe it might be related to a bug in another version of the framework and thus this has to be reopened.

@darshankawar
Copy link
Member

@hannahgrinton @aminedakhlii
Can you provide a complete minimal reproducible code sample, preferably in single file (main.dart) that we can directly copy paste and run to see the issue ? Please don't use any 3rd party plugins in the code sample.

@hannahgrinton
Copy link
Author

@darshankawar @aminedakhlii

I created a code sample, but was unable to reproduce the issue (using no 3rd party plugins - my project where the error occurs uses Staggered Grid View plugin). So, I decided to add this plugin into my code sample as well, and sure enough, the error occurred. If there aren't enough grid items to need to scroll, the issue doesn't present itself, but if there are enough children (grid items), and you scroll down the page, the error appears in the terminal. Removing the overflow property to the text widget, however, and hot reloading the app, removes the error, same as in my original project. I'll attach the main.dart and pubspec.yaml files in a zipped folder so you can try it yourself, but I'm not sure there's really anything that can be done, looks like it's an issue for the Staggered Grid View plugin team to look at. Thanks for your time and effort!

flutter.zip

@github-actions
Copy link

github-actions bot commented Aug 5, 2021

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 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

3 participants