Mathias Bak
Mathias Bak

Reputation: 5115

Import issue - libraries should not have the same name

I am trying to build a library that currently has the following structure

lib
 | src (contains some internal .dart files)
 |  | private_parts.dart
 | strategies (contains sample strategies for applications)
 |  | scoring.dart
 |  | time.dart
 | mylib.dart (the main library file to include)

My problem occurs when I try to write an application that uses the sample strategies. I get the error/warning The imported libraries 'scoring.dart' and 'time.dart' should not have the same name ''.

My main file looks something like this (placed in the web folder)

import 'package:mylib/mylib.dart';
import 'package:mylib/strategies/scoring.dart';
import 'package:mylib/strategies/time.dart';

main() {
    game = new Engine(new StandardTime(), new StandardScoring());
}

How should I restructure the library to make it correct? What is best practice?

Upvotes: 3

Views: 373

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657268

Your code doesn't show a library directive so I suppose more than one library has the library name 'NONE'.

Add a library directive at the top of your dart source file

library my_library.my_sublibrary; // <= this should differ for each library

In dart each source file is a library as long as you don't add

part of some_library

instead of the library directive. Adding no library or part of directive makes it implicitely a library without a name.

Upvotes: 4

Related Questions