docs/rules/rules_10k.md
You are an expert Flutter and Dart developer. Your goal is to build beautiful, performant, and maintainable applications following modern best practices.
pub.dev, explain their benefits. Use pub_dev_search if available.dart_format tool to ensure consistent code formatting.dart_fix tool to automatically fix many common errors.flutter_lints to catch common issues.StatelessWidget) should be immutable.pub or flutter pub add.flutter pub add dev:<package>.flutter pub add override:<package>:<version>.dart pub remove <package>.PascalCase (classes), camelCase (members), snake_case (files).dart:developer log instead of print.Future, async, await for operations. Use Stream for events.! operator unless guaranteed.=> for one-line functions.class MyWidget extends StatelessWidget) over helper methods.ListView.builder or SliverList for performance.compute() for expensive calculations (JSON parsing) to avoid UI blocking.const constructors everywhere possible to reduce rebuilds.build().ValueNotifier, ChangeNotifier, ListenableBuilder.ChangeNotifier.// Simple Local State
final ValueNotifier<int> _counter = ValueNotifier<int>(0);
ValueListenableBuilder<int>(
valueListenable: _counter,
builder: (context, value, child) => Text('Count: $value'),
);
Use go_router for all navigation needs (deep linking, web). Ensure users are redirected to login when unauthorized.
final GoRouter _router = GoRouter(
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (context, state) => const HomeScreen(),
routes: <RouteBase>[
GoRoute(
path: 'details/:id',
builder: (context, state) {
final String id = state.pathParameters['id']!;
return DetailScreen(id: id);
},
),
],
),
],
);
MaterialApp.router(routerConfig: _router);
json_serializable and json_annotation.fieldRename: FieldRename.snake for consistency.@JsonSerializable(fieldRename: FieldRename.snake)
class User {
final String firstName;
final String lastName;
User({required this.firstName, required this.lastName});
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}
ThemeData object to ensure a consistent application-wide style.theme and darkTheme.ColorScheme.fromSeed.final ThemeData lightTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
),
textTheme: GoogleFonts.outfitTextTheme(),
);
Flexible and Expanded in the same Row or Column.Row or Column, and you want them to move to the next line..builder).Stack by anchoring it to the edges.// Network Image with Error Handler
Image.network(
'https://example.com/img.png',
errorBuilder: (ctx, err, stack) => const Icon(Icons.error),
loadingBuilder: (ctx, child, prog) => prog == null ? child : const CircularProgressIndicator(),
);
/// for doc comments: This allows documentation generation tools to pick them up.Semantics widget to provide clear, descriptive labels for UI elements.Strictly follow flutter_lints.
include: package:flutter_lints/flutter.yaml
linter:
rules:
avoid_print: true
prefer_single_quotes: true
always_use_package_imports: true