|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:zeta_example/widgets.dart'; |
| 3 | +import 'package:zeta_flutter/zeta_flutter.dart'; |
| 4 | + |
| 5 | +class SnackBarExample extends StatelessWidget { |
| 6 | + static const String name = 'SnackBar'; |
| 7 | + |
| 8 | + const SnackBarExample({super.key}); |
| 9 | + |
| 10 | + @override |
| 11 | + Widget build(BuildContext context) { |
| 12 | + return ExampleScaffold( |
| 13 | + name: SnackBarExample.name, |
| 14 | + child: SingleChildScrollView( |
| 15 | + child: Row( |
| 16 | + mainAxisAlignment: MainAxisAlignment.center, |
| 17 | + children: [ |
| 18 | + Column( |
| 19 | + children: [ |
| 20 | + // Standard Rounded |
| 21 | + Row( |
| 22 | + children: [ |
| 23 | + Padding( |
| 24 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 25 | + child: ZetaButton.primary( |
| 26 | + label: "Standard Rounded SnackBar", |
| 27 | + onPressed: () { |
| 28 | + ScaffoldMessenger.of(context).showSnackBar( |
| 29 | + ZetaSnackBar( |
| 30 | + context: context, |
| 31 | + onPressed: () { |
| 32 | + ScaffoldMessenger.of(context).hideCurrentSnackBar(); |
| 33 | + }, |
| 34 | + actionLabel: "Action", |
| 35 | + content: Text('This is a snackbar'), |
| 36 | + ), |
| 37 | + ); |
| 38 | + }, |
| 39 | + ), |
| 40 | + ), |
| 41 | + ], |
| 42 | + ), |
| 43 | + |
| 44 | + // Standard Sharp |
| 45 | + Padding( |
| 46 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 47 | + child: ZetaButton.primary( |
| 48 | + label: "Standard Sharp SnackBar", |
| 49 | + onPressed: () { |
| 50 | + ScaffoldMessenger.of(context).showSnackBar( |
| 51 | + ZetaSnackBar( |
| 52 | + context: context, |
| 53 | + onPressed: () { |
| 54 | + ScaffoldMessenger.of(context).hideCurrentSnackBar(); |
| 55 | + }, |
| 56 | + actionLabel: "Action", |
| 57 | + rounded: false, |
| 58 | + content: Text('This is a snackbar'), |
| 59 | + ), |
| 60 | + ); |
| 61 | + }, |
| 62 | + ), |
| 63 | + ), |
| 64 | + |
| 65 | + // Default |
| 66 | + Padding( |
| 67 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 68 | + child: ZetaButton.primary( |
| 69 | + label: "Contectual Default", |
| 70 | + onPressed: () { |
| 71 | + ScaffoldMessenger.of(context).showSnackBar( |
| 72 | + ZetaSnackBar( |
| 73 | + context: context, |
| 74 | + type: ZetaSnackBarType.defaultType, |
| 75 | + leadingIcon: Icon(Icons.mood_rounded), |
| 76 | + content: Text('Message with icon'), |
| 77 | + ), |
| 78 | + ); |
| 79 | + }, |
| 80 | + ), |
| 81 | + ), |
| 82 | + |
| 83 | + // Action |
| 84 | + Padding( |
| 85 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 86 | + child: ZetaButton.primary( |
| 87 | + label: "Action", |
| 88 | + onPressed: () { |
| 89 | + ScaffoldMessenger.of(context).showSnackBar( |
| 90 | + ZetaSnackBar( |
| 91 | + context: context, |
| 92 | + type: ZetaSnackBarType.action, |
| 93 | + onPressed: () {}, |
| 94 | + actionLabel: "Action", |
| 95 | + content: Text('Actionable message with icon'), |
| 96 | + ), |
| 97 | + ); |
| 98 | + }, |
| 99 | + ), |
| 100 | + ), |
| 101 | + |
| 102 | + // Positive |
| 103 | + Padding( |
| 104 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 105 | + child: ZetaButton.primary( |
| 106 | + label: "Positive", |
| 107 | + onPressed: () { |
| 108 | + ScaffoldMessenger.of(context).showSnackBar( |
| 109 | + ZetaSnackBar( |
| 110 | + context: context, |
| 111 | + type: ZetaSnackBarType.positive, |
| 112 | + content: Text('Request sent successfully'), |
| 113 | + ), |
| 114 | + ); |
| 115 | + }, |
| 116 | + ), |
| 117 | + ), |
| 118 | + |
| 119 | + // Info |
| 120 | + Padding( |
| 121 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 122 | + child: ZetaButton.primary( |
| 123 | + label: "Info", |
| 124 | + onPressed: () { |
| 125 | + ScaffoldMessenger.of(context).showSnackBar( |
| 126 | + ZetaSnackBar( |
| 127 | + context: context, |
| 128 | + type: ZetaSnackBarType.info, |
| 129 | + content: Text('Information is being displayed'), |
| 130 | + ), |
| 131 | + ); |
| 132 | + }, |
| 133 | + ), |
| 134 | + ), |
| 135 | + |
| 136 | + // Info |
| 137 | + Padding( |
| 138 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 139 | + child: ZetaButton.primary( |
| 140 | + label: "Info", |
| 141 | + onPressed: () { |
| 142 | + ScaffoldMessenger.of(context).showSnackBar( |
| 143 | + ZetaSnackBar( |
| 144 | + context: context, |
| 145 | + type: ZetaSnackBarType.info, |
| 146 | + content: Text('Information is being displayed'), |
| 147 | + ), |
| 148 | + ); |
| 149 | + }, |
| 150 | + ), |
| 151 | + ), |
| 152 | + |
| 153 | + // Warning |
| 154 | + Padding( |
| 155 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 156 | + child: ZetaButton.primary( |
| 157 | + label: "Warning", |
| 158 | + onPressed: () { |
| 159 | + ScaffoldMessenger.of(context).showSnackBar( |
| 160 | + ZetaSnackBar( |
| 161 | + context: context, |
| 162 | + type: ZetaSnackBarType.warning, |
| 163 | + content: Text('Warning has been issued'), |
| 164 | + ), |
| 165 | + ); |
| 166 | + }, |
| 167 | + ), |
| 168 | + ), |
| 169 | + |
| 170 | + // Error |
| 171 | + Padding( |
| 172 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 173 | + child: ZetaButton.primary( |
| 174 | + label: "Error", |
| 175 | + onPressed: () { |
| 176 | + ScaffoldMessenger.of(context).showSnackBar( |
| 177 | + ZetaSnackBar( |
| 178 | + context: context, |
| 179 | + type: ZetaSnackBarType.error, |
| 180 | + content: Text('Error has been detected'), |
| 181 | + ), |
| 182 | + ); |
| 183 | + }, |
| 184 | + ), |
| 185 | + ), |
| 186 | + |
| 187 | + // Deletion |
| 188 | + Padding( |
| 189 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 190 | + child: ZetaButton.primary( |
| 191 | + label: "Deletion", |
| 192 | + onPressed: () { |
| 193 | + ScaffoldMessenger.of(context).showSnackBar( |
| 194 | + ZetaSnackBar( |
| 195 | + context: context, |
| 196 | + type: ZetaSnackBarType.deletion, |
| 197 | + onPressed: () {}, |
| 198 | + content: Text('Item was deleted'), |
| 199 | + ), |
| 200 | + ); |
| 201 | + }, |
| 202 | + ), |
| 203 | + ), |
| 204 | + |
| 205 | + // View |
| 206 | + Padding( |
| 207 | + padding: const EdgeInsets.only(top: ZetaSpacing.x4), |
| 208 | + child: ZetaButton.primary( |
| 209 | + label: "View", |
| 210 | + onPressed: () { |
| 211 | + ScaffoldMessenger.of(context).showSnackBar( |
| 212 | + ZetaSnackBar( |
| 213 | + context: context, |
| 214 | + type: ZetaSnackBarType.view, |
| 215 | + onPressed: () {}, |
| 216 | + content: Text('Something neeeds your attention'), |
| 217 | + ), |
| 218 | + ); |
| 219 | + }, |
| 220 | + ), |
| 221 | + ), |
| 222 | + ], |
| 223 | + ), |
| 224 | + ], |
| 225 | + ), |
| 226 | + ), |
| 227 | + ); |
| 228 | + } |
| 229 | +} |
0 commit comments