AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Dart Modern Syntax

skill-dhruvanbhalara-skills-dart-modern-syntax · by dhruvanbhalara

Guide for utilizing Dart 3.0+ up to 3.12 syntax updates (private named parameters, extension types, records, pattern matching, wildcard variables, and primary constructors).

No reviews yet
0 installs
34 views
0.0% view→install

Install

$ agentstack add skill-dhruvanbhalara-skills-dart-modern-syntax

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-dhruvanbhalara-skills-dart-modern-syntax)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
3mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Dart Modern Syntax? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Modern Dart Syntax (Dart 3.0 - 3.12+)

Leverage the latest syntax features introduced in Dart 3.x to write clean, concise, type-safe, and highly optimized code.

Contents

  • [Private Named Parameters](#private-named-parameters)
  • [Extension Types](#extension-types)
  • [Wildcards for Unused Elements](#wildcards-for-unused-elements)
  • [Records and Pattern Matching](#records-and-pattern-matching)
  • [Primary Constructors](#primary-constructors)

Private Named Parameters

Introduced in Dart 3.12

Dart now supports initializing private fields directly using named parameters in constructors. This removes the need for manual assignments in the initializer list.

Usage

  • When declaring a named constructor parameter, prefix the private field name with this.:
  • The compiler automatically strips the leading underscore (_) at the call site.
class User {
  final String _name;
  final int _age;

  // Initializing private fields directly
  User({
    required String this._name,
    required int this._age,
  });

  String get name => _name;
  int get age => _age;
}

void main() {
  // Call site does NOT include the underscore
  final user = User(name: 'Alice', age: 30);
  print(user.name); // Alice
}

Extension Types

Introduced in Dart 3.3

Extension types are compile-time-only wrapper classes around an underlying representation type. They provide a zero-cost abstraction, meaning they do not allocate wrapper objects in memory at runtime, unlike standard classes.

Rules & Patterns

  • Expose a new interface for an existing type without runtime allocation overhead.
  • Declare using extension type Name(RepresentationType value).
  • Use when designing performance-sensitive APIs, domain-specific ID wrappers, or when wrapping JS interop objects.
// Exposes a zero-cost wrapper around an integer
extension type Id(int value) {
  // Add custom helper methods
  bool get isValid => value > 0;
}

// Wrapping a list to restrict available methods
extension type IntList(List list) {
  int get head => list.first;
  
  void printSummary() {
    print('Length: ${list.length}, Head: $head');
  }
}

void main() {
  final myId = Id(42); // Zero overhead, compiled directly to 42
  print(myId.isValid); // true
}

Wildcards for Unused Elements

Introduced in Dart 3.7

You can use the wildcard _ to denote unused elements. This prevents linter warnings and clearly signals to other developers (and AI agents) that a variable or import is intentionally ignored.

Wildcard Scopes

  • Unused Parameters: Use _ (and __, ___ if nesting) in callbacks.
  • Unused Local Variables: Declare variables as _ if they are only needed to trigger side effects.
  • Unused Imports: Import a package as _ to run its initialization logic without binding names.
import 'package:init_library/init.dart' as _;

void processItems() {
  final items = ['apple', 'banana', 'orange'];
  
  // Wildcards in list mapping
  final indexed = items.mapIndexed((index, _) => 'Item $index');
  
  // Wildcard for unused exception variable
  try {
    performDangerousTask();
  } catch (_) {
    print('Failed to perform task.');
  }
}

Records and Pattern Matching

Introduced in Dart 3.0

Records allow returning multiple values from a function without the boilerplate of a custom class. Pattern matching extracts those values or destructures objects cleanly.

Syntactic Best Practices

  • Positional Records: (double, double) getCoordinates() => (37.77, -122.41);
  • Named Records: ({String name, int age}) getDetails() => (name: 'Bob', age: 25);
  • Destructuring: Assign directly to matching structures:
// 1. Positional Record Destructuring
final (lat, lng) = getCoordinates();

// 2. Named Record Destructuring
final (name: userName, age: userAge) = getDetails();

// 3. Object Destructuring with Patterns
if (user case User(name: final name, age: > 18)) {
  print('$name is an adult');
}

Primary Constructors

Introduced in Dart 3.12 (Experimental)

Primary constructors provide a concise syntax for defining classes with automatic field declarations and assignments, similar to other modern languages.

// Shorthand for immutable data structures
class Point(int x, int y);

// Equivalent to:
// class Point {
//   final int x;
//   final int y;
//   Point(this.x, this.y);
// }

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.