How do I create a pub package that works with Flutter? - dart-pub

pub is Dart's package manager. Flutter is a mobile app SDK that uses Dart. How can I create a package that depends on, or targets, Flutter?

To declare a dependency on Flutter, from a pub package, add this to your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
You must use flutter packages get instead of pub get, because Flutter needs to set the appropriate environment variables to map the sdk: flutter to a location.
To easily and quickly create a new pub package, use the stagehand tool. After you install stagehand, follow these instructions:
$ mkdir fancy_project
$ cd fancy_project
$ stagehand package-simple
After you create your new package, edit the pubspec.yaml and add the sdk:flutter as shown above.

A trick I also use is to just flutter create foo (which creates a full-fledged Flutter app, more than you need) and then rm -rf foo/ios foo/android and edit/remove foo/lib/main.dart, etc.
The stagehand solution from #sethladd is more elegant, but requires having installed stagehand.

flutter create now supports templates.
The package template creates exactly that:
flutter create -t package
or to create a plugin that depends on platform-specific code:
flutter create -t plugin

Related

Adding Pallets to Substrate

This is a very basic question, but I am following the "nicks" tutorial from the Substrate network, and it's not very clear how - after I have added the pallet - I install or "pull in" these dependencies so I can inspect the code. I was expecting something like node_modules folder where everything is put once you run npm i, but that is a different environment. I have run cargo build but to no avail. Please advise.
When you add dependency in Cargo.toml, by default, the actual dependency will download and store on global Cargo registry $HOME/.cargo/ and specify the version in Cargo.lock inside project directory, not the actual dependency.
For a tutorial on Substrate, after adding Nick's pallet and running cargo build, you can check the code of downloaded pallet_nick in $HOME/.cargo/. The easiest way is to download rust_analyzer plugin to your VSCode and CRTL + Click to the dependency name inside Cargo.toml, it will take you to the library.

How to change app package name in Flutter without using Android Studio?

As you know, app package name (**com.****.******) is very important thing in Flutter app, it is also being used in app's link on Play Store, and some other places.
So, I have a app package name which is automatically created by flutter when creating app via command line: com.example.app
How can I change it properly? There are lots of files and folders named after the app package name, so changing app package name manually without causing error is something I seek.
You need to change it in
android/app/build.gradle
android/app/src/main/kotlin/com/example/personal_web/MainActivity.kt
android/app/src/main/AndroidManifest.xml
There's a useful package for changing it but it works well with android, I didn't try for IOS.
Firstly install the package:
change_app_package_name: ^1.0.0
Then in terminal in your project paths do these commands:
flutter pub get
Then write the line below and use the unique name you want after com. then press enter:
flutter pub run change_app_package_name:main com.myuniquename.flutter_app
it will update files and delete old package name.
You need to change it in the following files.
android/app/build.gradle
android/app/src/main/kotlin/com/example/personal_web/MainActivity.kt
android/app/src/main/AndroidManifest.xml
android/app/src/main/profile/AndroidManifest.xml
android/app/src/debug/AndroidManifest.xml
From the documentation:
Your application ID is defined with the applicationId property in your
module's build.gradle file [...]
Flutter: Open /android/app/build.gradle, scroll down to applicationId.
The most appropriate command would be flutter create --org com.changehere -a kotlin -i swift yourapp_name

How to set up googletest wtih meson?

I have a git repository with some test code in C++ and I want to use Googletest to write some tests. I used git submodule to get it as part of the above repository. I want to use meson as the build engine. So far, so good.
However, I cannot fathom how to get meson to build and link my tests with the googletest submodule… Should I use a wrap? An external dependency? what?
Note that meson supports dependencies on packaged versions of gtest/gmock but this is not what I want since the developers of gtest/gmock recommend against it. Plus, I want bleeding edge 'cause I am crazy⸮
Furthermore, I do not think ninja plays a role here but I mentioned that I use it just in case.
I tried using the wrap for gtest with
gtest_proj = subproject('gtest')
gtest_dep = gtest_proj.get_variable('gtest_dep')
gmock_dep = gtest_proj.get_variable('gmock_dep')
in meson.build. This builds a local copies of googletest which can then be used like so:
tests_src = [
'tests/gtest-all.cpp',
'tests/test_MyClass.cpp',
]
e = executable(
'gtest-all',
tests_src,
dependencies : [
gtest_dep,
gmock_dep],
link_with : libshield,
)
test('gtest tests', e)
Note that libshield is a shared library created from my (toy) code so I can link to it.
If you would like to use a project that is not meson project you need to find that project in wrapDB:
meson wrap search gtest
If that command gives you name of the wrap then you need to install it to your project:
mkdir -p subprojects
meson wrap install gtest
Then you should reconfigure your project and meson will download that project for you:
meson --reconfigure path/to/build/dir
Additional information you can find in documentation of wrap tool.
--reconfigure - supported since 0.49.0

