Skip to content

Widget throws an exception when a simple TextStyle value is provided #11

@calin0s

Description

@calin0s

Hi there!

I've started using the widget yesterday, so I haven't explored everything, however I am getting an error when specifying a simple TextStyle instance to the textStyle parameter, when creating the WeekdaySelector widget.

Here's the code:

Container(
  decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(35),
    border: Border.all(width: 1, color: cs.outline),
  ),
  child: WeekdaySelector(
      textStyle: TextStyle(fontFamily: "Arial", color: cs.onBackground),
      color: cs.onBackground,
      elevation: 0,
      onChanged: (index) {
        setState(() {
          days[index % 7] = !days[index % 7];
        });
      },
      values: days),
);

ERROR INFORMATION

The TextStyles being interpolated were:
from: TextStyle
    inherit: true
    color: Color(0xff1b1b1f)
to: TextStyle
    debugLabel: (((englishLike bodyMedium 2021).merge(((blackMountainView bodyMedium).apply).merge(unknown))).copyWith).copyWith
    inherit: false
    color: Color(0xffffffff)
    family: Merriweather_regular
    familyFallback: Merriweather
    size: 14.0
    weight: 400
    letterSpacing: 0.3
    baseline: alphabetic
    height: 1.4x
    leadingDistribution: even
    decoration: Color(0xff1b1b1f) TextDecoration.none

The following fields are unspecified in both TextStyles:
"backgroundColor", "wordSpacing", "decorationThickness".
When "inherit" changes during the transition, these fields may observe abrupt value changes as a result, causing "jump"s in the transition.

In general, TextStyle.lerp only works well when both TextStyles have the same "inherit" value, and specify the same fields.
If the TextStyles were directly created by you, consider bringing them to parity to ensure a smooth transition.

If one of the TextStyles being lerped is significantly more elaborate than the other, and has "inherited" set to false, it is often because it is merged with another TextStyle before being lerped. Comparing the "debugLabel"s of the two TextStyles may help identify if that was the case.
For example, you may see this error message when trying to lerp between "ThemeData()" and "Theme.of(context)". This is because TextStyles from "Theme.of(context)" are merged with TextStyles from another theme and thus are more elaborate than the TextStyles from "ThemeData()" (which is reflected in their "debugLabel"s -- TextStyles from "Theme.of(context)" should have labels in the form of "(<A TextStyle>).merge(<Another TextStyle>)"). It is recommended to only lerp ThemeData with matching TextStyles.

STRACK TRACE

When the exception was thrown, this was the stack:
#0      TextStyle.lerp.<anonymous closure> (package:flutter/src/painting/text_style.dart:1212:7)
text_style.dart:1212
#1      TextStyle.lerp (package:flutter/src/painting/text_style.dart:1253:6)
text_style.dart:1253
#2      TextStyleTween.lerp (package:flutter/src/widgets/implicit_animations.dart:214:41)
implicit_animations.dart:214
#3      Tween.transform (package:flutter/src/animation/tween.dart:362:12)
tween.dart:362
#4      Animatable.evaluate (package:flutter/src/animation/tween.dart:68:46)
tween.dart:68
#5      _AnimatedDefaultTextStyleState.build (package:flutter/src/widgets/implicit_animations.dart:1961:22)
implicit_animations.dart:1961
#6      StatefulElement.build (package:flutter/src/widgets/framework.dart:5592:27)
framework.dart:5592
#7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5480:15)
framework.dart:5480
#8      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
framework.dart:5643
#9      Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
framework.dart:5196
#10     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2904:19)
framework.dart:2904
#11     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:989:21)
binding.dart:989
#12     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
binding.dart:448
#13     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
binding.dart:1386
#14     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
binding.dart:1311
#15     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169:5)
binding.dart:1169
#16     _invoke (dart:ui/hooks.dart:312:13)
hooks.dart:312
#17     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399:5)
platform_dispatcher.dart:399
#18     _drawFrame (dart:ui/hooks.dart:283:31)
hooks.dart:283

Removing the textStyle option gets the widget back to working.
Am I using the widget textStyle parameter incorrectly?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions