Ad

How Can I Get Web Site Title In Flutter?

- 1 answer

I want to get the title of a given website address in flutter. Example a website title : <title>Some Value</title>. How can i get Some Value in title tag?

Ad

Answer

Use the html package so that you can parse the HTML content of the website. Then you can use querySelector('title')!.text to get the text of the <title> element.

import 'package:html/parser.dart' as html_parser;

void main() {
    const html = '<title>Some Value</title>';
    var doc = html_parser.parse(html);
    final value = doc.querySelector('title');
    print(value!.text);
}
Ad
source: stackoverflow.com
Ad