Pubspec.yaml what this file does in Flutter - flutter

version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
sqflite: any
path_provider: any
intl: ^0.15.7
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
What things are written in it?

version: 1.0.0+1
The version of your application or package.
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Your application or package claims to support Dart SDK within this version range
dependencies:
flutter:
sdk: flutter
Your application or package depends on the flutter package which can be found in the SDK
sqflite: any
Your application or package depends on the package sqflite from https://pub.dartlang.org with no specific version constraint.
path_provider: any
intl: ^0.15.7
Your application or package depends on the package intl from https://pub.dartlang.org on any version 0.15.7 or later but before 0.16.0.
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
The ^ changes the meaning for versions 1.0.0 and later.
^0.15.7 means >=0.15.7 <0.16.0
^1.15.7 means >=1.15.7 <2.0.0
because for versions < 1.0.0 breaking changes are indicated by incrementing the middle number, while for >= 1.0.0 breaking changes are indicated by incrementing the first part of the version.

It is responsible for handling of importing images/fonts/third party packages which you want to include in your project.

As explained here on the Flutter site:
The pubspec file manages the assets and dependencies for a Flutter app.
More info can be found here.

To briefly explain, this file written in the YAML language, allows you to manage the pub packages you want to use in your flutter app.

From the dart page :
Every pub package needs some metadata so it can specify its dependencies. Pub packages that are shared with others also need to provide some other information so users can discover them. All of this metadata goes in the package’s pubspec: a file named pubspec.yaml that’s written in the YAML language.
So you will find all the required dependencies / fonts and images sources /sdk version in the pubspec.yaml

Related

Getting error in flutter compilation like : carousel_slider-4.2.0/lib/carousel_slider.dart:311:29: Error: Member not found: 'trackpad'

I am getting error while compiling flutter app
Anyone can help?
Here is full error :
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/carousel_slider-4.2.0/lib/carousel_slider.dart:311:29: Error: Member not found: 'trackpad'.
PointerDeviceKind.trackpad
Here are dependencies from yaml file
`
version: 1.0.0+1
environment:
sdk: ">=2.16.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
carousel_slider: ^4.2.0
video_player:
`
Welcome Rohan!
This issue is because of the introduction of the new trackpad gestures in version 3.3.0-0.0.pre of flutter as documented here: https://docs.flutter.dev/release/breaking-changes/trackpad-gestures looks like carousel_slider has been update to use it.
You have two options:
Upgrade your flutter SDK to 3.3.0-0.0.pre or greater
Or downgrade carousel_slider: 4.1.0
Clean pub cache folder by command bellow
flutter pub cache repair
And download all dependencies by following command in your project directory
flutter pub cache repair
IMPORTANT
All libraries will be downloaded from the internet from the scratch and this will take some time depends how many libraries are you using
you should declare carousel_slider: 4.1.1 in pubspec.yaml
instead of carousel_slider: ^4.1.1 because with ^ sign flutter will try to use latest version in pub.dev

Can we stop Flutter plugin loading if not use in final build

Seems if a plugin package is included in pubspec.yaml, it will be included in build even not use.
Take my sample project https://github.com/J-Siu/flutter_scroll as example, pubspec.yaml
name: flutter_scroll
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.17.6 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
google_sign_in: ^5.4.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
google_sign_in is a plugin but not imported in any of the source code and there is no dependency using it.
However if you go to the demo page: https://j-siu.github.io/app/flutter_scroll/#/ , open browser inspector -> network, reload the page, you will see https://apis.google.com/js/platform.js is loaded. That is done by google_sign_in initialization.
Question: Other than removing it from pubspec.yaml, is there a way to exclude plugin from final build if it is not imported in source and other dependency?
PS: You can experiment with a plain starting project:
flutter create --platforms web my_testing
cd my_testing
flutter pub add google_sign_in
flutter run (should open chrome)
check inspector -> network with reload
No, i dont think its possible to not use a package thats defined in pubspec during build. You could take a look at packages like
Dependency validator
Where you get to know which packages arent used at all and remove them easily.

How to add a custom library in project Flutter?

I want to create a custom library and use it in Flutter project.
I created a custom library in project:
But I can't get pub it. (Error)
Because write_library_external depends on lib_math from path which doesn't exist (could not find package lib_math at "..\lib_math"), version solving failed.
pub get failed (66; Because write_library_external depends on lib_math from path which doesn't exist (could not find package lib_math at "..\lib_math"), version solving failed.)
This is my pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
lib_math:
path: /lib_math
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
Please help me! Thanks!
It looks like you added the wrong library path.
With your project, you should try changing the file at pubspec.yaml:
dependencies:
lib_math:
path: ../write_library_external/library/lib_math

Unable to install new packages with pub command

The following is the excerpt from my pubspec.yaml file. I have added new dependency for shared preferences. when i do command pub get i get the error
Package secondapp requires SDK version >=2.7.0 <3.0.0 but the current SDK is 1.10.1.
I am able to resolve this by adding proper path to my dart installation. But after doing this, the flutter version error is coming.
My yaml file :
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter,
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
shared_preferences: ^0.5.6+3
dev_dependencies:
flutter_test:
I am unable to add the dependency. What settings am i missing?

Getting gradle errors in a Flutter application after importing packages

I'm building a Flutter app, and just added the mime and http_parser packages. After that I got the following error when building:
<appname>\build\app\intermediates\merged_manifests\debug\AndroidManifest.xml:35: AAPT: error: resource integer/google_play_services_version (aka com.att.fluttercount:integer/google_play_services_version) not found.
Up until now, the app had built just fine. I backed out my changes, including removing the packages from pubspec.yaml, but the error won't go away.
Here's the relevant part of my pubspec.yaml:
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
flutter_map: ^0.5.0+1
scoped_model: ^1.0.1
rxdart: ^0.21.0
flutter_masked_text: ^0.8.0
image_picker: ^0.5.0+9
webview_flutter: ^0.3.6
sqflite: ^1.1.5
http: ^0.12.0+2
#mime: ^0.9.6+2
#http_parser: ^3.1.3
# Must use 'any' as the version of path_provider, because other packages depend on
# earlier versions of path_provider.
path_provider: any
# Note: Must use 'any' as the version of uuid, because some dependencies of flutter_map
# depend on earlier versions of uuid.
uuid: any
dev_dependencies:
flutter_test:
sdk: flutter
Does anyone have any suggestions on how to fix this errror?
I had neglected to mention that I had also removed a dependency on google_maps_flutter, which I was no longer using. I added this dependency back in, and the error went away.