Saltar al contenido
Skillpedia
Programación general48 mil · #5890

dart

Qué hace

Esta guía te enseña a escribir código en Dart de forma más eficiente y clara. Muestra ejemplos de cómo evitar errores comunes y usar buenas prácticas para que tu código sea más fácil de leer y de mantener.

Cuándo usarla

  • ✓Cuando estás aprendiendo a programar en Dart.
  • ✓Cuando revisas código escrito por otras personas.
  • ✓Cuando quieres mejorar la calidad de tu propio código.

Link de la skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/dart/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/dart/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo puedo escribir código Dart más seguro para manejar valores que podrían ser null?”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La guía compara las 'formas incorrectas' y las 'formas correctas' de escribir código en Dart. Usa ejemplos de código para mostrar cómo aprovechar las funciones del lenguaje y simplificar tareas habituales.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

Dart: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for dart.

Table of Contents

  1. Null Safety
  2. Collections & Iteration
  3. Classes & Records
  4. Async/Await & Streams
  5. Error Handling
  6. Flutter-Specific Patterns
  7. Anti-patterns specific to Dart

1. Null Safety {#nulls}

// ❌ Manual null check
String display;
if (user.name != null) {
  display = user.name!;
} else {
  display = 'Unknown';
}

// ✅
final display = user.name ?? 'Unknown';
// ❌ Nested null checks
if (user != null && user.address != null && user.address!.city != null) {
  print(user.address!.city!);
}

// ✅
final city = user?.address?.city;
if (city != null) print(city);
// ❌ Late field when nullable is correct
late String name; // crashes if accessed before assignment

// ✅ — use late only when you guarantee initialization before access
String? name; // honestly nullable
// late is fine for: late final _controller = TextEditingController();
// ❌ Bang operator (!) everywhere
final name = user.name!;
final city = user.address!.city!;

// ✅ — promote through null checks
final name = user.name;
if (name == null) return;
// name is now non-null (promoted)

2. Collections & Iteration {#collections}

// ❌ Imperative accumulation
final result = <String>[];
for (final item in items) {
  if (item.isActive) result.add(item.name.toUpperCase());
}

// ✅
final result = items
    .where((i) => i.isActive)
    .map((i) => i.name.toUpperCase())
    .toList();
// ❌ Manual map construction
final map = <String, List<Item>>{};
for (final item in items) {
  map.putIfAbsent(item.category, () => []).add(item);
}

// ✅ (using collection-if/for in a different way — but groupBy isn't built-in)
// The loop above is actually idiomatic Dart. Use package:collection for groupBy:
import 'package:collection/collection.dart';
final map = groupBy(items, (Item i) => i.category);
// ❌ Building list with add() calls
final widgets = <Widget>[];
widgets.add(Header());
if (showSubtitle) widgets.add(Subtitle());
widgets.add(Body());

// ✅ — collection-if
final widgets = [
  Header(),
  if (showSubtitle) Subtitle(),
  Body(),
];
// ❌ Spreading manually
final all = <int>[];
all.addAll(listA);
all.addAll(listB);

// ✅
final all = [...listA, ...listB];

3. Classes & Records {#classes}

// ❌ Manual data class boilerplate
class Point {
  final int x, y;
  const Point(this.x, this.y);
  @override bool operator ==(Object other) => ...
  @override int get hashCode => ...
  @override String toString() => 'Point($x, $y)';
}

// ✅ (Dart 3.0+)
typedef Point = ({int x, int y});
// or for named class semantics:
class Point {
  final int x, y;
  const Point(this.x, this.y);
}
// Use package:equatable or Dart records for equality
// ❌ Verbose constructor
class User {
  final String name;
  final int age;
  User(String name, int age) : name = name, age = age;
}

// ✅ — initializing formals
class User {
  final String name;
  final int age;
  const User(this.name, this.age);
}
// ❌ Mutable fields on an immutable object
class Config {
  String host;
  int port;
  Config(this.host, this.port);
}

// ✅
class Config {
  final String host;
  final int port;
  const Config(this.host, this.port);
}
// ❌ Switch on type with if-else chain
if (shape is Circle) {
  return (shape as Circle).radius * pi;
} else if (shape is Rectangle) { ... }

// ✅ (Dart 3.0+)
return switch (shape) {
  Circle(:final radius) => radius * radius * pi,
  Rectangle(:final width, :final height) => width * height,
};

4. Async/Await & Streams {#async}

// ❌ .then() chains
fetchUser()
    .then((user) => fetchPosts(user))
    .then((posts) => display(posts))
    .catchError((e) => log(e));

// ✅
try {
  final user = await fetchUser();
  final posts = await fetchPosts(user);
  display(posts);
} catch (e) {
  log(e);
}
// ❌ Sequential await for independent work
final a = await fetchA();
final b = await fetchB();

// ✅
final results = await Future.wait([fetchA(), fetchB()]);
// or with typed destructuring:
final (a, b) = await (fetchA(), fetchB()).wait; // Dart 3.0+ record
// ❌ StreamBuilder doing too much in build
StreamBuilder(
  stream: stream,

…
Preguntas frecuentes

¿Qué es 'Null Safety'?

Es una función de Dart que ayuda a prevenir errores comunes causados por variables que deberían tener un valor pero acaban siendo null (vacías). La guía explica cómo usarla correctamente.

¿Qué son las 'Colecciones e iteración'?

Se refiere a cómo organizar y recorrer listas y otros conjuntos de datos. La guía muestra formas más eficientes de hacerlo en Dart.

¿Qué son los 'antipatrones'?

Son prácticas de programación que parecen funcionar, pero que suelen dar problemas más adelante, haciendo el código más difícil de entender o más propenso a errores. La guía te ayuda a identificarlos y evitarlos.

Detalles

Descripción original del autor

Language-specific super-code guidelines for dart.

repo: sickn33/agentic-awesome-skills

Popularidad

Estrellas en GitHub
48 mil
Posición en el ranking
#5890
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas