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

[Flutter Web] FontLoader doesn't work on web. #45727

Closed
johnsonmh opened this issue Nov 27, 2019 · 3 comments
Closed

[Flutter Web] FontLoader doesn't work on web. #45727

johnsonmh opened this issue Nov 27, 2019 · 3 comments

Comments

@johnsonmh
Copy link
Contributor

Steps to Reproduce

Run the following app on Web:

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

Future<ByteData> fetchFont() async {
  final response = await http.get(
      'https://raw.githubusercontent.com/google/fonts/master/ofl/montserrat/Montserrat-Light.ttf');

  if (response.statusCode == 200) {
    return ByteData.view(response.bodyBytes.buffer);
  } else {
    // If that call was not successful, throw an error.
    throw Exception('Failed to load font');
  }
}

void main() async {
  var fontLoader = FontLoader('Montserrat');
  fontLoader.addFont(fetchFont());
  await fontLoader.load();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Custom Fonts',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Custom Fonts')),
      body: Center(
        child: Text(
          'Montserrat is displayed here',
          style: TextStyle(fontFamily: 'Montserrat'),
        ),
      ),
    );
  }
}

Target Platform:: Web
Target OS version/browser:: MacOS/chrome

Logs

The following error is produced in the chrome console:

:57711/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
errors.dart:145 Uncaught (in promise) Error: Unsupported operation: loadFontFromList is not supported.
    at Object.throw_ [as throw] (errors.dart:194)
    at Object.loadFontFromList (text.dart:1384)
    at font_loader.FontLoader.new.loadFont (font_loader.dart:75)
    at font_loader.dart:62
    at _RootZone.runUnary (zone.dart:1379)
    at _FutureListener.then.handleValue (future_impl.dart:137)
    at handleValueCallback (future_impl.dart:678)
    at Function._propagateToListeners (future_impl.dart:707)
    at _Future.new.[_completeWithValue] (future_impl.dart:522)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:552)
    at Object._microtaskLoop (schedule_microtask.dart:41)
    at _startMicrotaskLoop (schedule_microtask.dart:50)
    at async_patch.dart:166

Flutter doctor output:


[✓] Flutter (Channel master, v1.10.2-pre.950, on Mac OS X 10.14.6 18G87, locale en-US)
    • Flutter version 1.10.2-pre.950 at /Users/johnsonmh/mdc/flutter
    • Framework revision 6cb6857f92 (13 days ago), 2019-11-14 16:50:17 -0500
    • Engine revision 77c3512ec8
    • Dart version 2.7.0


[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/johnsonmh/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-stable, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.0, Build version 11A420a
    • CocoaPods version 1.7.5

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio
    • Android Studio at /Applications/Android Studio with Blaze.app/Contents
    • Flutter plugin version 41.2.3
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (4 available)
    • iPhone 11 Pro Max • 51ED21D6-0095-4C79-8B9B-A556005909CF • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)
    • macOS             • macOS                                • darwin-x64     • Mac OS X 10.14.6 18G87
    • Chrome            • chrome                               • web-javascript • Google Chrome 78.0.3904.108
    • Web Server        • web-server                           • web-javascript • Flutter Tools

! Doctor found issues in 1 category.
@johnsonmh
Copy link
Contributor Author

The above demo does not compile on MacOS Desktop either.

@jonahwilliams
Copy link
Member

Duplicate of #45459

@jonahwilliams jonahwilliams marked this as a duplicate of #45459 Nov 27, 2019
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants