본문 바로가기
Flutter

[Flutter / Error] Locale data has not been initialized, call initializeDateFormatting(<locale>).

by hymndaniel 2022. 12. 15.
  • In your pubspec.yaml, add this dependencie package: intl:
  • In your highest StatefulWidget (in your dart file), add these imports:
    import 'package:intl/intl.dart';
    import 'package:intl/date_symbol_data_local.dart';
  • In its State, override initState add :
      @override
      void initState() {
        super.initState();
        initializeDateFormatting(); //very important
      }
  • And the code:
     DateTime now = new DateTime.now();
     var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
     String nowFormatted = formatter.format(now);

 

Reference

https://stackoverflow.com/questions/36174033/intl-package-and-date-formatting-strange-behaviour

 

intl package and date formatting strange behaviour

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'");

stackoverflow.com

 

 

728x90