简体   繁体   English

Google NotoSans 字体在 Flutter Web 应用程序中的 iOS 上无法正确显示

[英]Google NotoSans font not displaying correctly on iOS in flutter web app

Situation : I am creating a flutter web app , which makes use of Google Fonts' NotoSans font to display English and Devanagari (Hindi) script.情况:我正在创建一个颤振网络应用程序,它利用 Google Fonts 的 NotoSans 字体来显示英文和梵文(印地语)脚本。 The app displays correctly on Chrome in MacOS.该应用程序在 MacOS 的 Chrome 上正确显示。

Complication : On iOS (Iphone 11) text is not displaying correctly.并发症:在 iOS (Iphone 11) 上,文本显示不正确。 See gif below:见下图: 在此处输入图像描述

I am using flutter 3.0.2 and this is a relevant excerpt from my pubspec.yaml file:我正在使用颤振 3.0.2,这是我的 pubspec.yaml 文件的相关摘录:

 # These dependencies get packaged with the app during build dependencies: flutter: sdk: flutter # For multilingual flutter_localizations: sdk: flutter intl: ^0.17.0 # Get access to many fancy fonts and icons google_fonts: ^3.0.1 # These dependencies do not get packaged with the app during build dev_dependencies: flutter_test: sdk: flutter # For clean formatting flutter_lints: ^2.0.1 # The following section is specific to Flutter. flutter: # Add icons from material design font uses-material-design: true # Internationalization generate: true # Add images assets: - assets/images/ - assets/images/brands/ - assets/images/flags/ - assets/icons/ - assets/videos/ - assets/fonts/ # Add personalized Strawmerry icons fonts: - family: NotoSans fonts: - asset: assets/fonts/NotoSansRegular.ttf - asset: assets/fonts/NotoSansBold.ttf weight: 700 - asset: assets/fonts/NotoSansItalic.ttf style: italic

This is an excerpt from my theme.dart file, in which I declare my text theme.这是我的 theme.dart 文件的摘录,我在其中声明了我的文本主题。

 class StrawmerryTheme { ThemeData get theme => ThemeData( textTheme: TextTheme( // Currently only used for starting page sub-title // titleSmall: GoogleFonts.notoSans( // fontSize: 34, // fontWeight: FontWeight.bold, // letterSpacing: 0.25, // color: Colors.black // ), titleSmall: const TextStyle( fontFamily: 'NotoSans', fontSize: 34, fontWeight: FontWeight.bold, letterSpacing: 0.25, color: Colors.black), // Currently used for page titles headlineLarge: TextStyle( fontFamily: 'NotoSans', fontSize: 34, fontWeight: FontWeight.bold, letterSpacing: 0.25, color: Colors.grey.shade800, ), // Currently used for page section titles headlineMedium: TextStyle( fontFamily: 'NotoSans', fontSize: 24, fontWeight: FontWeight.bold, letterSpacing: -1, color: Colors.grey.shade800, ), headlineSmall: TextStyle( fontFamily: 'NotoSans', fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: 0.15, color: Colors.grey.shade800, ), // Main body text bodyMedium: TextStyle( fontFamily: 'NotoSans', fontSize: 16, fontWeight: FontWeight.normal, letterSpacing: 0.5, color: Colors.grey.shade800, ), // Used for units bodySmall: TextStyle( fontFamily: 'NotoSans', fontSize: 12, fontWeight: FontWeight.normal, letterSpacing: 0.4, color: Colors.grey.shade800, ), // Used for buttons labelMedium: const TextStyle( fontFamily: 'NotoSans', fontSize: 22, fontWeight: FontWeight.normal, letterSpacing: 1.0, color: Colors.white, ), ), ), }

Question : Any idea how to fix this?问题:知道如何解决这个问题吗?

I figured this one out.我想出了这个。 The problem only occurred for me when using the html web renderer when building, like such:只有在构建时使用 html Web 渲染器时才会出现此问题,如下所示:

flutter build web --web-renderer html

After switching to canvaskit everything worked fine:切换到 canvaskit 后一切正常:

flutter build web --web-renderer canvaskit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM