I have on project on pure dart (the server).
And another one in flutter (the client).
How can I easily share the folder lib/model with my another project?
I want to use the same collection of class in both projects.
Create a dart package which can be used in both server and client.
$ dart create -t package <PACKAGE_NAME>
See Creating packages for details.
The package can be published, used directly from git or used locally (e.g. mono repo), see Using packages.
I can do this by
A. I create a folder test_project
B. In the test_project folder, I create the dart server project by using dart create test_project_server and create the folder to share anything that I want by using dart create test_project_share.
Now you have folders/projects test_project_server and test_project_share in the test_project folder.
C. Open the project test_project_share and create the file share_class.dart in the lib folder. Copy my example class and paste this code into this file.
class ShareClass {
static String value = "Hello World";
}
D. Open the test_project_server project and add this code below the dependencies of the pubspec.yaml file.
test_project_server:
path: ../test_project_server
E. Run pub get in the test_project_server terminal.
Now, you can call ShareClass from test_project_share to the test_project_server project. Hope this will help you.
Related
I've been using dart projects in order to practice dart programs and wondered why there are two folders bin and lib both can contain dart files.
I did some research about this and they said bin folder is for creating console application but that didn't help me. I don't have a clear idea about console application.
and why should I bother about these folder if I'm only using dart projects just for practicing dart language?
The bin folder is where you put the public entrypoints for your project to compile it to executable binaries for console applications.
If you are just practing dart code, you can leave it there and just use the lib folder. Just make sure you'll have a file inside bin with the same name as the project/package you created (defined in pubspec.yaml) and a main() function, so you can use dart run.
The lib folder is for all the other code you write. You can add in there all your classes files of your project as a additional code to be called by the files from the bin folder. Or you can use just the lib folder to write a package/library for other apps, without needing to have a bin folder.
But the bin folder can have a file for each command, with a main() inside each file.
For example, you could have in it bin/sum.dart and bin/subtract.dart. Then you can compile each to a executable binary (sum.exe and subtract.exe) to use it as a command-line/console program.
To run each file without compiling just use dart run :COMMAND (in the example above, dart run :sum).
If you want to know more about it, see the documentation explaining how to compile and how to write a package that has a command-line tool
I'm getting problem with flutter/dart. I created one flutter-package using dart lang, there is so many dart files. But i didn't get any option to make single lib file or assembly like dll (dll in Xamarin). I want to use that API in flutter mobile app [Android/iOS]. So is it possible to make single lib file in dart ? I don't want to show a source code to that person, who will use my API in Android/iOS & I don't want to publish my code to pub.dev.
I hope this is possible.
Thanks, i would be grateful.
You can store your package on your git repository and access them.
If the package is located at the root of the repo, use the following syntax:
dependencies:
plugin1:
git:
url: git://github.com/test/plugin1.git
https://flutter.dev/docs/development/packages-and-plugins/using-packages
I have downloaded an open source project, made changes to it and then created a nuget package from this new code. The package actually functions as a post-build target. It just runs an exe. That is why it does not contain a lib folder. There is a tools folder and files are copied under this folder. The other folders are: build, buildCrossTargeting, package, _rels. .But when I try to install this local nuget package to a .net 4.6.1 project, I get the following error in Visual Studio:
You are trying to install this package into a project that targets
'.NETFramework,Version=v4.6.1', but the package does not contain any
assembly references or content files that are compatible with that
framework.
When I open and inspect the original nuget package downloaded from nuget.org, I see the same structure. But somehow it installs fine while this locally created one raises error.
What can be done about it?
With the information you provided, I can only guess (please see How to create a Minimal, Reproducible Example). My guess is that you changed the name (id) of the package, but didn't change the name of the target or props files in the build directory. As the docs say, the name of the targets and props file must match the package id exactly, so if you change the package id, you must rename those files.
I'm trying to create a Dart backend framework that developers can download as a dependancy and have the basic folder structure, Dart files and such generated for them in their own project. From what I understand, downloading a dependancy package only places files inside the package directory/ies (although, I may be wrong).
To get around this, I believe Dart can be used like a Bash script, and can place files in the project directory automatically through running the package's bin files in the terminal (illustrated in the Running a script in a dependency https://www.dartlang.org/tools/pub/cmd/pub-run.html).
Would this be the best way to achieve the desired result? Or is there an easier way to download a framework as a project template? (I'd also like to place similar scripts for generating controllers and such in the tools directory, and don't know if keeping this framework as a dependancy would be necessary after 'install').
Thank you for reading.
You can use pub global activate some_package to be able to use pub global run some_package:some_script or just some_script to allow to run a script contained in a Dart package without adding it to the dependencies.
I think this is the best way to distribute it.
I have some automated tests that are using Selenium WebDriver. Tests should run on Chrome so I need to have ChromeDriver.exe. I am using NuGet to download the libraries and found that the ChromeDriver could be downloaded as a package too (http://www.nuget.org/packages/WebDriver.ChromeDriver).
However, this package contains only ChromeDriver.exe in the Tools folder. I need to copy this file into the bin folder because tests need to find it. Is there some way to do the copy in a generic way (without specific paths), because in the folder where the ChromeDriver.exe is unpacked from package contains version number so I would need to change the paths when the new version will be used. Also I would need to do similar thing with the NUnit.Runner package.
You could probably use a post-build event. Then inside the event use copy/xcopy and move it into the bin folder after the project has successfully built.