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
75 stars 48 forks source link

Error on update to version 2.0.0 for null safety: `CustomTextStyle ` & `leadingDistribution` & `copyWith` #31

Closed yasinarik closed 3 years ago

yasinarik commented 3 years ago

BUG Description

I am trying to migrate to null safety and currently using: Flutter 2.2.0-10.2.pre & Flutter 2.0.6 Dart 2.12.4 (stable) styled_text_package: 2.0.0

I get this error code and don't know what to do :(

Terminal Build Error Code

Launching lib/main.dart on iPhone 8 in debug mode...
Xcode build done.                                           16,8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_style.dart:6:7: Error: The non-abstract class 'CustomStyle' is missing implementations for these members:
     - TextStyle.leadingDistribution
    Try to either
     - provide an implementation,
     - inherit an implementation from a superclass or mixin,
     - mark the class as abstract, or
     - provide a 'noSuchMethod' implementation.
    class CustomStyle with Diagnosticable implements TextStyle {
          ^^^^^^^^^^^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:630:37: Context: 'TextStyle.leadingDistribution' is defined here.
      final ui.TextLeadingDistribution? leadingDistribution;
                                        ^^^^^^^^^^^^^^^^^^^
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_text_style.dart:33:7: Error: The non-abstract class 'CustomTextStyle' is missing implementations for these members:
     - TextStyle.leadingDistribution
    Try to either
     - provide an implementation,
     - inherit an implementation from a superclass or mixin,
     - mark the class as abstract, or
     - provide a 'noSuchMethod' implementation.
    class CustomTextStyle extends CustomStyle {
          ^^^^^^^^^^^^^^^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:630:37: Context: 'TextStyle.leadingDistribution' is defined here.
      final ui.TextLeadingDistribution? leadingDistribution;
                                        ^^^^^^^^^^^^^^^^^^^
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_style.dart:15:13: Error: The method 'CustomStyle.apply' has fewer named arguments than those of overridden method 'TextStyle.apply'.
      TextStyle apply(
                ^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:859:13: Context: This is the overridden method ('apply').
      TextStyle apply({
                ^
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_style.dart:15:13: Error: The method 'CustomStyle.apply' doesn't have the named parameter 'leadingDistribution' of overridden method 'TextStyle.apply'.
      TextStyle apply(
                ^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:859:13: Context: This is the overridden method ('apply').
      TextStyle apply({
                ^
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_style.dart:81:13: Error: The method 'CustomStyle.copyWith' has fewer named arguments than those of overridden method 'TextStyle.copyWith'.
      TextStyle copyWith(
                ^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:770:13: Context: This is the overridden method ('copyWith').
      TextStyle copyWith({
                ^
    ../../../.pub-cache/hosted/pub.dartlang.org/styled_text-2.0.0/lib/custom_style.dart:81:13: Error: The method 'CustomStyle.copyWith' doesn't have the named parameter 'leadingDistribution' of overridden method 'TextStyle.copyWith'.
      TextStyle copyWith(
                ^
    ../../../fvm/versions/2.2.0-10.2.pre/packages/flutter/lib/src/painting/text_style.dart:770:13: Context: This is the overridden method ('copyWith').
      TextStyle copyWith({
                ^
andyduke commented 3 years ago

@yasinarik Use the stable version Flutter 2.0.6. In the pre-release version, the leadingDistribution property was added to TextStyle, StyledText does not yet support it.

yasinarik commented 3 years ago

@andyduke Thanks a lot. I have switched back to Flutter 2.0.6 and the error is gone. I hope this issue can help if anybody else faces the same error. CLosing it now.

ryanheise commented 3 years ago

Hi @yasinarik

It's unfortunate the Flutter SDK made a breaking change that appears to make it impossible for you to release a version that works on both Flutter stable and Flutter beta (since it is usually a good idea for plugins to be prepared for the next Flutter release before it happens rather than after.)

However, maybe this exposes some fragility in extending TextStyle and you might consider just abandoning that subclass relationship and having your style class as its own class.

Or if you like keeping it as a subclass, would you at least consider making a prerelease version that works with the new version of TextStyle? It is technically a bug.

The Flutter team does recommend app developers use the beta channel in certain instances because Flutter 2.0 was rushed out the door with things like integration testing broken (flutter_driver). From this page:

Which channel should I use?

We recommend using the stable branch.

That said, the beta branch should be fine. There is no extra level of testing that we do for stable than for beta, other than the extended stabilization period on the beta branch. So if there is something you want to use that is available on beta but not stable, feel free to consider using beta.

andyduke commented 3 years ago

@ryanheise I am currently working on a new version of StyledText that will not directly implement TextStyle and will get rid of this fragility when breaking changes in newer Flutter versions.