Assorted Dart code snippets


Dart Code Snippets

Dart, the language behind Flutter, is a useful and powerful language. Here are some snippets I find useful from time to time.

Simple 'Hello, World!' style code to test your environment

Simple and easy to copy and paste to just do a quick environment check.

                void main() {
                    print('Hello, Dart!');

Obtaining the current date and testing if it is the same day as a given date

Figures out whether a particular set of times are on the same day.

                void main() {
                    var now =;
                    var sameDay = now.subtract(Duration(hours: 1));
                    print("The times are the same day: ${isSameDay(now, sameDay)}");
                isSameDay(DateTime d1, DateTime d2) {
                    return ( == && d1.month == d2.month && d1.year == d2.year);

Return to the blog index