โ† Back to list

Dot Shorthands in Flutter & Dart ๐Ÿš€

Introduction ๐ŸŒ…

Aditya Mhatre in Stackademic ยท 2026-06-13 07:49 ยท 1 claps ยท 2.4 min read
#flutter #dart #enum #clean-code
Open on Medium โ†—
Wiki topics: ๐Ÿ“ฑ ยท Mobile Development

Dot Shorthands in Flutter & Dart ๐Ÿš€

Introduction ๐ŸŒ…

Dart has evolved significantly over the years, bringing many features that make code more expressive and concise. One such feature is Dot Shorthands.

Dot shorthands provide a cleaner way to access static members and enum values without repeatedly specifying the type name. This improves readability and reduces unnecessary verbosity in our code.

In this article, letโ€™s explore dot shorthands and understand how they can simplify our Flutter and Dart applications.

What are Dot Shorthands?

Dot shorthands allow us to omit the type name when the context already makes it obvious.

enum ThemeMode { light, dark }

// Previously, we had to write:
ThemeMode mode = ThemeMode.dark;

// With dot shorthands, we can write:
ThemeMode mode = .dark;

Here, Dart automatically infers that .dark belongs to ThemeMode.

Why do we need Dot Shorthands?

Before this feature, we often had to repeat the type name multiple times.

Consider the following example:

BorderRadius borderRadius = BorderRadius.circular(16);
ThemeMode mode = ThemeMode.dark;

Repeating the class or enum name can make the code verbose.

Dot shorthands reduce this repetition and make the code easier to read.

Using Dot Shorthands with Enums

Enums are one of the most common use cases.

enum UserRole { admin, user, guest }

// // Previously, we had to write:
UserRole role = UserRole.admin;
UserRole currentRole = UserRole.guest;

// With dot shorthands, we can write:
UserRole role = .admin;
UserRole currentRole = .guest;

Since the variable type is already known, Dart can infer the enum type automatically.

Using Dot Shorthands in Switch Statements

Suppose we have:

enum OrderStatus { pending, shipped, delivered }

Without dot shorthand:

switch (status) {
  case OrderStatus.pending:
    print('Pending');
  case OrderStatus.shipped:
    print('Shipped');
  case OrderStatus.delivered:
    print('Delivered');
}

With dot shorthand:

switch (status) {
  case .pending:
    print('Pending');
  case .shipped:
    print('Shipped');
  case .delivered:
    print('Delivered');
}

This makes switch statements cleaner and more readable.

Using Dot Shorthands with Static Members

// Without dot shorthand:
double size = double.parse('80');
Duration duration = Duration.zero;

// With dot shorthand:
double size = .parse('80');
Duration duration = .zero;

Dart infers that the value belongs to the expected type context.

Constructor Invocation with Dot Shorthands

// Without dot shorthand:
final DateTime now = DateTime.now();

// With dot shorthand:
final DateTime now = .now();

The type context tells Dart which constructor should be used.

Advantages of Dot Shorthands

Less Boilerplate

Removes repetitive type names from the code.

Improved Readability

The focus stays on the value rather than the type.

Cleaner Switch Statements

Pattern matching and switch expressions become more concise.

Better Developer Experience

Writing less code makes development faster and reduces clutter.

Things to Keep in Mind

Dot shorthands work only when Dart can infer the type from the surrounding context.

For example:

// Works perfectly
ThemeMode mode = .dark;

// Will produce an error because
// Dart cannot determine which type .dark belongs to
var mode = .dark; โŒ

Conclusion ๐ŸŒ‡

Dot shorthands are a small but powerful addition to Dart. They help eliminate unnecessary repetition and make code cleaner and easier to read.

Whether youโ€™re working with enums, static members, constructor tear-offs, or pattern matching, dot shorthands can make your Flutter and Dart code more expressive and maintainable.

As Dart continues to evolve, features like these contribute to a more pleasant and productive developer experience. ๐Ÿš€

[embed]Building Robust Data Sources in Clean Architecture for Flutter Introduction ๐ŸŒ…blog.stackademic.com

[embed]Use Cases in Clean Architecture for Flutter: Bridge the Gap Introduction ๐ŸŒ…blog.stackademic.com

Thanks for reading. If you found this article to be helpful please share it with your friends.


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
434963e234e4
slug
dot-shorthands-in-flutter-dart-434963e234e4
url
https://medium.com/@adityagmhatre/dot-shorthands-in-flutter-dart-434963e234e4
canonical_url
https://medium.com/@adityagmhatre/dot-shorthands-in-flutter-dart-434963e234e4
author_url
https://medium.com/@adityagmhatre
status
ok
fetched_at
2026-06-16 19:09:56