Francesco
Francesco

Reputation: 103

flutter intl 0.17.0-nullsafety.2 package initializeDateFormatting

i need some help because im going crazy. I just want to format date to my locale (should be it-IT).

In flutter app i putted in pubspec.yaml the intl package with the new nullsafety feature:

  flutter:
    sdk: flutter
  intl: ^0.17.0-nullsafety.2 

looking into the documentation it says:

<< Note that before doing any DateTime formatting for a particular locale, you must load the appropriate data by calling: >>

import 'package:intl/date_symbol_data_local.dart';
...
initializeDateFormatting('de_DE', null).then(formatDates); 

(https://pub.dev/packages/intl/versions/0.17.0-nullsafety.2)

so, just to try, i did:

initializeDateFormatting('it-IT', null).then((value) => {print('intl ok')});

but the dart nullsafety doesnt want a null parameter, and it says "The argument type 'Null' can't be assigned to the parameter type 'String'."

Any suggestion?

Upvotes: 3

Views: 1747

Answers (3)

Aditya Agarwal
Aditya Agarwal

Reputation: 21

I was facing the same issue.

Changed import statement to

import 'package:intl/date_symbol_data_local.dart';

from

import 'package:intl/date_symbol_data_file.dart';

Also dependency I am using is intl: ^0.18.1

Upvotes: 2

Usama Ishfaq
Usama Ishfaq

Reputation: 111

I also encountered the similar issue where initializeDateFormatting(localeName, null) was imported from 'package:intl/date_symbol_data_file.dart' and it requires filePath in arguments or if you import it from 'package:intl/date_symbol_data_http_request.dart' you have to pass url in second argument that is required.

Intl package has initializeDateFormatting() declared in different three files if you only want to pass locale you should consider it importing from date_symbol_data_local.dart

import 'package:intl/date_symbol_data_local.dart'

final String localeName = Intl.canonicalizedLocale('en_US');

try {
  await initializeDateFormatting(localeName, null);
} catch (error, stackTrace) {
  
}

Upvotes: 0

Thread: flutter intl 0.17.0 package initializeDateFormatting.

Same problem here, did you solve the issue? I tried upgrading intl to ^0.18.0, but in my pubspec.yaml I am using

  flutter_localizations: # Add this line
    sdk: flutter

so, my project is coupled with intl 0.17.0. I realize this when I tried the [flutter pub get] command and got this message:

Running "flutter pub get" in expenses...                        
**Because expenses depends on flutter_localizations from sdk which depends on intl 0.17.0, intl 0.17.0 is required.**
So, because expenses depends on intl ^0.18.0, version solving failed.
pub get failed (1; So, because expenses depends on intl ^0.18.0, version solving failed.)

I also made a lab with only dart and not flutter, and intl works as expected: https://gist.github.com/ejyanezp/994c49f15bb2ce3fd4c3d84ed37ca198

So is a compatibility issue between flutter_localizations and intl.

Conclusion: i will go for a workaround and wait the final solution from the authors of both libraries.

Upvotes: 0

Related Questions