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.
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.
Here are some steps that I offten see as problems with dependencies in flutter.
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.
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.
You can try to repair pub cache by running flutter pub cache repair
Sometimes just restarting your IDE might solve the problem as well.
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);
}
It needs to reload the flowing package using CTRL+S might not work sometimes. Need to restart IDE after saving pubspec.yaml
file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With