Dart 2.3 for, if and spread support warning messag

2020-08-09 04:44发布

问题:

I am getting the warning message 'The for, if and spread elements were not supported until version 2.2.2, but this code is required to be able to run on earlier versions' but the code

Column(   crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              if (document['propertyid'] == '1') Text('jjj'),
              GestureDetector(
                onTap: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) =>
                              PropertyDetails(document['propertyid'])));
                },
                child: Text(document['propertyname'],
                    style: TextStyle(
                        color: Colors.blue,
                        fontStyle: FontStyle.italic,
                        fontWeight: FontWeight
                            .w500) //Theme.of(context).textTheme.title,
                    ),
              ),
            ],
  ),

works as expected. The minSDKVersion etc is 28. Why does it think I want to be able to run this code on any earlier version? What do I need to change to a later version?

回答1:

In pubspec.yaml you can update your environment sdk to get rid of those warnings:

environment:
  sdk: ">=2.3.0 <3.0.0"


回答2:

Press option + return on the warning and select Update the SDK constraints



回答3:

Changing the SDK to ">=2.3.0 <3.0.0"resulted in another issue.

However ">=2.2.2 <3.0.0" works like a charm!



标签: dart flutter