Monday, 27 April 2015

Dart POW - ( Package Of The Week) #5 : timeago

Sorry for the lack of posts - April has been busy! A combination of holidays, work deadlines and writing a book has made blogging impossible. The good news is that it is a Dart book - more details as I can share them!

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

timeago is a Dart library for creating fuzzy timestamps, such as "15 minutes ago". Great for human friendly labeling of dynamic interfaces.

import 'package:timeago/timeago.dart';

main() async {
    TimeAgo time = new TimeAgo();
    int current = new DateTime.now().millisecondsSinceEpoch;
    
    print(time.timeAgo(current - (15 * 60 * 1000))); // 15 minutes ago
    
    //change locale
    await time.changeLocale("es");
    
    print(time.timeAgo(current - (15 * 60 * 1000))); // hace 15 minutos
}

Try out the live demo here.

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)

Friday, 3 April 2015

Dart POW - (Package Of The Week) #4 dart-reddit

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

reddit is a library for Dart that allows read-only API access to the popular link sharing site Reddit.

The following example fetches the latest links from the Dart sub-reddit.

import "package:reddit/reddit.dart";
import "package:http/http.dart";
import 'dart:convert';

main() {
  
  Reddit reddit = new Reddit(new Client());

  reddit.sub("dartlang").top("month").listen((result) {

    Map data = JSON.decode(result.toString());
    List Titles = data["data"]["children"];
    Titles.forEach((headline) => print(headline["data"]["title"]));

  });
}


Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)