Search code examples
flutterdartmaterial-uiflutter-layoutstatefulwidget

Text widget font not appearing correctly


I've created a separate page with a StatefulWidget inside my Flutter app, and it has a Text widget inside of it.

However, when testing my app, the text does not render as intended - instead it shows up in a weird font with yellow underlining.

Here's my code:

import 'package:flutter/material.dart';

class ListsPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ListsPageState();
  }
}

class _ListsPageState extends State {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Text('Log in page'),
    );
  }
}

Results image


Solution

  • Please remove Material Widget just return Text Widget Only, and please try to use the Stateless widget for better performance. Here's the example code

     import 'package:flutter/material.dart';
     import 'package:show_case/diementions/text_size.dart';
    
    class TextWidget extends StatelessWidget {
      const TextWidget({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Text(
          'Login Page',
          style: kLabelStyle,
        );
      }
    }