build method

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

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  return Card(
    child: Padding(
      padding: const EdgeInsets.all(SubZeroSpacing.lg),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Toast Types Preview
          Text('Toast Types', style: SubZeroTypography.textTheme.titleMedium),
          const SizedBox(height: SubZeroSpacing.sm),
          Text(
            'Non-intrusive feedback messages with status-specific colors',
            style: SubZeroTypography.textTheme.bodySmall,
          ),
          const SizedBox(height: SubZeroSpacing.lg),

          // Icon Variants (left column in Figma)
          Text('Icon Variant', style: SubZeroTypography.textTheme.labelLarge),
          const SizedBox(height: SubZeroSpacing.md),

          Wrap(
            spacing: SubZeroSpacing.md,
            runSpacing: SubZeroSpacing.md,
            children: const [
              SubZeroToastPreview(
                message: 'This is a toast for default',
                type: SubZeroToastType.defaultType,
                actionMode: SubZeroToastActionMode.icon,
              ),
              SubZeroToastPreview(
                message: 'This is a toast for info',
                type: SubZeroToastType.info,
                actionMode: SubZeroToastActionMode.icon,
              ),
              SubZeroToastPreview(
                message: 'This is a toast for success',
                type: SubZeroToastType.success,
                actionMode: SubZeroToastActionMode.icon,
              ),
              SubZeroToastPreview(
                message: 'This is a toast for error',
                type: SubZeroToastType.error,
                actionMode: SubZeroToastActionMode.icon,
              ),
              SubZeroToastPreview(
                message: 'This is a toast for warning',
                type: SubZeroToastType.warning,
                actionMode: SubZeroToastActionMode.icon,
              ),
            ],
          ),

          const SizedBox(height: SubZeroSpacing.xl),

          // Text Variants (right column in Figma)
          Text('Text Action Variant', style: SubZeroTypography.textTheme.labelLarge),
          const SizedBox(height: SubZeroSpacing.md),

          Wrap(
            spacing: SubZeroSpacing.md,
            runSpacing: SubZeroSpacing.md,
            children: const [
              SubZeroToastPreview(
                message: 'This is a toast for default',
                type: SubZeroToastType.defaultType,
                actionMode: SubZeroToastActionMode.text,
                actionLabel: 'ACTION',
              ),
              SubZeroToastPreview(
                message: 'This is a toast for info',
                type: SubZeroToastType.info,
                actionMode: SubZeroToastActionMode.text,
                actionLabel: 'ACTION',
              ),
              SubZeroToastPreview(
                message: 'This is a toast for success',
                type: SubZeroToastType.success,
                actionMode: SubZeroToastActionMode.text,
                actionLabel: 'ACTION',
              ),
              SubZeroToastPreview(
                message: 'This is a toast for error',
                type: SubZeroToastType.error,
                actionMode: SubZeroToastActionMode.text,
                actionLabel: 'ACTION',
              ),
              SubZeroToastPreview(
                message: 'This is a toast for warning',
                type: SubZeroToastType.warning,
                actionMode: SubZeroToastActionMode.text,
                actionLabel: 'ACTION',
              ),
            ],
          ),

          const Divider(height: SubZeroSpacing.xxl),

          // Interactive Demo
          Text('Interactive Demo', style: SubZeroTypography.textTheme.titleMedium),
          const SizedBox(height: SubZeroSpacing.sm),
          Text(
            'Tap buttons to trigger actual toast overlays',
            style: SubZeroTypography.textTheme.bodySmall,
          ),
          const SizedBox(height: SubZeroSpacing.lg),

          Wrap(
            spacing: SubZeroSpacing.md,
            runSpacing: SubZeroSpacing.md,
            children: [
              _ToastTriggerButton(
                label: 'Default',
                color: const Color(0xFF3D3D3D),
                onPressed: () => SubZeroToast.defaultToast(
                  context,
                  message: 'Self recommendation completed',
                ),
              ),
              _ToastTriggerButton(
                label: 'Info',
                color: const Color(0xFF0D5A65),
                onPressed: () => SubZeroToast.info(
                  context,
                  message: 'Your session will expire in 5 minutes',
                ),
              ),
              _ToastTriggerButton(
                label: 'Success',
                color: const Color(0xFF008A2E),
                onPressed: () => SubZeroToast.success(
                  context,
                  message: 'Item saved successfully!',
                ),
              ),
              _ToastTriggerButton(
                label: 'Error',
                color: const Color(0xFFDC3545),
                onPressed: () => SubZeroToast.error(
                  context,
                  message: 'Failed to save changes',
                ),
              ),
              _ToastTriggerButton(
                label: 'Warning',
                color: const Color(0xFFD84A05),
                onPressed: () => SubZeroToast.warning(
                  context,
                  message: 'Your storage is almost full',
                ),
              ),
            ],
          ),

          const SizedBox(height: SubZeroSpacing.lg),

          // With Action Button
          Text('With Action Button', style: SubZeroTypography.textTheme.labelLarge),
          const SizedBox(height: SubZeroSpacing.md),

          Wrap(
            spacing: SubZeroSpacing.md,
            runSpacing: SubZeroSpacing.md,
            children: [
              _ToastTriggerButton(
                label: 'With UNDO',
                color: SubZeroColors.secondary,
                onPressed: () => SubZeroToast.show(
                  context,
                  message: 'Item deleted',
                  type: SubZeroToastType.defaultType,
                  actionMode: SubZeroToastActionMode.text,
                  actionLabel: 'UNDO',
                  onAction: () {},
                ),
              ),
              _ToastTriggerButton(
                label: 'Top Position',
                color: SubZeroColors.info,
                onPressed: () => SubZeroToast.info(
                  context,
                  message: 'Message at top of screen',
                  position: SubZeroToastPosition.top,
                ),
              ),
              _ToastTriggerButton(
                label: 'Short Duration',
                color: SubZeroColors.success,
                onPressed: () => SubZeroToast.success(
                  context,
                  message: 'Quick notification (2s)',
                  duration: const Duration(seconds: 2),
                ),
              ),
            ],
          ),

          const Divider(height: SubZeroSpacing.xxl),

          // Usage Example
          Text('Usage', style: SubZeroTypography.textTheme.titleMedium),
          const SizedBox(height: SubZeroSpacing.md),
          Container(
            padding: const EdgeInsets.all(SubZeroSpacing.md),
            decoration: BoxDecoration(
              color: SubZeroColors.surfaceVariant,
              borderRadius: BorderRadius.circular(SubZeroRadius.sm),
            ),
            child: const Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '// Simple toast\n'
                  'SubZeroToast.success(context, message: \'Saved!\');\n\n'
                  '// With action\n'
                  'SubZeroToast.show(\n'
                  '  context,\n'
                  '  message: \'Item deleted\',\n'
                  '  actionMode: SubZeroToastActionMode.text,\n'
                  '  actionLabel: \'UNDO\',\n'
                  '  onAction: () => undoDelete(),\n'
                  ');',
                  style: TextStyle(
                    fontFamily: 'monospace',
                    fontSize: 12,
                  ),
                ),
              ],
            ),
          ),

          const Divider(height: SubZeroSpacing.xxl),

          // API Reference
          Text('API Reference', style: SubZeroTypography.textTheme.titleMedium),
          const SizedBox(height: SubZeroSpacing.md),
          Container(
            padding: const EdgeInsets.all(SubZeroSpacing.md),
            decoration: BoxDecoration(
              color: SubZeroColors.surfaceVariant,
              borderRadius: BorderRadius.circular(SubZeroRadius.sm),
            ),
            child: const Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('SubZeroToast', style: TextStyle(fontWeight: FontWeight.bold)),
                SizedBox(height: SubZeroSpacing.sm),
                _ApiItem('.show()', 'Full configuration toast'),
                _ApiItem('.defaultToast()', 'Dark gray default toast'),
                _ApiItem('.info()', 'Teal info toast'),
                _ApiItem('.success()', 'Green success toast'),
                _ApiItem('.error()', 'Red error toast'),
                _ApiItem('.warning()', 'Orange warning toast'),
                _ApiItem('.dismiss()', 'Manually dismiss current toast'),
                SizedBox(height: SubZeroSpacing.md),
                Text('Parameters', style: TextStyle(fontWeight: FontWeight.bold)),
                SizedBox(height: SubZeroSpacing.sm),
                _ApiItem('message', 'Toast message text'),
                _ApiItem('type', 'defaultType / info / success / error / warning'),
                _ApiItem('position', 'top / bottom'),
                _ApiItem('actionMode', 'icon (X button) / text (ACTION button)'),
                _ApiItem('duration', 'Auto-dismiss duration (default 4s)'),
                _ApiItem('actionLabel', 'Custom action button text'),
                _ApiItem('onAction', 'Callback when action is tapped'),
                _ApiItem('leadingIcon', 'Optional icon before message'),
              ],
            ),
          ),
        ],
      ),
    ),
  );
}