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
App throws package:flutter/src/painting/text_style.dart': Failed assertion: line 1031 pos 12: 'a == null || b == null || a.inherit == b.inherit': is not true
exception upon launch.
#89947
Comments
we are not explicitly setting any custom navActionTextStyle. we are using a theme generated with FlexColorScheme but a quick glance at the code, I didn't see anything in there either. |
@mrcsh |
I will see what I can do. I don't know what parts of our code need to be isolated. Is is pretty likely that the issue is something with the way the ThemeData has been setup? |
I was able to isolate the issue and will post the code later this morning.
…On Tue, Sep 14, 2021, 00:31 darshankawar ***@***.***> wrote:
@mrcsh <https://github.com/mrcsh>
Is there any chance to provide a replicable and self-contained code
sample, that we can use to analyse ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#89947 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDS4BLGXP27J3R2T2RWTJTUB3T5ZANCNFSM5D4JLGQA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I kept adding stuff until I was able to reproduce it. It seems to happen when the theme is updated from the default. |
Thanks for the effort to isolate the issue and providing a minimal code sample. I see the same exception on latest master and stable upon app launch. console error log
stable, master flutter doctor -v
|
package:flutter/src/painting/text_style.dart': Failed assertion: line 1031 pos 12: 'a == null || b == null || a.inherit == b.inherit': is not true
exception upon launch.
/cc: @HansMuller |
@mrcsh This error looks very similar to what happens if you change Since you mentioned FlexColorScheme defaults to the newer, according to Material Guide, correct For some more info on this issue see here: rydmike/flex_color_scheme#9 If you first create a default theme made with In the issue above rydmike/flex_color_scheme#9 I also show how this happens even if you do not use FlexColorScheme, it is enough to just use two different FlexColorScheme just returns a normal You can of course solve this issue by assigning By the way, if you are just using a default An even nicer way is to fully form the target @HansMuller Imo lerping between Typography SidenoteAs a minor side note, I just happened on this issue right now when I was researching status of Typography defaults in 2.5.0 and master, and searching also for issues that mention Typography as a part of that status research, quite a coincidence really that I stumbled in here. When it comes to my findings from that discovery here is what I learned: Interestingly class Typography with Diagnosticable {
/// Creates a typography instance.
///
/// This constructor is identical to [Typography.material2018].
factory Typography({
TargetPlatform? platform,
TextTheme? black,
TextTheme? white,
TextTheme? englishLike,
TextTheme? dense,
TextTheme? tall,
}) = Typography.material2018; This is a pretty new change, from Jun 15, 2021: But of course platform ??= defaultTargetPlatform;
typography ??= Typography.material2014(platform: platform);
TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;
TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;
if (fontFamily != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(fontFamily: fontFamily);
defaultAccentTextTheme = defaultAccentTextTheme.apply(fontFamily: fontFamily);
}
textTheme = defaultTextTheme.merge(textTheme);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
accentTextTheme = defaultAccentTextTheme.merge(accentTextTheme); The @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
final Typography defaultTypography = Typography.material2014();
properties.add(DiagnosticsProperty<TextTheme>('black', black, defaultValue: defaultTypography.black));
properties.add(DiagnosticsProperty<TextTheme>('white', white, defaultValue: defaultTypography.white));
properties.add(DiagnosticsProperty<TextTheme>('englishLike', englishLike, defaultValue: defaultTypography.englishLike));
properties.add(DiagnosticsProperty<TextTheme>('dense', dense, defaultValue: defaultTypography.dense));
properties.add(DiagnosticsProperty<TextTheme>('tall', tall, defaultValue: defaultTypography.tall));
} |
That is a lot of info, thanks. |
So using
if our theme definition was not available did not work, but using a FlexColorScheme generated ThemeData from our static config and then updating it to a newer version once we loaded the dynamic parts did eliminate the exception, (and the color flash) |
Correct finding, because if you do a: Theme.of(context).copyWith(typography: Typography.material2018()) You are only creating a copy of So with the above update you did not actually change the differences in typographic text styles that the SDK does not want to lerp between. Only the ThemeData(typography: Typography.material2018())` Or if you are using eg It is possible to do it with copyWith as well, but you need to work on the textTheme and merge in the correct typography, something like this, for adding a custom textTheme in light theme mode:
Messy. There was discussion about it here: rydmike/flex_color_scheme#15 So for next update FlexColorScheme, among other features, I will make using using custom text themes easier, since the proper steps to copy and merge them into BTW: static TextStyle? lerp(TextStyle? a, TextStyle? b, double t) {
assert(t != null);
assert(a == null || b == null || a.inherit == b.inherit);
if (a == null && b == null) {
return null;
} |
Consider this additional exampleConsider this simple Flutter SDK only example where we toggle between two different themes in light and dark mode. return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
darkTheme: ThemeData.from(
colorScheme: const ColorScheme.dark(),
).copyWith(typography: Typography.material2018()),
themeMode: themeMode,
home: MyHomePage(
title: 'Flutter Demo Home Page',
themeMode: themeMode,
onThemeModeChanged: (ThemeMode mode) {
setState(() {
themeMode = mode;
});
},
),
); This will trigger the assert reported in this issue as well. Assert error: Failed assertion: line 1031 pos 12: 'a == null || b == null || a.inherit == b.inherit': is not true.The following assertion was thrown building AnimatedTheme(duration: 200ms, dirty, state: _AnimatedThemeState#79c49(ticker active, ThemeDataTween(ThemeData#caa00 → ThemeData#4d489))):
'package:flutter/src/painting/text_style.dart': Failed assertion: line 1031 pos 12: 'a == null || b == null || a.inherit == b.inherit': 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?template=2_bug.md
The relevant error-causing widget was:
MaterialApp MaterialApp:file:///C:/Users/mryds/OneDrive/code/flutter/_issues/typography_issue/lib/main.dart:20:12
When the exception was thrown, this was the stack:
#2 TextStyle.lerp (package:flutter/src/painting/text_style.dart:1031:12)
#3 TextTheme.lerp (package:flutter/src/material/text_theme.dart:432:28)
#4 Typography.lerp (package:flutter/src/material/typography.dart:289:17)
#5 ThemeData.lerp (package:flutter/src/material/theme_data.dart:1741:30)
#6 ThemeDataTween.lerp (package:flutter/src/material/theme.dart:174:41)
#7 Tween.transform (package:flutter/src/animation/tween.dart:327:12)
#8 Animatable.evaluate (package:flutter/src/animation/tween.dart:53:46)
#9 _AnimatedThemeState.build (package:flutter/src/material/theme.dart:230:20)
#10 StatefulElement.build (package:flutter/src/widgets/framework.dart:4700:27)
#11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4583:15)
#12 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4758:11)
#13 Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#14 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2578:33)
#15 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#16 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#17 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#18 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#19 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#23 _invoke (dart:ui/hooks.dart:166:10)
#24 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#25 _drawFrame (dart:ui/hooks.dart:129:31)
(elided 5 frames from class _AssertionError and dart:async) This assert error currently occurs on all Flutter channels.Illustrated here: Full sample codeimport 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ThemeMode themeMode = ThemeMode.system;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.from(colorScheme: const ColorScheme.light()),
darkTheme: ThemeData.from(
colorScheme: const ColorScheme.dark(),
).copyWith(typography: Typography.material2018()),
themeMode: themeMode,
home: MyHomePage(
title: 'Flutter Demo Home Page',
themeMode: themeMode,
onThemeModeChanged: (ThemeMode mode) {
setState(() {
themeMode = mode;
});
},
),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({
Key? key,
required this.title,
required this.themeMode,
required this.onThemeModeChanged,
}) : super(key: key);
final String title;
final ThemeMode themeMode;
final ValueChanged<ThemeMode> onThemeModeChanged;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Toggle theme to see error'),
ThemeModeSwitch(
themeMode: themeMode,
onChanged: onThemeModeChanged,
),
],
),
),
);
}
}
/// Widget used to toggle the theme style of the application.
@immutable
class ThemeModeSwitch extends StatelessWidget {
const ThemeModeSwitch({
Key? key,
required this.themeMode,
required this.onChanged,
}) : super(key: key);
final ThemeMode themeMode;
final ValueChanged<ThemeMode> onChanged;
@override
Widget build(BuildContext context) {
final List<bool> isSelected = <bool>[
themeMode == ThemeMode.light,
themeMode == ThemeMode.system,
themeMode == ThemeMode.dark,
];
return ToggleButtons(
isSelected: isSelected,
onPressed: (int newIndex) {
if (newIndex == 0) {
onChanged(ThemeMode.light);
} else if (newIndex == 1) {
onChanged(ThemeMode.system);
} else {
onChanged(ThemeMode.dark);
}
},
children: const <Widget>[
Icon(Icons.wb_sunny),
Icon(Icons.phone_iphone),
Icon(Icons.bedtime),
],
);
}
}
Why is the assert needed?Is there any possibility that the assert is a left over from when the different lerping situations in If we look at these checks: static TextStyle? lerp(TextStyle? a, TextStyle? b, double t) {
assert(t != null);
assert(a == null || b == null || a.inherit == b.inherit);
if (a == null && b == null) {
return null;
} If both if (a == null) {
return TextStyle(
inherit: b!.inherit,
... Then the case for when if (b == null) {
return TextStyle(
inherit: a.inherit,
... Then finally the case for when neither is null, only one left since we returned null earlier when both were null: return TextStyle(
inherit: b.inherit,
color:
... The assert is thrown, because the use case in this issue does not fulfill the
Set Questions:
If the 3 Where there is now no assert error shown when toggling between the same themes, and we can also see the slight difference in the typography geometry between the used themes in light and dark mode as well. Perhaps the assert does fill some other meaningful purpose, I don't have enough insights to know its detailed purpose, but at least in this use case, it is just in the way. |
We have been seeing this error on the startup of our app for a while. I does not seem to have any impact.
It happens very early on.
With the update to flutter 2.5 the error is more detailed, but still the stack trace does not really indicate where in our code the exception is being thrown from.
full output of flutter run --verbose attached.
Logs
The text was updated successfully, but these errors were encountered: