I start to use intl package in my dart project. After start to use this package i use this code:
DateTime now = new DateTime.now();
var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String nowFormatted = formatter.format(now);
And it works correctly. After i use intl i obtain this message in log:
Uncaught LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).
I cannot understand why i should pass locale in this code snippet
I've the same issue to the current Intl
version so I've solved with
these imports:
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
and the code:
initializeDateFormatting();
DateTime now = DateTime.now();
var dateString = DateFormat('dd-MM-yyyy').format(now);
final String configFileName = 'lastConfig.$dateString.json';
Verify your imports:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
Set initializeDateFormatting according to your language, example:
initializeDateFormatting('pt_BR', null);
If you encounter this problem, write initializeDateFormatting('az');
top of "Material App". I searched for 1 hour and nobody wrote it clearly.
it is really solved.
I have solved this use in this way:
DateTime now = new DateTime.now();
var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", 'en');
String nowFormatted = formatter.format(now);
But I have to make this to my dart file used to configure itnl support:
library translation_helper;
import 'dart:async';
import 'package:intl/date_symbol_data_local.dart';
import '../../resources/messages_all.dart';
void setupLanguage(){
//var germanDatesFuture = initializeDateFormatting('de_DE', null);
var enDatesFuture = initializeDateFormatting('en', null);
var germanMessagesFuture = initializeMessages('de');
var englishMessagesFuture = initializeMessages('en');
var italianMessagesFuture = initializeMessages('it');
var polishMessagesFuture = initializeMessages('pl');
Future
.wait([
enDatesFuture,
germanMessagesFuture,
englishMessagesFuture,
italianMessagesFuture,
polishMessagesFuture
]);
}
Before I was missing:
var enDatesFuture = initializeDateFormatting('en', null);
For more info I use:
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