一键导入
configure-global-defaults
Set global default values for RetryConfig, ThrottleConfig, DebounceConfig, and other bloc_superpowers configurations
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Set global default values for RetryConfig, ThrottleConfig, DebounceConfig, and other bloc_superpowers configurations
用 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 | configure-global-defaults |
| description | Set global default values for RetryConfig, ThrottleConfig, DebounceConfig, and other bloc_superpowers configurations |
This skill sets global default values for bloc_superpowers configuration classes.
Configures static defaults properties on configuration classes so that:
mix() calls use your preferred defaultsAsk the user what default values they want for:
Set defaults in main() before runApp():
import 'package:bloc_superpowers/bloc_superpowers.dart';
import 'package:flutter/material.dart';
void main() {
// Configure global defaults
RetryConfig.defaults = retry(
maxRetries: 5,
initialDelay: 200.millis,
multiplier: 2.0,
maxDelay: 10.sec,
);
runApp(
Superpowers(
child: MyApp(),
),
);
}
Now when you use retry: retry without parameters, it uses your defaults:
void loadData() => mix(
key: this,
retry: retry, // Uses your 5 retries, 200ms delay, etc.
() async {
final data = await api.getData();
emit(data);
},
);
RetryConfig.defaults = retry(
maxRetries: 5, // Default: 3
initialDelay: 200.millis, // Default: 350ms
multiplier: 2.0, // Default: 2
maxDelay: 10.sec, // Default: 5 seconds
);
ThrottleConfig.defaults = throttle(
duration: 2.sec, // Default: 1 second
);
DebounceConfig.defaults = debounce(
duration: 500.millis, // Default: 300ms
);
FreshConfig.defaults = fresh(
freshFor: 30.sec, // Default: 1 second
);
CheckInternetConfig.defaults = checkInternet(
maxRetryDelay: 2.sec, // Default: 1 second
);
SequentialConfig.defaults = sequential(
maxQueueSize: 50, // Default: unlimited
queueTimeout: 30.sec, // Default: none
);
import 'package:bloc_superpowers/bloc_superpowers.dart';
import 'package:flutter/material.dart';
void main() {
_configureSuperpowersDefaults();
runApp(
Superpowers(
child: MyApp(),
),
);
}
void _configureSuperpowersDefaults() {
// Retry: 5 attempts with faster initial retry
RetryConfig.defaults = retry(
maxRetries: 5,
initialDelay: 200.millis,
multiplier: 2.0,
maxDelay: 10.sec,
);
// Throttle: 2 seconds between calls
ThrottleConfig.defaults = throttle(
duration: 2.sec,
);
// Debounce: 400ms wait for search
DebounceConfig.defaults = debounce(
duration: 400.millis,
);
// Fresh: Data valid for 30 seconds
FreshConfig.defaults = fresh(
freshFor: 30.sec,
);
// Sequential: Limit queue size
SequentialConfig.defaults = sequential(
maxQueueSize: 100,
queueTimeout: 60.sec,
);
}
Config.defaults)config:)mix())// Built-in default: maxRetries = 3
// Your default: maxRetries = 5
RetryConfig.defaults = retry(maxRetries: 5);
// Uses your default (5)
mix(key: this, retry: retry, () async { ... });
// Overrides to 10
mix(key: this, retry: retry(maxRetries: 10), () async { ... });
Good candidates for custom defaults:
Consider your app's needs:
To reset to built-in defaults (useful in tests):
void setUp() {
Superpowers.clear(); // Resets everything including defaults
}
Or reset individual configs:
RetryConfig.defaults = RetryConfig.builtInDefaults;
ThrottleConfig.defaults = ThrottleConfig.builtInDefaults;
Ask the user: