Yellow lines under Text Widgets in Flutter?

92,303

Solution 1

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

Add Material widget as root element.

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

Solution 3

All you need to do is provide a Material widget, or a Scaffold which internally covers this widget. You can do that in the following ways:

  • Use Material (simple and better):

    Material(
      color: Colors.transparent, // <-- Add this, if needed
      child: Text('Hello'),
    )
    
  • Set Text.style property:

    Text(
      'Hello',
      style: TextStyle(decoration: TextDecoration.none), // Set this
    )
    
  • Provide Scaffold:

    Scaffold(body: Text('Hello'))
    

Fixing yellow text issues when using Hero :

As aaronvargas mentioned, you can wrap your child in Material when using Hero on both sides. For example:

Hero(
  tag: 'fooTag',
  child: Material( // <--- Provide Material
    type: MaterialType.transparency,
    child: YourWidget(),
  ),
);

Solution 4

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

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

Share:
92,303

Related videos on Youtube

dasfima
Author by

dasfima

Updated on May 12, 2022

Comments

  • dasfima
    dasfima about 2 years

    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

    • Shady Aziza
      Shady Aziza over 6 years
      Can you add your code ?
    • Shady Aziza
      Shady Aziza over 6 years
      I suspect the reason is because you do not have a Scaffold on this page.
    • dasfima
      dasfima over 6 years
      @aziza I think you're right. This page doesn't have a scaffold. I suspected that might be the issue, but didn't follow through with checking it. Any ideas as to why this happens when I have no scaffold? I did not realise it was required. Should I just use a Scaffold anyway, even though I'm only gonna use the_body_ parameter?
    • Shady Aziza
      Shady Aziza over 6 years
      Each page needs a Scaffold, even if you are refactoring smaller widgets onto separate classes they should end up with a Scaffold parent somewhere. I am not sure if it is meant this way for the text to be underlined or it is an issue, regardless, you will end up needing to build any page within a Scaffold.
    • dasfima
      dasfima over 6 years
      @aziza very well. Thanks!
    • realpac
      realpac about 6 years
      Or if you donot want Scaffold, you can just surround your Text with Material widget
    • Andrey Gordeev
      Andrey Gordeev about 5 years
      Is this documented somewhere? Since I'm new to Flutter I couldn't figure out why my texts get double underline by default
    • John Melody Me
      John Melody Me over 3 years
      set decoration to none.
  • MMK
    MMK over 5 years
    surrounding the text or widget with Material widget helped me. Adding Material as root element didn't help in my case
  • 5422m4n
    5422m4n almost 5 years
    works both with type: MaterialType.transparency or without any.
  • tmele54
    tmele54 almost 5 years
    Also keep in mind for a Hero, it is disconnected from the parent while 'in flight' so adding a Material (or any Theme) as the Hero's child (BOTH sides) fixes it in the transition. See github.com/flutter/flutter/issues/30647
  • kitta
    kitta over 3 years
    @Rémi If you said Theme instance is missing in the parent, Why having Theme on top instead of Material or Scaffold doesn't help solve the problem? I just try it.
  • kitta
    kitta over 3 years
    Just an update, It's the DefaultTextStyle, not Theme that's missing.
  • kitta
    kitta over 3 years
    I just added another way to fix this in the answer below.
  • Srini2k6
    Srini2k6 about 3 years
    this workaround helped me to fix the yellow lines in hero animation. Thanks.
  • Juukie14
    Juukie14 almost 3 years
    Thanks for pointing out type: MaterialType.transparency,. Needed it because my child had rounded borders so I was seeing a white background.
  • Andrei Tudor Diaconu
    Andrei Tudor Diaconu almost 3 years
    Adding a Theme parent does not solve the problem. DefaultTextStyle is the missing parent, as per documentation
  • Happy Singh
    Happy Singh over 2 years
    Scaffold adding as parent fixes the issue, Thanks!!
  • Scorb
    Scorb about 2 years
    This is not an accurate answer. I have a Theme parent and the issue still exists.