flutter
Flutter cross-platform development with Dart. Widgets, state management (Riverpod, BLoC), navigation, platform channels, and production patterns. USE WHEN: user mentions "Flutter", "Dart", "flutter widget", "Riverpod", "BLoC", "flutter build", "pubspec.yaml" DO NOT USE FOR: React Native - use `react-native`; Expo - use `expo`; native iOS/Android
What this skill does
# Flutter
## Widget Basics
```dart
class ProductCard extends StatelessWidget {
final Product product;
final VoidCallback onTap;
const ProductCard({super.key, required this.product, required this.onTap});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(product.name, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 4),
Text('\$${product.price}', style: const TextStyle(color: Colors.grey)),
],
),
),
),
);
}
}
```
## State Management (Riverpod — recommended)
```dart
// Provider definition
final productsProvider = FutureProvider<List<Product>>((ref) async {
final repo = ref.watch(productRepoProvider);
return repo.fetchAll();
});
// Usage in widget
class ProductListScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final products = ref.watch(productsProvider);
return products.when(
data: (items) => ListView.builder(
itemCount: items.length,
itemBuilder: (context, i) => ProductCard(product: items[i], onTap: () {}),
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, _) => Center(child: Text('Error: $err')),
);
}
}
```
## Navigation (GoRouter)
```dart
final router = GoRouter(
routes: [
GoRoute(path: '/', builder: (_, __) => const HomeScreen()),
GoRoute(
path: '/product/:id',
builder: (_, state) => ProductScreen(id: state.pathParameters['id']!),
),
],
);
// Navigate
context.go('/product/123');
context.push('/product/123'); // pushes onto stack
```
## HTTP Requests (Dio)
```dart
final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'));
dio.interceptors.add(InterceptorsWrapper(
onRequest: (options, handler) {
options.headers['Authorization'] = 'Bearer $token';
handler.next(options);
},
));
Future<List<Product>> fetchProducts() async {
final response = await dio.get('/products');
return (response.data as List).map((e) => Product.fromJson(e)).toList();
}
```
## Platform Channels
```dart
// Dart side
const channel = MethodChannel('com.example/battery');
Future<int> getBatteryLevel() async {
final level = await channel.invokeMethod<int>('getBatteryLevel');
return level ?? -1;
}
```
## Anti-Patterns
| Anti-Pattern | Fix |
|--------------|-----|
| setState in large widgets | Extract state to Riverpod/BLoC |
| Deeply nested widget trees | Extract widgets into separate classes |
| No const constructors | Add `const` to stateless constructors |
| String-based navigation | Use GoRouter with type-safe routes |
| No error handling on futures | Use `.when()` or try-catch |
## Production Checklist
- [ ] Release mode builds tested on real devices
- [ ] App signing (Android keystore, iOS distribution cert)
- [ ] Flavor/scheme setup for dev/staging/prod
- [ ] Crashlytics or Sentry integration
- [ ] ProGuard rules for Android
- [ ] App size optimized (deferred components, tree shaking)
- [ ] Accessibility: Semantics widgets used
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.