I am trying to make a custom stepper in Flutter. I copied the implementation of stepper.dart, save my file to my own lib folder and fixed the imports to remove the errors.
import 'package:flutter/src/material/button_theme.dart';
import 'package:flutter/src/material/colors.dart';
import 'package:flutter/src/material/debug.dart';
import 'package:flutter/src/material/flat_button.dart';
import 'package:flutter/src/material/icons.dart';
import 'package:flutter/src/material/ink_well.dart';
import 'package:flutter/src/material/material.dart';
import 'package:flutter/src/material/material_localizations.dart';
import 'package:flutter/src/material/theme.dart';
import 'package:flutter/src/material/typography.dart';
Errors are removed but dart says that "Don't import implementation files from another package."
May I know if it's safe to proceed? OR is there another way to implement custom widgets? Or should I transfer the location of my custom stepper file? Thanks.
Flutter Material Widgets are not meant to be subclassed. Here is what I do to create a customized version of a Widget:
(1) Find the source file of the original widget and copy it to the lib directory of your project.
(you already did that)
(2) remove all import statements from the copied file and insert the line
import 'package:flutter/material.dart'; instead
(3) Check the Dart Analysis for missing packages. To add those click on the unknown (red underlined) class name in the copied source file then hit ALT+Enter and select the context menu entry that offers to add the missing dependency.
(4) Now modify the Widget to your hearts delight.
(5) to use the modified Widget in your project import it like this:
import 'stepper.dart' as my;
(6) You can now access your modified stepper as
my.Stepper stepper = my.Stepper(...);
lib/src from other packages is considered to be private by convention.
The analyzer explains that you shouldn't import such files.
Flutter exports everything it considers public under package:flutter/... anyway. Import these files instead.
See also https://www.dartlang.org/tools/pub/package-layout#implementation-files
Related
I am super new to unit testing and java in general, so my apologies for the basic question. However, when I try to import import static org.hamcrest.Matchers.hasEntry; I get a message saying "cannot resolve symbol 'Matchers'. I'm trying to use hasEntry to unit test a method that returns a map.
Here are the imports I have
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
the top two are working fine, but I can't get the last one to work. If anyone has any suggestions as to how to fix the problem, or if there is another way I can import hasEntry, please let me know! Thank you
Which version of Hamcrest are you using?
It would be great if you put your pom.xml file here to facilitate the analysis.
Maybe you only need to trigger another import maven command (with force update snapshots) in your IDE, for example, to refresh your local dependencies.
Or you can try this:
mvn --batch-mode --update-snapshots clean package
Basically I have a lot of widgets and services and stuff, like most people do, that I need to access throughout the app. I was wondering if have a single file with an export of every single file and then just simply importing that one file in every page/file i need to access something rather than just importing specific files that the page needs, will it slow down the app or cause any issues or increase file size, etc... or will it behave the same?
Example
login_page.dart
import '1.dart'
import '2.dart'
home_page.dart
import '2.dart'
import '3.dart'
import '9.dart'
import '10.dart'
settings_page.dart
import '1.dart'
import '2.dart'
import '9.dart'
import '10.dart'
or...
all_imports.dart:
export '1.dart'
export '2.dart'
export '3.dart'
... (up until)
export '10.dart'
in every dart file:
import 'all_imports.dart'
Using 'all_imports.dart' may cause unneeded dependencies but dart knows how to handle dependencies that called but not used.
Same implementation of 'all_imports.dart' is used by flutter team on 'material.dart'
You may wish to just make simple design but when you import 'material.dart' it brings everything to the table ('about.dart', 'app.dart', 'banner.dart') and many others.
I would advise you structure your application using 'all_import.dart' pattern
actually, it dosent make a difference, lets imagine this case
in login_page.dart
import '1.dart'
import '2.dart'
here you are being explicit about the dependencies of this module/file/widget, which means it only uses what it needs. which is better for maintenance and redablity of the modules dependanices.
the other case where you have all of your imports in one file
import 'all_imports.dart'
lets see what happens here:
Dart executes the file all_imports.dart
that file is importing every module that you have listed in that file
so the import calls happend again
which means that wont affect your software's performance if you dont have an all_imports.dart file.
actulally i find that this method(the all_imports.dart) will affect your program in a bad way if any.
why? lets say we have a module A that depends on both module B and module C , you would import them this way
moduleA.dart
import 'moduleB'
import 'moduleC'
the advantages is that the module is now explicit in its dependencies and anyone who looks at this module/file in the future will know what they are.
however
the other method where you have all of your imports in a single all_imports.dart file, will cause unneeded dependencies to be loaded for a certain module
lets have the same example above, module A depends on moduleB and moduleC and you listed them in the all_imports.dart file, it will look like this
export `moduleA'
export 'moduleB'
/// some other modules that you are exporting
and in the moduleA.dart file you import it this way
import 'all_imports.dart`
now
the module A has successfully imported moduleB and moduleC which it needs. BUT, now it has all the other dependancies that it dose not need loaded for it although it only needs moduleA and moduleB.
For example I need to import OneDrive SDK.
But I can't use cocoapods due to some reasons.
How to import this library as source files instead? The problem I have is all the import macro are surrounded with <>. For example this doesn't work:
#import <ADALiOS/ADUserInformation.h>
And this works:
#import "ADUserInformation.h"
But if it is possible to import them without of editing the source code?
For your header files, if you want to import with angle brackets, you should pass relative or the absolute path for your header directory to the compiler. Check this answer for more details.
I am using Groovy Grails Tool Suite for my Grails project.
I am trying to use LazyList.decorate in one of my domain classes and so want to import org.apache.common.collections.list within the domain class.
I see that org.apache.commons.collections_3.2.0.v2013030210310.jar is available under the GGTS plugins folder.
However, the editor shows an error at the import statement saying "Groovy: Unable to resolve org.apache.common.collections.list".
Please help!
Since the question is missing a code snippet I suspect you have a line like this import org.apache.common.collections.list. You should do import org.apache.common.collections.list.* - or if only LazyList is what you want: import org.apache.common.collections.list.LazyList
Create a sample web application using the Web UI (web_ui) library, e.g., mylib
open mylib.dart, make it a library:
library mylib;
import 'dart:html';
import 'package:web_ui/web_ui.dart';
part 'xclickcounter.dart';
...
open xclickcounter.dart, remove imports and insert:
part of mylib;
web/out/mylib.dart and web/out/xclickcounter.dart get messed up:
The included part ''xclickcounter.dart'' must have a part-of directive
Classes can only mixin other classes
Mixin can only be applied to class
... more errors follow
What am I doing wrong? Please help :(
Edit: if I don't edit generated sample code, wdc will generate code that falls into separate libraries:
web/out/xclickcounter.dart => x_click_counter
web/out/mylib.dart => mylib_html
Does it mean that if we use web_ui we should not create our own libraries and wdc will do this for us automatically?
Update: if I don't use any library name, similar to what generated sample code does, and only rely on the library names generated by xdc in web/out/... files, I still run into trouble when importing my two components into a 3rd file. Dart Editor will produce the following warning:
The imported libraries 'compa.dart' and 'compb.dart'
should not have the same name
The workaround is to name your libraries based on what xdc produces in web/out/... files, that is:
compa.dart => x-comp-a
compb.dart => x-comp-b
After explicitly placing components into libraries like these the Dart Editor warning disappears.