toWidget method
CoralWidget
toWidget({
- Key? key,
- Widget errorBuilder(
- BuildContext context,
- Object error,
- StackTrace? stackTrace
Converts this Computation into a strongly-typed CoralWidget.
key: Optional key for the CoralWidget.errorBuilder: Optional builder to render a fallback widget if the Computation fails.
Ensures:
- Returns a new CoralWidget containing this Computation's coral pipeline.
AI & Developer Note (App-Wide Fallback Pattern):
Create a project-specific extension (e.g. toAppWidget()) wrapping toWidget to encapsulate
your design system's default error UI and global error logging (e.g., Sentry, Firebase)
centrally across your application.
Example:
class CounterView extends BuildComponent { ... }
final widget = CounterView().toWidget();
// Custom App-Wide Fallback Extension Pattern:
extension AppCoralWidgetExtension<T extends CoralComputation<Widget>> on T {
CoralWidget toAppWidget({
Key? key,
Widget Function(BuildContext context, Object error, StackTrace? stackTrace)? errorBuilder,
}) {
return toWidget(
key: key,
errorBuilder: errorBuilder ?? (context, error, stackTrace) {
return AppStandardErrorCard(error: error); // Shared Design System Fallback
},
);
}
}
Implementation
CoralWidget toWidget({
Key? key,
Widget Function(BuildContext context, Object error, StackTrace? stackTrace)?
errorBuilder,
}) {
return CoralWidget(key: key, coral: coral, errorBuilder: errorBuilder);
}