Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to import the intl package for dart

Tags:

flutter

dart

Hi I am trying to use the intl package in my flutter project. The packages get command runs successfully but when I import the package it shows error.

My pubspec.yaml file

For the import in the my dart file I am using the following import

import 'package:intl/intl.dart';

I have also upgraded flutter from the terminal using the flutter upgrade command.

like image 963
nick.tdr Avatar asked May 18 '18 17:05

nick.tdr


4 Answers

Here are some steps that I offten see as problems with dependencies in flutter.

  1. The thing with pubspec.yaml is that you have to save it CRTL/CMD + S before pub get will work. Running pub get from IDE doesn't save the file automatically.

  2. Try running flutter clean and then run flutter pub get. Sometimes when you remove dependencies like plugins, .build folder doesnt get cleaned up properly so you have to do it manually.

  3. You can try to repair pub cache by running flutter pub cache repair

  4. Sometimes just restarting your IDE might solve the problem as well.

like image 122
Tree Avatar answered Sep 16 '22 13:09

Tree


After the project cleaning you could have some error like this:

intl_browser.dart:13:8: Error: Not found: 'dart:html'

You can clean your cache, make all you want to refresh your flutter project:

- flutter clean 
- rm -rf pubspec.lock .packages .flutter-plugins 
- flutter pub pub cache repair
- flutter packages get 

But you can't solve until you comment this line on your code :

findSystemLocale()

This line is in conflict with dart:html as you can see here below according with the current intl source:

library intl_browser;

import "dart:async";
import "dart:html";
import "intl.dart";

// TODO(alanknight): The need to do this by forcing the user to specially
// import a particular library is a horrible hack, only done because there
// seems to be no graceful way to do this at all. Either mirror access on
// dart2js or the ability to do spawnUri in the browser would be promising
// as ways to get rid of this requirement.
/// Find the system locale, accessed as window.navigator.language, and
/// set it as the default for internationalization operations in the
/// [Intl.systemLocale] variable.
Future<String> findSystemLocale() {
  Intl.systemLocale = Intl.canonicalizedLocale(window.navigator.language);
  return new Future.value(Intl.systemLocale);
}
like image 33
Alessandro Ornano Avatar answered Sep 17 '22 13:09

Alessandro Ornano


It needs to reload the flowing package using CTRL+S might not work sometimes. Need to restart IDE after saving pubspec.yaml file.

like image 36
Ramu Ramasani Avatar answered Sep 18 '22 13:09

Ramu Ramasani


Faced the same issue, if you are importing

import "package:intl/intl_browser.dart";

then you will get that error, it seems like the dart SDK bundled with flutter does not have the required dependencies.

So use only

import 'package:intl/intl.dart';

and it should work just fine.

like image 42
Ketan Ramteke Avatar answered Sep 19 '22 13:09

Ketan Ramteke