|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:stream_core_flutter/stream_core_flutter.dart'; |
| 3 | +import 'package:widgetbook/widgetbook.dart'; |
| 4 | +import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook; |
| 5 | + |
| 6 | +// ============================================================================= |
| 7 | +// Playground |
| 8 | +// ============================================================================= |
| 9 | + |
| 10 | +@widgetbook.UseCase( |
| 11 | + name: 'Playground', |
| 12 | + type: StreamRetryBadge, |
| 13 | + path: '[Components]/Badge', |
| 14 | +) |
| 15 | +Widget buildStreamRetryBadgePlayground(BuildContext context) { |
| 16 | + final size = context.knobs.object.dropdown<StreamRetryBadgeSize>( |
| 17 | + label: 'Size', |
| 18 | + options: StreamRetryBadgeSize.values, |
| 19 | + initialOption: StreamRetryBadgeSize.md, |
| 20 | + labelBuilder: (option) => '${option.name.toUpperCase()} (${option.value.toInt()}px)', |
| 21 | + description: 'The diameter of the badge.', |
| 22 | + ); |
| 23 | + |
| 24 | + return Center( |
| 25 | + child: StreamRetryBadge(size: size), |
| 26 | + ); |
| 27 | +} |
| 28 | + |
| 29 | +// ============================================================================= |
| 30 | +// Showcase |
| 31 | +// ============================================================================= |
| 32 | + |
| 33 | +@widgetbook.UseCase( |
| 34 | + name: 'Showcase', |
| 35 | + type: StreamRetryBadge, |
| 36 | + path: '[Components]/Badge', |
| 37 | +) |
| 38 | +Widget buildStreamRetryBadgeShowcase(BuildContext context) { |
| 39 | + final colorScheme = context.streamColorScheme; |
| 40 | + final textTheme = context.streamTextTheme; |
| 41 | + final spacing = context.streamSpacing; |
| 42 | + |
| 43 | + return DefaultTextStyle( |
| 44 | + style: textTheme.bodyDefault.copyWith(color: colorScheme.textPrimary), |
| 45 | + child: SingleChildScrollView( |
| 46 | + padding: EdgeInsets.all(spacing.lg), |
| 47 | + child: const Column( |
| 48 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 49 | + children: [ |
| 50 | + _SizeVariantsSection(), |
| 51 | + ], |
| 52 | + ), |
| 53 | + ), |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +// ============================================================================= |
| 58 | +// Size Variants Section |
| 59 | +// ============================================================================= |
| 60 | + |
| 61 | +class _SizeVariantsSection extends StatelessWidget { |
| 62 | + const _SizeVariantsSection(); |
| 63 | + |
| 64 | + @override |
| 65 | + Widget build(BuildContext context) { |
| 66 | + final colorScheme = context.streamColorScheme; |
| 67 | + final textTheme = context.streamTextTheme; |
| 68 | + final boxShadow = context.streamBoxShadow; |
| 69 | + final radius = context.streamRadius; |
| 70 | + final spacing = context.streamSpacing; |
| 71 | + |
| 72 | + return Column( |
| 73 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 74 | + children: [ |
| 75 | + const _SectionLabel(label: 'SIZE VARIANTS'), |
| 76 | + SizedBox(height: spacing.md), |
| 77 | + Container( |
| 78 | + width: double.infinity, |
| 79 | + clipBehavior: Clip.antiAlias, |
| 80 | + padding: EdgeInsets.all(spacing.md), |
| 81 | + decoration: BoxDecoration( |
| 82 | + color: colorScheme.backgroundSurface, |
| 83 | + borderRadius: BorderRadius.all(radius.lg), |
| 84 | + boxShadow: boxShadow.elevation1, |
| 85 | + ), |
| 86 | + foregroundDecoration: BoxDecoration( |
| 87 | + borderRadius: BorderRadius.all(radius.lg), |
| 88 | + border: Border.all(color: colorScheme.borderSubtle), |
| 89 | + ), |
| 90 | + child: Column( |
| 91 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 92 | + children: [ |
| 93 | + Text( |
| 94 | + 'Two sizes for different contexts', |
| 95 | + style: textTheme.captionDefault.copyWith( |
| 96 | + color: colorScheme.textSecondary, |
| 97 | + ), |
| 98 | + ), |
| 99 | + SizedBox(height: spacing.md), |
| 100 | + Row( |
| 101 | + children: [ |
| 102 | + for (final (index, size) in StreamRetryBadgeSize.values.indexed) ...[ |
| 103 | + _SizeDemo(size: size), |
| 104 | + if (index < StreamRetryBadgeSize.values.length - 1) SizedBox(width: spacing.xl), |
| 105 | + ], |
| 106 | + ], |
| 107 | + ), |
| 108 | + ], |
| 109 | + ), |
| 110 | + ), |
| 111 | + ], |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +class _SizeDemo extends StatelessWidget { |
| 117 | + const _SizeDemo({required this.size}); |
| 118 | + |
| 119 | + final StreamRetryBadgeSize size; |
| 120 | + |
| 121 | + @override |
| 122 | + Widget build(BuildContext context) { |
| 123 | + final colorScheme = context.streamColorScheme; |
| 124 | + final textTheme = context.streamTextTheme; |
| 125 | + final spacing = context.streamSpacing; |
| 126 | + |
| 127 | + return Column( |
| 128 | + children: [ |
| 129 | + SizedBox( |
| 130 | + width: 48, |
| 131 | + height: 48, |
| 132 | + child: Center( |
| 133 | + child: StreamRetryBadge(size: size), |
| 134 | + ), |
| 135 | + ), |
| 136 | + SizedBox(height: spacing.sm), |
| 137 | + Text( |
| 138 | + size.name.toUpperCase(), |
| 139 | + style: textTheme.metadataEmphasis.copyWith( |
| 140 | + color: colorScheme.accentPrimary, |
| 141 | + fontFamily: 'monospace', |
| 142 | + ), |
| 143 | + ), |
| 144 | + Text( |
| 145 | + '${size.value.toInt()}px', |
| 146 | + style: textTheme.metadataDefault.copyWith( |
| 147 | + color: colorScheme.textTertiary, |
| 148 | + fontFamily: 'monospace', |
| 149 | + fontSize: 10, |
| 150 | + ), |
| 151 | + ), |
| 152 | + ], |
| 153 | + ); |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +// ============================================================================= |
| 158 | +// Shared Widgets |
| 159 | +// ============================================================================= |
| 160 | + |
| 161 | +class _SectionLabel extends StatelessWidget { |
| 162 | + const _SectionLabel({required this.label}); |
| 163 | + |
| 164 | + final String label; |
| 165 | + |
| 166 | + @override |
| 167 | + Widget build(BuildContext context) { |
| 168 | + final colorScheme = context.streamColorScheme; |
| 169 | + final textTheme = context.streamTextTheme; |
| 170 | + final radius = context.streamRadius; |
| 171 | + final spacing = context.streamSpacing; |
| 172 | + |
| 173 | + return Container( |
| 174 | + padding: EdgeInsets.symmetric(horizontal: spacing.sm, vertical: spacing.xs), |
| 175 | + decoration: BoxDecoration( |
| 176 | + color: colorScheme.accentPrimary, |
| 177 | + borderRadius: BorderRadius.all(radius.xs), |
| 178 | + ), |
| 179 | + child: Text( |
| 180 | + label, |
| 181 | + style: textTheme.metadataEmphasis.copyWith( |
| 182 | + color: colorScheme.textOnAccent, |
| 183 | + letterSpacing: 1, |
| 184 | + fontSize: 9, |
| 185 | + ), |
| 186 | + ), |
| 187 | + ); |
| 188 | + } |
| 189 | +} |
0 commit comments