The orignal pubspec.yaml files works fine when generated through "flutter create {project_name}" but suppose I want to try to add a dependency such as fluttertoast it gives error message
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0 1
environment:
sdk: '>=2.18.0-170.0.dev <3.0.0'
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
fluttertoast: ^8.0.9
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
This gives the error:
Error on line 10, column 5 of pubspec.yaml: A version constraint must be a string.
╷
10 │ ┌ sdk: flutter
11 │ │
12 │ │ cupertino_icons: ^1.0.2
13 │ │ fluttertoast: ^8.0.9
14 │ │
15 │ │ dev_dependencies:
16 │ │ flutter_test:
17 │ │ sdk: flutter
18 │ │ flutter_lints: ^2.0.0
19 │ │ flutter:
20 │ │
21 │ └ uses-material-design: true
╵
Running "flutter pub get" in textfield...
pub get failed (65; ╵)
And know even if I delete the fluttertoast dependency
It still results in the error
Error on line 10, column 5 of pubspec.yaml: A version constraint must be a string.
╷
10 │ ┌ sdk: flutter
11 │ │
12 │ │ cupertino_icons: ^1.0.2
13 │ │ # fluttertoast: ^8.0.9
14 │ │
15 │ │ dev_dependencies:
16 │ │ flutter_test:
17 │ │ sdk: flutter
18 │ │ flutter_lints: ^2.0.0
19 │ │ flutter:
20 │ │
21 │ └ uses-material-design: true
╵
Running "flutter pub get" in textfield...
pub get failed (65; ╵)
flutter --version output -->
Flutter 3.1.0-0.0.pre.1112 • channel master • https://github.com/flutter/flutter.git
Framework • revision 8294d9e91e (24 hours ago) • 2022-06-05 13:38:04 -0400
Engine • revision 9e4f372577
Tools • Dart 2.18.0 (build 2.18.0-170.0.dev) • DevTools 2.14.0
CodePudding user response:
Yaml is indent sensitive. Easiest way to add a package is to run `flutter pub add fluttertoast' in terminal. To fix the error that you are facing make the indentation of flutter toast same as flutter in pubspec.yaml
dependencies:
flutter:
sdk: flutter
cupertino_icons: any
flutter toast : ^8.0.9
CodePudding user response:
I think you just missed dependencies:
before sdk:
.
Set it like this:
environment:
sdk: '>=2.15.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.4
Refer this example for more details about it.