بنقرة واحدة
create-mix-preset
Create a callable MixPreset function that replaces mix() with preconfigured settings
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Create a callable MixPreset function that replaces mix() with preconfigured settings
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Add custom error handling with catchError to a mix() call for logging, error conversion, or suppression
Add internet connectivity checking before executing a Cubit method with optional retry
Add debounce to delay method execution until after a period of inactivity for search or validation
Add EffectQueue to state for triggering multiple sequential one-time UI effects
Add Effect fields to state class for one-time UI notifications like snackbars, navigation, or form clearing
Add error state handling to widgets using context.isFailed() and context.getException()
| name | create-mix-preset |
| description | Create a callable MixPreset function that replaces mix() with preconfigured settings |
This skill creates a MixPreset - a callable reusable function that replaces mix() with preconfigured settings.
Creates a MixPreset that:
mix() function with preset parametersmix()mix()| Feature | MixConfig | MixPreset |
|---|---|---|
| Usage | mix(config: myConfig, ...) | myPreset(...) |
| Callable | No | Yes |
| Default key | No | Yes |
| Code style | Passes to mix() | Replaces mix() |
Ask the user what common pattern they want to encapsulate:
Define a const MixPreset with the desired parameters:
import 'package:bloc_superpowers/bloc_superpowers.dart';
const apiCall = MixPreset(
retry: retry,
checkInternet: checkInternet,
);
Call it directly instead of mix():
class UserCubit extends Cubit<User> {
void loadUser() => apiCall(
key: this,
() async {
final user = await api.getUser();
emit(user);
},
);
}
const apiCall = MixPreset(
retry: retry(maxRetries: 3),
checkInternet: checkInternet,
);
// Usage
void loadData() => apiCall(
key: this,
() async {
final data = await api.getData();
emit(data);
},
);
Avoid repeating the key by setting a default:
const userApiCall = MixPreset(
key: UserCubit, // Default key
retry: retry,
checkInternet: checkInternet,
);
// Usage - key is optional
void loadUser() => userApiCall(
() async {
final user = await api.getUser();
emit(user);
},
);
void _logStart() => print('API call starting...');
void _logEnd() => print('API call complete');
void _logError(Object error, StackTrace stack) => print('Error: $error');
const loggedApiCall = MixPreset(
retry: retry,
checkInternet: checkInternet,
before: _logStart,
after: _logEnd,
catchError: _logError,
);
const criticalLoad = MixPreset(
retry: retry.unlimited,
checkInternet: checkInternet(maxRetryDelay: 1.sec),
);
// Usage
void loadAppConfig() => criticalLoad(
key: this,
() async {
final config = await api.getConfig();
emit(config);
},
);
const backgroundSync = MixPreset(
checkInternet: checkInternet(abortSilently: true),
nonReentrant: nonReentrant,
);
// Usage
void sync() => backgroundSync(
key: Sync,
() async {
await api.syncData();
},
);
Use .ctx() to access retry attempts and other context info:
const apiCall = MixPreset(
retry: retry,
);
void loadData() => apiCall.ctx(
key: this,
(ctx) async {
final attempt = ctx.retry!.attempt; // 0, 1, 2, ...
print('Attempt ${attempt + 1}');
final data = await api.getData();
emit(data);
},
);
Explicit parameters override preset values:
const apiCall = MixPreset(
retry: retry(maxRetries: 3),
checkInternet: checkInternet,
);
// Uses preset retry (3 attempts)
void loadUsers() => apiCall(
key: this,
() async { ... },
);
// Overrides to 10 attempts
void loadCriticalData() => apiCall(
key: this,
retry: retry(maxRetries: 10), // Overrides preset
() async { ... },
);
Values resolve in order (later wins):
// lib/presets/api_presets.dart
import 'package:bloc_superpowers/bloc_superpowers.dart';
/// Standard API call with retry and internet check
const apiCall = MixPreset(
retry: retry(maxRetries: 3),
checkInternet: checkInternet,
);
/// Critical data that must eventually load
const criticalLoad = MixPreset(
retry: retry.unlimited,
checkInternet: checkInternet(maxRetryDelay: 1.sec),
);
/// Background sync that fails silently
const backgroundSync = MixPreset(
checkInternet: checkInternet(abortSilently: true),
nonReentrant: nonReentrant,
);
/// Search with debounce
const searchCall = MixPreset(
debounce: debounce(duration: 300.millis),
);
// Usage in Cubit
class ProductCubit extends Cubit<ProductState> {
ProductCubit() : super(const ProductState());
// Standard API call
void loadProducts() => apiCall(
key: this,
() async {
final products = await api.getProducts();
emit(state.copyWith(products: products));
},
);
// Critical data
void loadCategories() => criticalLoad(
key: LoadCategories,
() async {
final categories = await api.getCategories();
emit(state.copyWith(categories: categories));
},
);
// Background sync
void syncFavorites() => backgroundSync(
key: SyncFavorites,
() async {
await api.syncFavorites(state.favorites);
},
);
// Search
void search(String query) => searchCall(
key: Search,
() async {
final results = await api.search(query);
emit(state.copyWith(searchResults: results));
},
);
// Override retry for specific case
void loadProductDetails(String id) => apiCall(
key: (ProductDetails, id),
retry: retry(maxRetries: 5), // More retries for this
() async {
final details = await api.getProductDetails(id);
emit(state.copyWith(
productDetails: {...state.productDetails, id: details},
));
},
);
}
Use MixPreset when:
myPreset(...) over mix(config: ..., ...)Use MixConfig when:
mix() explicitlyconfig: parameter styleFor injecting parameters into every action (dependency injection pattern):
final apiCall = MixPreset.withUserContext<
({String baseUrl, void Function(String) log}), // P: injected params type
({String env, bool verbose}) // C: call-time config type
>(
params: (ctx, config) => (
baseUrl: config.env == 'prod'
? 'https://api.example.com'
: 'https://staging.example.com',
log: (msg) {
if (config.verbose) {
final attempt = ctx.retry?.attempt ?? 0;
debugPrint('[API Attempt $attempt] $msg');
}
},
),
defaultConfig: (env: 'dev', verbose: false),
retry: retry,
checkInternet: checkInternet,
);
// Usage - actions receive injected params
await apiCall(
key: 'fetchUsers',
config: (env: 'prod', verbose: true),
(ctx) async {
ctx.log('Fetching users...');
return await http.get('${ctx.baseUrl}/users');
},
);
Key points:
params function receives MixContext - can access retry metadataUse MixPreset.withUserContext when:
Ask the user: