In my project there is an error occurs
The name 'MenuItem' is defined in the libraries
'package:emarket_user/view/base/mars_menu_bar.dart' and
'package:flutter/src/widgets/platform_menu_bar.dart'.
(ambiguous_import at [emarket_user] lib\view\base\menu_bar.dart:10)
please help me to solve this
The class MenuItem is an abstract class for describing cascading menu hierarchies that are part of a [PlatformMenuBar] package.
in the second line import you're importing this class in this line:
import 'package:flutter/src/widgets/platform_menu_bar.dart';
but in this line 'package:emarket_user/view/base/mars_menu_bar.dart' you are importing from a library or class that you wrote, maybe you have wrote it and then delete it or renaming without refactoring it. try to remove that line of import or change the class name in platform_menu_bar.dart.
Related
I'm facing an issue where I'm trying to split the code up into different files (to make it neater). So far the import is working except for one file.
Currently, my flutter project is setup in this manner
However, one of my files is not importing correctly.
This is my chorusSearch.dart file:
I've tried importing a class from chorusPage.dart. But the import is not resolving.
What is wrong here? This is my chorusPage.dart file.
You cannot call a method or a function of a class that should be instantiated.
You are trying to access a method inside a private class (with the _ char before) of a class that should be initialized before.
If you want to create functions that don't require a view, a page and nothing visual you should make public and static classes and create something like an utility.dart class that contains them.
Then you can call Utility.yourfunction() from where you want
A little example
file utility.dart in lib/utils/
void your_method() {
//do something
}
then in place you can import the file utility.dart and you can also assign to it a name with "as" like this -> import 'package:appname/utils/utility.dart' as Utility;
then you can use Utility.your_method()
What is causing Eclipse to NOT recognize and consequently not offer any suggestion on an import of JsonParser.Feature as shown in the picture below:
Manually adding the static import of com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES (commented in the picture above), however, works fine.
Would it be the case that something is eclipsing the file on the classpath, and if so - what is Eclipse's strategy on resolving those conflicts? Or is it something else?
Thank you in advance.
You cannot use JsonParser class to access Feature since it is not a static member of the class. Instead you can directly use the Feature class :
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
I can suggest 2 workarounds:
Use AutoComplete (Ctrl + Space) to suggest classes:
Add . to class Name (JsonParser.) and then remove it (JsonParser) it will suggest all JsonParser classes:
For example, I have two files called file1.swift and file2.swift.
file1.swift:
import UIKit
class A: B {
}
file2.swift:
import UIKit
class C: A{
}
I am reading that public class can not subclassed outside of module. Here I have subclass C. I am trying to understand what does module mean here. I imported to same module UIKit for both file. So the both files are of same module? So that I can subclassed. Or both files have different module even I import the same UIKit?
Can anybody explain what is module?
Source:
Classes with public access, or any more restrictive access level, can be subclassed only within the module where they’re defined.
Class members with public access, or any more restrictive access level, can be overridden by subclasses only within the module where they’re defined.
A module is a single unit of code distribution—a framework or application that is built and shipped as a single unit and that can be imported by another module with Swift’s import keyword.
Each build target (such as an app bundle or framework) in Xcode is treated as a separate module in Swift. If you group together aspects of your app’s code as a stand-alone framework—perhaps to encapsulate and reuse that code across multiple applications—then everything you define within that framework will be part of a separate module when it’s imported and used within an app, or when it’s used within another framework.
As the docs indicate, the module is an application or a framework (library). If you create a project with classes A and B, they are part of the same module. Any other class in the same project can inherit from those classes. If you however import that project to another project, classes from that another project won't be able to subclass A nor B. For that you would have to add open indicator before their declarations.
Basically, if you work on a single app then you are working in one single module and unless declared as private or fileprivate, the classes can subclass each other.
EDIT
Let us have following class in module (project) Module1:
class A {
}
Since this class is not open, it can be subclassed only within the same module. That means that following class:
class B: A {
}
Can be written only in the same project, in Module1.
If you add Module1 as a dependency to project Module2, and try to do this:
import Module1
class C: A {
}
It will not compile. That's because class A is not open (in other words it has access public or less) and it does not belong to the same module as C. A belongs to Module1, C belongs to Module2.
Note
import keyword imports a dependency module to your current module. If you write import UIKit in your project, you are telling the compiler that you want to use module UIKit in your module. import does not define current module. Current module is the current project.
Adding import UIKit at the beginning of the file does not change nor define to which module the file belongs. It just tells the compiler that in that file you want to use code from UIKit module.
Swift module(.swiftmodule)
History:
[#include -> #import] -> [Precompiled Headers .pch] -> [#import Module(ObjC);] -> import Module(Swift)
There are two type of Module - folder and file
.swiftmodule folder. Folder contains all .swiftmodule files for architectures and other meta information like:
.swiftmodule file. It is binary file format which contains Abstract Syntax Tree(AST) or Swift Intermediate Language(SIL) of framework's public API.
.swiftdoc - attached docs which can be revived by consumer
.swiftinterface - Module stability
[.swiftinterface or Swift Module Interfaces] is a next step of improving closed source compatibility
When you Jump to Definition of imported module actually you reviewing public interface of .modulemap
Binary(library, framework) can contains several modules, each module can contains a kind of submodule(from Objective-C world) thought.
import struct SomeModule.SomeStruct
These modules can have dependencies between each others.
Module is a set of source files which solves the same problem that is why they can be grouped under the same model name.
Module helps to group sources to reuse them
Module helps Xcode to minimize build time(open source)(If module was not changed it should not been recompiled)
Also Module is a kind of scope which can help compiler to figure out which exactly class to use. If two modules use the same name you get
Ambiguous use of 'foo()'
It can be solved by:
import ModuleName1
import ModuleName2
func someFunc() {
ModuleName1.SomeClass.foo()
ModuleName2.SomeClass.foo()
}
I'm writing a dart file:
import 'something.dart'
part of my_lib;
class A{
//...
}
I have tried this with the import and part of directives reversed and it still won't work, can you not have a class file as part of a library and have imports?
All your imports should go in the file that defines the library.
Library:
library my_lib;
import 'something.dart';
part 'a.dart';
class MyLib {
//...
}
a.dart
part of my_lib;
class A {
//...
}
Since a.dart is part of my_lib it will have access to any files that my_lib imports.
The Pixel Elephanr's answer is correct, but I suggest the alternative syntax for the part-of directive:
my_file.dart
(the library main file):
//This now is optional:
//library my_lib;
import 'something.dart';
part 'a.dart';
class MyLib {
//...
}
a.dart
(part of the same library; so in it you can reference the elements imported in my_file.dart)
//Instead of this (whitout quotes, and referencing the library name):
//part of my_lib;
//use this (whit quotes, and referencing the library file path):
part of 'my_file.dart'
class A {
//...
}
In the Doc you can found both the syntax, but only using the part-of's syntax with quotes (pointing to the file path), you can omit the library directive in the library main file; or, if the library directive is still needed for other reasons (to put doc and annotations to library level), at least you won't be forced to keep in sync the library name in multiple files, which is boring in case of refactoring.
If you are facing this in IntelliJ IDEA or Android Studio while moving the files via drag and drop, then switch to 'Project Source' in project pane at left and then move(drag and drop). When I faced this problem while working with flutter, this worked for me.
I added the Facebook sdk code to my project then I got this error because I already had a json library, so I deleted the Facebook json library from my computer and from the project but I still get this error. I search the whole project for "#interface SBJsonBase" and I only get one result. How can it say it's a duplicate when I only have one interface? Is it including the file twice? Does the search not always find everything?
May be this helps? Delete your derived data and do a clean project, then try to build again
I had a simular problem. It was a small search, but I could solve it without creating a new project etc...
The thing was I had a Class B that was importing Class A.
Then I had a class that imported Class B and also Class A.
When I did this, these problems occured.
Eg. A SOAP webservice Class imports all the Entities that are passed over the web.
Class goToSchoolWebservice.
import "person.h"
import "school.h"
...
Then I had a Singleton class used for caching that had the Logged in Person and also a ref to the webservice class.
import "person.h"
import "goToSchoolWebservice.h"
--> this is where is went wrong!!
So watch out for these circular references. ITs not so easy to detect them!
if your using #include instead of import then use this technique to minimize duplicates: at the begining of your interface (actually right before it) do check for a definition and if not defined then define it and proceed to define your interface. here is an example:
#ifndef __NetworkOptionsViewController__H // check if this has every been imported before
#define __NetworkOptionsViewController__H
#import "blahblah.h"
#interface NetworkOptionsViewController : UITableViewController
{
NSMutableArray* somevariable1;
int somevariable2;
}
#end
#endif
-- for me personally, i got this error though because the file path to my class was wrong. I checked file inspector and my class file was not defined in Classes folder even though the IDE said it was. I deleted them and copied them over again.
For those that still get this error, despite following header import conventions: I got this error from importing a header that had been deleted from the project. The missing header was instead found in an old backup of my project in dropbox (That I made before doing some destructive stuff in Git), and that file caused the circular import.
I solved a similar problem by moving all the imports to the prefix header file.