How to import intl library in Flutter?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to import intl library in Flutter?



I am new in Flutter. When I import the library: import 'package:intl/intl.dart'; , it says that the target of URI doesn't exist:package:intl/intl.dart;
enter image description here


import 'package:intl/intl.dart';


the target of URI doesn't exist:package:intl/intl.dart;





Just to double check, you did import intl: ^0.15.7 into pubspec.yaml; triple check that it has four spaces in front of it (no more and no less); and you ran packages get? Also, put your focus on the tab for main.dart and hit the green arrow to run it. Sometimes you will then see a popup bar at the top of the screen that tells you pubspec.yaml has changed and you need to run it again from that link in order for it to take. (I've seen that in IntelliJ) Let us know if that doesn't help.
– scottstoll2017
Aug 6 at 10:54





It works now. Thanks! But it is still showing the red underlines. Is there a way to solve it ? @scottstoll2017
– TSR
Aug 6 at 11:01





If it's showing red lines under publspec.yaml in the project window but everything is working, that's a bug in the analysis. Ignore it but yes, they do know about it and are working on it. It's often there because, for some reason, pubspec.yaml says your assets directory doesn't exist even though you can access the assets without any problem.
– scottstoll2017
Aug 6 at 11:09





@scottstoll2017 No it is showing under main.dart (as shown in the picture in my question)
– TSR
Aug 6 at 11:10





Try stopping the app, going to the terminal and running "flutter clean" Also, there is a chance that you might have a second import that is trying to use a different class with the same name, but try the clean first.
– scottstoll2017
Aug 6 at 11:13




2 Answers
2



Just to double check, you did import intl: ^0.15.7 into pubspec.yaml; triple check that it has four spaces in front of it (no more and no less); and you ran packages get?



Also, put your focus on the tab for main.dart and hit the green arrow to run it. Sometimes you will then see a popup bar at the top of the screen that tells you pubspec.yaml has changed and you need to run it again from that link in order for it to take. (I've seen that in IntelliJ)



Also, if it's showing red lines under publspec.yaml in the project window but everything is working, that's a bug in the analysis. Ignore it but yes, they do know about it and are working on it. It's often there because, for some reason, pubspec.yaml says your assets directory doesn't exist even though you can access the assets without any problem.



When you import any package, example:


import 'package:intl/intl.dart';



You need to also add the package inside the pubspec.yaml file under the dependencies field example:


pubspec.yaml


dependencies


dependencies:
intl: ^0.15.7



Then from the terminal you can execute the following command:


flutter packages get



or



From Android Studio/IntelliJ:



Click Packages Get in the action ribbon at the top of pubspec.yaml


Packages Get


pubspec.yaml



more info here:



https://flutter.io/using-packages/






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered