Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do configuration flags in pubspec.yaml work?

I am learning Flutter and Dart. I noticed that thepubspec.yaml file seems to contain more than just dependency versions for third party libraries. For example.

# The following section is specific to Flutter.
flutter:
  uses-material-design: true

I understand that the Dart Pub Tool defines the format for the pubspec.yaml and it seems like frameworks like Flutter can enhance the pubspec.yaml with extra settings raising the following questions:

  • Is pubspec.yaml designed to be used to provide configuration flags or only dependencies?
  • Does the way flutter use pubspec.yaml idiomatic Dart or unique?
  • Is pubspec.yaml only parsed by the pub tool or is it parsed at runtime as a generic application config file?
  • Does Flutter implement it's own parser for pubspec.yaml and make settings like uses-material-design: true available at runtime?
like image 555
ams Avatar asked Apr 19 '19 22:04

ams


1 Answers

Is pubspec.yaml designed to be used to provide configuration flags or only dependencies?

Historically it also contained build settings in pure Dart projects. For example settings for compiling to JS, but that was moved out to build.yaml. See https://github.com/dart-lang/build/blob/master/build_config/README.md

Does the way flutter use pubspec.yaml idiomatic Dart or unique?

It's unique to Flutter.

Does Flutter implement it's own parser for pubspec.yaml and make settings like uses-material-design: true available at runtime?

yes.

These settings are build-time settings though, not runtime settings.


Actually I find it rather unfortunate that this file mixes up different purposes. In early Flutter days Flutter-specific settings were in a different file, but that also caused some difficulties (don't know details - only saw it mentioned in a GitHub discussion) so they merged it with pubspec.yaml.

like image 149
Günter Zöchbauer Avatar answered Sep 26 '22 03:09

Günter Zöchbauer