Book Image

Dart By Example

By : David Mitchell
Book Image

Dart By Example

By: David Mitchell

Overview of this book

Table of Contents (17 chapters)
Dart By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with dates


The ISO 8601 standard for dates is 'Year Month Day', and naturally, no country in the world uses this standard day to day! A typical variation is to have the month or day first, and then the separator character is used between digits in shorthand.

The intl package can help provide the appropriate format and translations for each language. Translation strings are required too as the name of the day or month may be required.

Date handling is implemented in the SlideShowApp class:

 import 'package:intl/date_symbol_data_local.dart';

A field is used to keep a reference to the active DateFormat object:

DateFormat slideDateFormatter;

We will consider how this formatter is initialized and kept up to date with the changes made to the users language.

Formatting for the locale

The locale for the date formatter will need to be updated whenever the interface language is changed:

    qs("#interfaceLang").onChange.listen((e){
      var lang = qs("#interfaceLang").value;
      setInterfaceLang...