Jens
Jens

Reputation: 2702

FontWeight not working when using GoogleFonts

I am using Flutter Web (which is currently in beta) and it seems that the FontWeight of the Text Widget is not working properly while using GoogleFonts. The problem does not exist when the default Font is used.


Project:

The project was created with the following commands

flutter channel beta 
flutter upgrade 
flutter config --enable-web
flutter create web_font_not_working

Example Code:

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          textTheme: GoogleFonts.montserratTextTheme()),
      home: HomePage(),    
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'This text should be bold',
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
        Text('This text is normal'),
      ],
    ));
  }
}

Result of the Example Code:

enter image description here

Side effects:

When saving the code, the browser refreshes as expected and shows a bold text for a short time. After the page is fully loaded the website looks as shown above.

Question(s):

  1. Am i doing something wrong?
  2. Is this a bug in the software?
  3. Is the GoogleFonts Package not supporting web yet? If this is the case what is a suitable workaround?

Upvotes: 1

Views: 1899

Answers (2)

Jens
Jens

Reputation: 2702

The question is now obsolete.

I am currently using flutter 1.21.0-9.1.pre and google_fonts is working as expected.

If you have a similar problem upgrade to the most recent flutter version.

Upvotes: 0

Vitor
Vitor

Reputation: 840

As you can see down below, google_fonts currently only supports ANDROID and IOS.

I think you might consider filtering your search when looking for a new plugin. This way, it will only show packages that support flutter web.

Also, you may want to take a look on this post as it shows how to change fonts on flutter web

Upvotes: 1

Related Questions