text stringlengths 1 372 |
|---|
using packages |
the following section describes how to use |
existing published packages. |
<topic_end> |
<topic_start> |
searching for packages |
packages are published to pub.dev. |
the flutter landing page on pub.dev displays |
top packages that are compatible with flutter |
(those that declare dependencies generally compatible with flutter), |
and supports searching among all published packages. |
the flutter favorites page on pub.dev lists |
the plugins and packages that have been identified as |
packages you should first consider using when writing |
your app. for more information on what it means to |
be a flutter favorite, see the |
flutter favorites program. |
you can also browse the packages on pub.dev by filtering |
on android, iOS, web, |
linux, windows, macOS, |
or any combination thereof. |
<topic_end> |
<topic_start> |
adding a package dependency to an app |
to add the package, css_colors, to an app: |
<topic_end> |
<topic_start> |
adding a package dependency to an app using flutter pub add |
to add the package, css_colors, to an app: |
<topic_end> |
<topic_start> |
removing a package dependency to an app using flutter pub remove |
to remove the package, css_colors, to an app: |
the installing tab, |
available on any package page on pub.dev, |
is a handy reference for these steps. |
for a complete example, |
see the css_colors example below. |
<topic_end> |
<topic_start> |
conflict resolution |
suppose you want to use some_package and |
another_package in an app, |
and both of these depend on url_launcher, |
but in different versions. |
that causes a potential conflict. |
the best way to avoid this is for package authors to use |
version ranges rather than specific versions when |
specifying dependencies. |
if some_package declares the dependencies above |
and another_package declares a compatible |
url_launcher dependency like '5.4.6' or |
^5.5.0, pub resolves the issue automatically. |
platform-specific dependencies on |
gradle modules and/or CocoaPods |
are solved in a similar way. |
even if some_package and another_package |
declare incompatible versions for url_launcher, |
they might actually use url_launcher in |
compatible ways. in this situation, |
the conflict can be resolved by adding |
a dependency override declaration to the app’s |
pubspec.yaml file, forcing the use of a particular version. |
for example, to force the use of url_launcher version 5.4.0, |
make the following changes to the app’s pubspec.yaml file: |
if the conflicting dependency is not itself a package, |
but an android-specific library like guava, |
the dependency override declaration must be added to |
gradle build logic instead. |
to force the use of guava version 28.0, make the following |
changes to the app’s android/build.gradle file: |
CocoaPods doesn’t currently offer dependency |
override functionality. |
<topic_end> |
<topic_start> |
developing new packages |
if no package exists for your specific use case, |
you can write a custom package. |
<topic_end> |
<topic_start> |
managing package dependencies and versions |
to minimize the risk of version collisions, |
specify a version range in the pubspec.yaml file. |
<topic_end> |
<topic_start> |
package versions |
all packages have a version number, specified in the |
package’s pubspec.yaml file. the current version of a package |
is displayed next to its name (for example, |
see the url_launcher package), as |
well as a list of all prior versions |
(see url_launcher versions). |
to ensure that the app doesn’t break when you update a package, |
specify a version range using one of the following formats. |
ranged constraints: specify a minimum and maximum version. |
ranged constraints using the caret syntax: |
specify the version that serves as the inclusive minimum version. |
this covers all versions from that version to the next major version. |
this syntax means the same as the one noted in the first bullet. |
to learn more, check out the package versioning guide. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.