|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import 'example_model.dart'; |
| 4 | + |
| 5 | +/// Minimal wrapper for embedding examples in iframes. |
| 6 | +/// |
| 7 | +/// Shows the example with minimal chrome - just the example content |
| 8 | +/// and optionally a small header with title and source link. |
| 9 | +class EmbedWrapper extends StatelessWidget { |
| 10 | + final Example example; |
| 11 | + final bool showHeader; |
| 12 | + final VoidCallback? onSourceTap; |
| 13 | + |
| 14 | + const EmbedWrapper({ |
| 15 | + super.key, |
| 16 | + required this.example, |
| 17 | + this.showHeader = true, |
| 18 | + this.onSourceTap, |
| 19 | + }); |
| 20 | + |
| 21 | + @override |
| 22 | + Widget build(BuildContext context) { |
| 23 | + final theme = Theme.of(context); |
| 24 | + |
| 25 | + return Scaffold( |
| 26 | + backgroundColor: theme.colorScheme.surface, |
| 27 | + body: Column( |
| 28 | + children: [ |
| 29 | + // Minimal header for embedded view |
| 30 | + if (showHeader) |
| 31 | + Container( |
| 32 | + height: 40, |
| 33 | + padding: const EdgeInsets.symmetric(horizontal: 12), |
| 34 | + decoration: BoxDecoration( |
| 35 | + color: theme.colorScheme.surfaceContainerHighest, |
| 36 | + border: Border( |
| 37 | + bottom: BorderSide( |
| 38 | + color: theme.colorScheme.outlineVariant, |
| 39 | + width: 1, |
| 40 | + ), |
| 41 | + ), |
| 42 | + ), |
| 43 | + child: Row( |
| 44 | + children: [ |
| 45 | + if (example.icon != null) ...[ |
| 46 | + Icon( |
| 47 | + example.icon, |
| 48 | + size: 16, |
| 49 | + color: theme.colorScheme.primary, |
| 50 | + ), |
| 51 | + const SizedBox(width: 8), |
| 52 | + ], |
| 53 | + Expanded( |
| 54 | + child: Text( |
| 55 | + example.title, |
| 56 | + style: theme.textTheme.titleSmall?.copyWith( |
| 57 | + fontWeight: FontWeight.w600, |
| 58 | + color: theme.colorScheme.onSurface, |
| 59 | + ), |
| 60 | + maxLines: 1, |
| 61 | + overflow: TextOverflow.ellipsis, |
| 62 | + ), |
| 63 | + ), |
| 64 | + if (onSourceTap != null) |
| 65 | + TextButton.icon( |
| 66 | + onPressed: onSourceTap, |
| 67 | + icon: Icon( |
| 68 | + Icons.code, |
| 69 | + size: 16, |
| 70 | + color: theme.colorScheme.primary, |
| 71 | + ), |
| 72 | + label: Text( |
| 73 | + 'Source', |
| 74 | + style: TextStyle( |
| 75 | + fontSize: 12, |
| 76 | + color: theme.colorScheme.primary, |
| 77 | + ), |
| 78 | + ), |
| 79 | + style: TextButton.styleFrom( |
| 80 | + padding: const EdgeInsets.symmetric(horizontal: 8), |
| 81 | + minimumSize: Size.zero, |
| 82 | + tapTargetSize: MaterialTapTargetSize.shrinkWrap, |
| 83 | + ), |
| 84 | + ), |
| 85 | + ], |
| 86 | + ), |
| 87 | + ), |
| 88 | + // Example content |
| 89 | + Expanded(child: example.builder(context)), |
| 90 | + ], |
| 91 | + ), |
| 92 | + ); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +/// Embed wrapper without any header - just the raw example. |
| 97 | +class EmbedWrapperMinimal extends StatelessWidget { |
| 98 | + final Example example; |
| 99 | + |
| 100 | + const EmbedWrapperMinimal({super.key, required this.example}); |
| 101 | + |
| 102 | + @override |
| 103 | + Widget build(BuildContext context) { |
| 104 | + return Scaffold(body: example.builder(context)); |
| 105 | + } |
| 106 | +} |
0 commit comments