Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

flutter dependencies - Dart 2.10 and `required` keyword

I'm new to both Dart and Flutter so please bear with me if this is off the mark. But I've exhausted my Googlefu and haven't been able to find an answer.

Context

I'm running Dart 2.10.4 and Flutter 1.22.5. At this point I'm just cloning a bunch of example apps from Github and running them locally by

  • Running flutter pub get
  • Then hitting Run in Android Studio

I am familiar with package management from other languages and have read the docs about potential differences with Dart, in particular

pub get uses the versions of dependencies locked in it (pubspec.lock) if possible

"if possible" tells me the pubspec.lock file is not always respected. The behavior I'm familiar with is for an error to be raised "if not possible".

I should mention that none of the repos I've cloned is very new. They all have over a year's history but have all had recent updates.

What happened

In all of the projects, doing a flutter pub get alters pubspec.lock. The changes are all upgrading the dependencies to a nullsafety version. For example boolean_selector went from 1.0.5 to 2.1.0-nullsafety.1. This confused the hell out of me at first. Digging into the pubspec.yaml files of the affected packages revealed that the SDK constraint is indeed satisfiable by my Dart version, e.g. boolean_selector. These version changes broke all of the codebases because of the required keyword.

Question 1

As I understand it, part of the Null-Safety changes is that the @required annotation becomes required. It's also my understanding that these changes don't land until Dart 2.12. So what's happening here? Why do packages release nullsafety versions for Dart 2.10?

Question 2

The pubspec.lock file is satisfiable by my current Dart version. To use the boolean_selector example again. The repo in question locks it to 1.0.5 which has an SDK constraint of sdk: '>=2.0.0 <3.0.0'. I'm running Dart 2.10. Everything should be fine. Why does pub get forcefully upgrade it to the latest compatible version?

Question 3

I thought ok maybe required is an experimental feature we can turn on for Dart 2.10. I read about NNBD and dart migrate and have tried it. It doesn't seem to do anything about required and would always error out. I read about dependency_overrides to use a newer version of analyzer. I'd get the same errors. I'm clearly missing something. If Dart 2.10 is compatible with required (as opposed to @required), how do I make it so?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...