Skip to content

TextStyle.copyWith not recognized inside eval → CompileError #120

@Treamz

Description

@Treamz

When trying to use TextStyle.copyWith in evaluated code, the compiler throws an error saying that the method is unknown.

Minimal reproducible code:

abstract class AppThemeStyles {
  ThemeData get themeData;

  TextTheme get textTheme => themeData.textTheme;

  get smallBannerTitleSmall =>
      themeData.textTheme.titleSmall?.copyWith(color: colors.white);
}

Error log:

CompileError: Unknown method TextStyle.copyWith at "themeData.textTheme...." (file package:hot_part/theme/app_theme_styles.dart)
#0      resolveInstanceMethod (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:355:9)
#1      resolveInstanceMethod (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:360:14)
#2      resolveInstanceMethod (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:360:14)
#3      _invokeWithTarget (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:260:12)
#4      compileMethodInvocation.<anonymous closure> (package:dart_eval/src/eval/compiler/expression/method_invocation.dart:48:19)
...

Expected behavior:

TextStyle.copyWith should be available inside flutter_eval, since it’s a core Flutter method used for theming.

Actual behavior:

Compilation fails with Unknown method TextStyle.copyWith.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions