skip to Main Content

I use flutter widget Text() for displaying data which comes from API. For example, I got this string with html-content

String test = "List: <li> One;<li> Two;<li> Three.";

My widget with this variable:

Text(test)

Is there a way to remove all html-tags from String value?

2

Answers


  1. To remove html tags from a string you can use this code:

    final text = 'List: <li> One;<li> Two;<li> Three.';
    text = text.replaceAll(RegExp(r'<.*?>'), '');
    

    You can change the RegExp according to your needs.

    Login or Signup to reply.
  2. This extension should do it

    extension StringExtension on String {
      String stripHtml() => replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), '');
    }
    

    Then use it like

    Text(test.stripHtml())
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search