build method

  1. @protected
Widget build(
  1. BuildContext context
)

Overrides the build method to conditionally choose which widget to build based on the screen type and the provided methods (builder, desktop, phone, tablet, watch).

If alwaysUseBuilder is set to true and builder is not null, the builder method is always used. Otherwise, the method corresponding to the current screen type is invoked. If a method corresponding to the current screen type is null, the method corresponding to a larger screen type is used as a fallback. If none of the methods are provided, the builder method is used as a final fallback.

Implementation

@protected
Widget build(BuildContext context) {
  screen.context = context;
  Widget? widget;
  if (alwaysUseBuilder) {
    widget = builder();
    if (widget != null) return widget;
  }
  if (screen.isDesktop) {
    widget = desktop() ?? widget;
    if (widget != null) return widget;
  }
  if (screen.isTablet) {
    widget = tablet() ?? desktop();
    if (widget != null) return widget;
  }
  if (screen.isPhone) {
    widget = phone() ?? tablet() ?? desktop();
    if (widget != null) return widget;
  }
  return watch() ?? phone() ?? tablet() ?? desktop() ?? builder()!;
}