Yellow lines under Text Widgets in Flutter?

FlutterDartUnderlineFlutter WidgetText Widget

Flutter Problem Overview


Working on my first flutter app. The main app screen doesn't have this issue, all the texts show up as they should.

However in this new screen I'm developing, all the text widget have some weird yellow line / double-line underneath.

Any ideas on why this is happening?

Yellow Lines

Flutter Solutions


Solution 1 - Flutter

The problem is having a Scaffold or not. Scaffold is a helper for Material apps (AppBar, Drawer, that sort of stuff). But you're not forced to use Material.

What you're missing is an instance of DefaultTextStyle as a parent:

DefaultTextStyle(
  style: TextStyle(...),
  child: Text('Hello world'),
)

Various widgets add one to change the default text theme, such as Scaffold, Dialog, AppBar, ListTile, ...

It's DefaultTextStyle that allows your app-bar title to be bold by default for example.

Solution 2 - Flutter

Add Material widget as root element.

@override
  Widget build(BuildContext context) {
    return Material(
        type: MaterialType.transparency,
        child: new Container(

Solution 3 - Flutter

All you need to do is provide a Material widget, or a Scaffold which internally covers this widget.

  • Using Scaffold:

    Scaffold(body: Text('Hi'))
    
  • Using Material:

    Material(child: Text('Hi'))
    
  • Setting style property:

    Text(
      'Your text',
      style: TextStyle(decoration: TextDecoration.none), // removes yellow line
    )
    

Solution 4 - Flutter

Text style has a decoration argument that can be set to none

Text("My Text",
  style: TextStyle(
    decoration: TextDecoration.none,
  )
);

Also, as others have mentioned, if your Text widget is in the tree of a Scaffold or Material widget you won't need the decoration text style.

Solution 5 - Flutter

Also you can use decoration: TextDecoration.none to remove underline

Solution 6 - Flutter

Just adding another way I encounter to these answers.

Wrap the root Widget around a DefaultTextStyle widget. Altering each Text widget is not a necessity here.

DefaultTextStyle(
    style: TextStyle(decoration: TextDecoration.none), 
    child : Your_RootWidget
)

Hope it helps someone.

Solution 7 - Flutter

You should add Material and Scaffold widgets in main.dart file

 MaterialApp(
  home: Scaffold(
    body: Text('Hello world'),
  ),
);

Solution 8 - Flutter

You just need to add Material root widget.

      @override
       Widget build(BuildContext context) {
      return Material(
         child: new Container(),
        );
       }

Solution 9 - Flutter

There is an other solution for this , especially if you are using multiple pages wrapped under main.dart file You can do something like this:

  child: MaterialApp(
    home: Material(child: Wrapper()),
  ),

This will remove the yellow lines under text that is present in any pages referenced/used under wrapper.

Solution 10 - Flutter

problem: your widget doesn't have default text style,

solution: wrap it in one!

DefaultTextStyle(
    style: TextStyle(),
    child: yourWidget,
  );

remember if you dont set any color, default text color is white!

Solution 11 - Flutter

The yellow lines come from _errorTextStyle. The documentation states that you should define a DefaultTextStyle parent (or use Material, which does this for you):

> MaterialApp uses this TextStyle as its DefaultTextStyle to encourage developers to be intentional about their DefaultTextStyle. > > In Material Design, most Text widgets are contained in Material widgets, which sets a specific DefaultTextStyle. If you're seeing text that uses this text style, consider putting your text in a Material widget (or another widget that sets a DefaultTextStyle).

Developing Flutter apps without material is not something most people do, but if that's your use case, you should use DefaultTextStyle.

Contrary to the accepted answer, Theme does not set a DefaultTextStyle, so it does not solve your problem. Scaffold does solve the problem, as it contains Material, which in turn defines DefaultTextStyle, but Scaffold is a bit more than you need for a Dialog, Hero, etc.

To permanently solve this for your whole app, you could set the DefaultTextStyle in your MaterialApp builder. This solves the issue for all the components of your app, not just the current screen you're working on.

Solution 12 - Flutter

Before

enter image description here

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Center(
          child: Text(
            "21:34",
            style: TextStyle(fontSize: 50),
          ),
        ),
        Center(
          child: Text(
            "Wakey - wakey",
            style: TextStyle(fontSize: 20),
          ),
        )
      ],
    );
  }

After (Solution):

Here Wrap the current top or parent widget with Scaffold widget

enter image description here

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: Text(
              "21:34",
              style: TextStyle(fontSize: 50),
            ),
          ),
          Center(
            child: Text(
              "Wakey - wakey",
              style: TextStyle(fontSize: 20),
            ),
          )
        ],
      ),
    );
  }

Full code:Dartpad or Live code

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(home: sta()));

class sta extends StatefulWidget {
  const sta({Key? key}) : super(key: key);

  @override
  State<sta> createState() => _staState();
}

var isShow = false;


class _staState extends State<sta> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: Text(
              "21:34",
              style: TextStyle(fontSize: 50),
            ),
          ),
          Center(
            child: Text(
              "Wakey - wakey",
              style: TextStyle(fontSize: 20),
            ),
          )
        ],
      ),
    );
  }
}

Solution 13 - Flutter

Add DefaultTextStyle under builder of our MaterialApp like so:

child: MaterialApp(      
  ...
  ...
  theme: yourThemeData,
  builder: (context, child) => DefaultTextStyle(
    style: yourThemeData.textTheme.bodyText1,
    child: child,
  ),
),

By doing so we don't need to specify a style or having DefaultTextTheme every time we want to use showDialog or Overlay.

Solution 14 - Flutter

The text has a hidden default text style .The problem arises because you can't provide this to any parent widget like Scaffold. Text widget takes the default style. for your solution either you can change the DefaultTextStyle like this.

DefaultTextStyle(
    style: TextStyle(),
    child: yourTextWidget,
  );

or just wrap into Scaffold, Scaffold is a widget. that provides scaffolding for pages in your app. like this

 MaterialApp(
  home: Scaffold(
    body: Text('Wakey Wakey!'),
  ),
);

for more info just walk through this Flutter Official video.

Yellow underline text | Decoding Flutter

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondasfimaView Question on Stackoverflow
Solution 1 - FlutterRémi RousseletView Answer on Stackoverflow
Solution 2 - FlutterDyvokerView Answer on Stackoverflow
Solution 3 - FlutterCopsOnRoadView Answer on Stackoverflow
Solution 4 - FlutterAaron HalvorsenView Answer on Stackoverflow
Solution 5 - FlutterAnirudh SharmaView Answer on Stackoverflow
Solution 6 - FlutterNikhileshwarView Answer on Stackoverflow
Solution 7 - FlutterkokemomukeView Answer on Stackoverflow
Solution 8 - FlutterParas SharmaView Answer on Stackoverflow
Solution 9 - FlutterAbdulmananView Answer on Stackoverflow
Solution 10 - FlutterAli80View Answer on Stackoverflow
Solution 11 - FlutterAndrei Tudor DiaconuView Answer on Stackoverflow
Solution 12 - FlutterlavaView Answer on Stackoverflow
Solution 13 - Flutterb.benView Answer on Stackoverflow
Solution 14 - Fluttershirsh shuklaView Answer on Stackoverflow