andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
74 stars 48 forks source link

No DefaultTextHeightBehavior widget ancestor could be found #64

Closed vixez closed 1 year ago

vixez commented 1 year ago

Hey,

Since upgrading to Flutter 3.7.0 I get the following error

No DefaultTextHeightBehavior widget ancestor could be found starting from the context that was passed to DefaultTextHeightBehavior.of(). This can happen because you are using a widget that looks for a DefaultTextHeightBehavior ancestor, but no such ancestor exists.
The context used was:
  StyledText(dependencies: [DefaultTextStyle, MediaQuery], state: _StyledTextState#8a636)
When the exception was thrown, this was the stack: 
#0      DefaultTextHeightBehavior.of.<anonymous closure> (package:flutter/src/widgets/text.dart:293:9)
#1      DefaultTextHeightBehavior.of (package:flutter/src/widgets/text.dart:305:6)
#2      _StyledTextState.build (package:styled_text/styled_text.dart:386:39)
#3      StatefulElement.build (package:flutter/src/widgets/framework.dart:5080:27)
#4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4968:15)
#5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5133:11)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:4690:5)
#7      StatefulElement.update (package:flutter/src/widgets/framework.dart:5156:5)
pgiokoglou commented 1 year ago

Starting with flutter 3.7, one should use DefaultTextHeightBehavior.maybeOf instead of DefaultTextHeightBehavior.of

Temporary solution:

 DefaultTextHeightBehavior(
        textHeightBehavior: TextHeightBehavior(),
        child: MyApp(),
 );
vixez commented 1 year ago

Thanks for the quick answer!

andyduke commented 1 year ago

Please check version 7.0.