Skip to content
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

Support asset paths that include % and [, etc #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CORDEA
Copy link

@CORDEA CORDEA commented Oct 21, 2023

Hi team, thank you for the great package!
I found a small problem, and tried to fix it. Could you please check it?

Error details

In the current release, the following error occurs when characters such as % are used in the asset path.

package:flutter/src/services/asset_bundle.dart 339:7  PlatformAssetBundle.load
package:golden_toolkit/src/font_loader.dart 30:37     loadAppFonts

Unable to load asset: "packages/custom_font/fonts/Raleway-Regular%25test.ttf".
The asset does not exist or has empty data.

I found that some characters such as % and [ in the asset path included in fontType are encoded. For example, Raleway-Regular!@$%^&*()[].ttf will be Raleway-Regular!@$%25%5E&*()%5B%5D.ttf.

How to reproduce

Create a package containing custom fonts like below.

flutter:
  fonts:
    - family: Raleway
      fonts:
        - asset: fonts/Raleway-Regular%test.ttf

And the create a widget using this font.

class CustomFontLabel extends StatelessWidget {
  const CustomFontLabel({super.key, required this.text});

  final String text;

  @override
  Widget build(BuildContext context) {
    return Text(
      text,
      style: const TextStyle(
        fontFamily: 'Raleway',
        package: 'custom_font',
        fontSize: 46,
      ),
    );
  }
}

Write a golden test using this widget on the app side, and it will fail.

void main() {
  setUp(() async {
    await loadAppFonts();
  });

  testGoldens('test', (tester) async {
    const widget = WidgetUsingCustomFontLabel();
    await tester.pumpWidgetBuilder(
      widget,
      wrapper: materialAppWrapper(),
    );
    await screenMatchesGolden(tester, 'test');
  });
}

This fixes errors that occur when characters such as % are used in the
asset path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant