This can't be done with the stable version of dart at the moment. @required
is just an annotation and not really a part of the language so the analyzer can't pick up on the problem you pose. However, with null-safety enabled in beta and higher channels, this is possible with the required
keyword.
You can try this by enabling null-safety and changing @required
to required
.
You could try this easily in dartpad
or
switch to a beta or higher channel and change your dart sdk version constraints to have a minimum of 2.12.0-0.
sdk: ">=2.12.0-0 <3.0.0"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…