Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Element' is imported from 2 packages

i'm trying to use html parsing with dart in a Flutter App:

Future getSomething() async {

  http.Response response = await http.get('https://news.ycombinator.com/');

  Document document = parser.parse(response.body);

  document.getElementsByTagName('a').forEach((Element element){
  print(element.text);
  });
} 

But i have an error in (Element element) :

Compiler message: lib/main.dart:7:1: Error: 'Element' is imported from both 'package:flutter/src/widgets/framework.dart' and 'package:html/dom.dart'.

like image 246
Fatima TT Avatar asked Apr 14 '26 07:04

Fatima TT


1 Answers

You can hide Element from the flutter import:

import 'package:flutter/widgets.dart' hide Element;

You can also use alias:

import 'package:flutter/widgets.dart' as widgets;

like image 197
Rémi Rousselet Avatar answered Apr 15 '26 22:04

Rémi Rousselet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!