Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Import dart file in flutter

I’m working on a flutter project and I want to import a dart file in my main file but I don’t know how to do it.
I import my dart file first import 'package:splash/Categories.dart';
and I initialized it like that final Category _category = Category();
but I have this error Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
Please how can I fix it. Thank you in advance

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This happens when the same class is in two different files. So if you want to use a specific class in specific file we need to use aliases.

Example:

import 'package:splash/Categories.dart';
import 'package:something/Something.dart' as name;

Use classname in in Something.dart as name.class_name

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading