import material package also imports key.dart and framework.dart Flutter

Viewed 363

After creating a new StatelessWidget, or a StatefulWidget, I decide to import material package so I can use Container and other widgets.

When I click on the lamp -> import material package it works correctly but also 2 more files have been imported.

To reproduce the error copy-paste the class below, remove all imports and try to import material package.

Example :

import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart'; //not used
import 'package:flutter/src/widgets/framework.dart'; //not used

class Foo extends StatelessWidget {
  const Foo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

It's weird because these 2 files are blue underlined and if I move my mouse over them this suggestion (for both) is shown :

The import of 'package:flutter/src/widgets/framework.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/material.dart'.
Try removing the import directive.

Simply removing them will fix but I would like to understand why this happens. I have installed this extension for VSCode called dart import maybe the error comes from here?

0 Answers
Related