build method
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:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedWidgetOfExactType.
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: [
// Horizontal Dividers
Text('Horizontal Dividers', style: SubZeroTypography.textTheme.titleMedium),
const SizedBox(height: SubZeroSpacing.sm),
Text(
'Line and Section variants for separating horizontal content',
style: SubZeroTypography.textTheme.bodySmall,
),
const SizedBox(height: SubZeroSpacing.lg),
// Line divider
Text('Line Divider (1px)', style: SubZeroTypography.textTheme.labelLarge),
const SizedBox(height: SubZeroSpacing.sm),
Container(
padding: const EdgeInsets.symmetric(vertical: SubZeroSpacing.md),
decoration: BoxDecoration(
color: SubZeroColors.surface,
borderRadius: BorderRadius.circular(SubZeroRadius.sm),
border: Border.all(color: SubZeroColors.border),
),
child: const Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Text('Content above'),
),
SubZeroDivider(),
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Text('Content below'),
),
],
),
),
const SizedBox(height: SubZeroSpacing.lg),
// Section divider
Text('Section Divider (8px)', style: SubZeroTypography.textTheme.labelLarge),
const SizedBox(height: SubZeroSpacing.sm),
Container(
padding: const EdgeInsets.symmetric(vertical: SubZeroSpacing.md),
decoration: BoxDecoration(
color: SubZeroColors.surface,
borderRadius: BorderRadius.circular(SubZeroRadius.sm),
border: Border.all(color: SubZeroColors.border),
),
child: const Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Text('Section 1'),
),
SubZeroDivider(variant: SubZeroDividerVariant.section),
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Text('Section 2'),
),
],
),
),
const Divider(height: SubZeroSpacing.xxl),
// Vertical Dividers
Text('Vertical Dividers', style: SubZeroTypography.textTheme.titleMedium),
const SizedBox(height: SubZeroSpacing.sm),
Text(
'Line and Section variants for separating vertical content',
style: SubZeroTypography.textTheme.bodySmall,
),
const SizedBox(height: SubZeroSpacing.lg),
// Vertical dividers in a row
Container(
padding: const EdgeInsets.all(SubZeroSpacing.md),
decoration: BoxDecoration(
color: SubZeroColors.surface,
borderRadius: BorderRadius.circular(SubZeroRadius.sm),
border: Border.all(color: SubZeroColors.border),
),
child: IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Line'),
SizedBox(height: SubZeroSpacing.sm),
SubZeroVerticalDivider(length: 48),
],
),
const SizedBox(width: SubZeroSpacing.xxl),
const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Section'),
SizedBox(height: SubZeroSpacing.sm),
SubZeroVerticalDivider(
variant: SubZeroDividerVariant.section,
length: 48,
),
],
),
const SizedBox(width: SubZeroSpacing.xxl),
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Custom'),
const SizedBox(height: SubZeroSpacing.sm),
SubZeroVerticalDivider(
thickness: 3,
length: 48,
color: SubZeroColors.primary,
),
],
),
],
),
),
),
const Divider(height: SubZeroSpacing.xxl),
// Customization options
Text('Customization', style: SubZeroTypography.textTheme.titleMedium),
const SizedBox(height: SubZeroSpacing.sm),
Text(
'Custom thickness, color, indent, and margin',
style: SubZeroTypography.textTheme.bodySmall,
),
const SizedBox(height: SubZeroSpacing.lg),
// Indented divider
Text('Indented Divider', style: SubZeroTypography.textTheme.labelLarge),
const SizedBox(height: SubZeroSpacing.sm),
Container(
padding: const EdgeInsets.symmetric(vertical: SubZeroSpacing.md),
decoration: BoxDecoration(
color: SubZeroColors.surface,
borderRadius: BorderRadius.circular(SubZeroRadius.sm),
border: Border.all(color: SubZeroColors.border),
),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Row(
children: [
Icon(Icons.person, size: 20),
SizedBox(width: SubZeroSpacing.sm),
Text('List Item 1'),
],
),
),
SubZeroDivider(indent: 40),
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Row(
children: [
Icon(Icons.settings, size: 20),
SizedBox(width: SubZeroSpacing.sm),
Text('List Item 2'),
],
),
),
SubZeroDivider(indent: 40),
Padding(
padding: EdgeInsets.symmetric(horizontal: SubZeroSpacing.md),
child: Row(
children: [
Icon(Icons.info, size: 20),
SizedBox(width: SubZeroSpacing.sm),
Text('List Item 3'),
],
),
),
],
),
),
const SizedBox(height: SubZeroSpacing.lg),
// Custom color divider
Text('Custom Colors', style: SubZeroTypography.textTheme.labelLarge),
const SizedBox(height: SubZeroSpacing.sm),
const Wrap(
spacing: SubZeroSpacing.md,
runSpacing: SubZeroSpacing.md,
children: [
_ColorDividerSample(label: 'Primary', color: SubZeroColors.primary),
_ColorDividerSample(label: 'Success', color: SubZeroColors.success),
_ColorDividerSample(label: 'Warning', color: SubZeroColors.warning),
_ColorDividerSample(label: 'Error', color: SubZeroColors.error),
],
),
const Divider(height: SubZeroSpacing.xxl),
// API Reference
Text('API Reference', style: SubZeroTypography.textTheme.labelLarge),
const SizedBox(height: SubZeroSpacing.sm),
Container(
padding: const EdgeInsets.all(SubZeroSpacing.md),
decoration: BoxDecoration(
color: SubZeroColors.surfaceVariant,
borderRadius: BorderRadius.circular(SubZeroRadius.sm),
),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ApiItem('orientation', 'horizontal | vertical'),
_ApiItem('variant', 'line (1px) | section (8px)'),
_ApiItem('thickness', 'Custom thickness override'),
_ApiItem('length', 'Extent in main axis direction'),
_ApiItem('color', 'Custom color override'),
_ApiItem('indent', 'Start indentation'),
_ApiItem('endIndent', 'End indentation'),
_ApiItem('margin', 'Custom margin around divider'),
],
),
),
],
),
),
);
}