Flutter provides a plugin package that allows code to be moduelled and shared. This makes it easier to compontize flutter, rather than building applications from scratch, just like iOS Cocopods.

create

A minimum package includes: (1) a pubspec.yaml file: a metadata file that declares the name, version, author, etc of the package. (2) A lib folder: include the public code in the package, and at least one.dart file

I use Android Studio, and I can create a Pulgin or package. One is a combination of Android and iOS, and the other is pure Dart code

release

There are several ways to publish:

(1) Local dependency

Local dependency is to add your plug-in project locally to an existing project, and then add the dependency to pubspec.yaml, demo: path: pathname

(2) Public library

The flutter packages pub publish –dry-run command can be used to publish flutter packages pub publish –dry-run. Flutter packages pub publish Flutter packages pub publish –server=pub.dartlang.org what is wrong with flutter packages pub publish –server=pub.dartlang.org

Dependencies: rxdart: 0.22.6Copy the code

(3) Private library

You can upload the flutter packages pub publish –server=http://192.168.0.1:8080 192.168.0.1 command to your own server only for internal use. The quoted format is as follows

Flutter_screenutil: Hosted: Name: Flutter_screenutil URL: http://192.168.0.1:8080 version: 4.0.2Copy the code

The problem

I also encountered some problems in the upload, but also in this share: (1) Publish public and private libraries can not connect to the server this is because no matter you publish public or private libraries, will pass The verification of Google, there will be problems in China, so to cross the wall, publish public this step is not omitted, must be verified, but publish private words, this step can be bypassed. Download items: github.com/ameryzhu/pu… Then perform

dart --snapshot=mypub.dart.snapshot bin/pub.dart 
Copy the code

The mypub.dart.snapshot file will be added to the project root directory after completion

After copying the file, save it to ${flutterSDK Path}/bin/cache/dart-sdk/bin/snapshots/

Open ${flutterSDK Path}/bin/cache/dart-sdk/bin/pub with TXT editor

Replace the third from last line: pub.dart.snapshot with mypub.dart.snapshot

This allows the publication of private packages to be completed without validation

(2) pub did not create. Dart_tools /package_config.json file

If you use your own mypub.dart. Snapshot file, this error will be reported when you perform pub get to clear the cache

(3) Private library header file not found

I really want to ridicule Android Studio for this problem. Clearing the cache is useless, because my project was locally dependent at the beginning, and then transferred to the private server, and deleted the local one. As a result, there was always a cache in the project, so I could not find the files at the end