Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting error: Undefined class 'required'. when trying to use required keyword

I am getting error: Undefined class 'required'. when trying to use required keyword.

Here is the code sample:

class Field {
  final int id;
  final String name;
  final bool userEditable;
  final String title;
  Field({
    required this.id,
    this.name,
    this.userEditable,
    this.title,
  });
}

enter image description here

I am already using flutter's @required keyword but I trying to switch to dart's new required keyword.

Here is pubspec.yaml's enviroment sdk line:

environment:
  sdk: ">=2.7.0 <3.0.0"

Here is output of flutter --version:

Flutter 2.0.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c5a4b4029c (2 weeks ago) • 2021-03-04 09:47:48 -0800
Engine • revision 40441def69
Tools • Dart 2.12.0
like image 728
ARK4579 Avatar asked Mar 20 '21 03:03

ARK4579


Video Answer


1 Answers

Update your minimum sdk constraint to 2.12.0.

environment:
  sdk: ">=2.12.0 <3.0.0"
like image 158
Christopher Moore Avatar answered Nov 13 '22 12:11

Christopher Moore