DocuSign Objective C REST API setup

I'm trying to set up an Objective C XCode project to test DocuSign API for request a signature via email recipe. These are the steps I've been through now.
Downloaded ObjC client
Copied code from GitHub (docusign-rest-recipes/core_recipes/CoreRecipes.m)
Created a new xcode project with ObjC client and GitHub code.
I now get JSONModel/JSONModel.h file not found.
Please help me on this.
Try installing through Cocoapods if you're having issues with a manual copy. There are instructions listed in the README at the root level of the repo:
https://github.com/docusign/docusign-objc-client
CocoaPods Install
Create a podfile, run pod install, then use the .xcworkspace project file moving forward. To use the clients in this manner, do the following:
At the command line run the following RubyGems command to install cocoapods (note: this might require sudo):
$ gem install cocoapods
Create a file in your root project directory called Podfile with the following content. Replace the two references to PROJECT below with your unique project name:
$ pod 'DocuSignESign', '~> 2.0.0'
Run the following command in the same directory as your Podfile:
$ pod install
Once you are done installing, close Xcode and open the newly created .xcworkspace project file. Make sure you use this work space going forward!

Cordova CLI, using Git, and saving plugins/platforms

I'm trying to figure out how to reconcile some Cordova + git "best practices" with what I think is reality, and I'm hoping someone can shed some light on this for me.
If I understand correctly, the current "best practice" is to add these directories to my .gitignore (from the book "Developing with Cordova CLI", the current version):
platforms/
plugins/
node_modules/
This removes the easily downloadable plugins and mostly boilerplate platform code from version control because it can be easily generated with a simple Cordova CLI command.
But, this seems counter-intuitive because - and I'm thinking like NPM or Bower - with the Cordova CLI I can't save which platforms and plugins I'm using in a config file. With NPM, I can add a --save switch to save the package in the package.json file. This allows me to not version control my node_modules folder and instead use 'npm install'. With the Cordova CLI I can't seem to use the --save switch (is there an equivalent) to 'remember' the plugins or platforms I intend to use.
It seems that the config.xml file in the www/ directory doesn't save which platforms or plugins have been added.
Is there some other file in the project that keeps a memory of which platforms and plugins I want to use? How does it work?
Cordova 4.3.0 + allows you to save and restore platforms and plugins. Saved information is stored in config.xml file. See v5.0.0 release notes and the official Cordova docs.
You can save platforms and plugins using the --save option when you add them:
cordova platforms add PLATFORM --save
cordova plugins add PLUGIN --save
Or you can save platforms and plugins that are currently added:
cordova platforms save
cordova plugins save
By doing this there is no need to check in platforms or plugins into your code repository. They will be automatically restored based on your config.xml file when cordova prepare command is run.
I typically write a hook to capture the plugins I want to use in my project. You can see this in an article I wrote here: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/
With the new modular architecture of Cordova 3.x, every app needs plugins, even to use basic functionality such as logging or geolocation. Rather than document which plugins/features your project needs and ask each new developer to install them, download and install them automatically with a hook in the after_platform_add step. Using this plugin, every time a developer checks out the project and adds a platform, they automatically have the required plugins.
You also may be interested in following along with this bug, which suggests npm style --save functionality: https://issues.apache.org/jira/browse/CB-5775
Platforms are a little more difficult because they don't fit into the hook architecture, but you could write a shell script which you could execute to add your platforms.
#!/bin/sh
for plat in ios android; do
cordova platform add $plat
done
You could do something similar with the version of cordova you have installed in node_modules (at least that is what I think you are installing in node_modules)--have shell script to get the correct version of cordova:
#!/bin/sh
VERSION=3.3.1-0.4.2
npm install cordova#$VERSION
PS Glad you liked the book!

Resources