|
| 1 | +import 'package:flash/flash.dart'; |
| 2 | +import 'package:fleasy/fleasy.dart'; |
1 | 3 | import 'package:flutter/material.dart';
|
2 | 4 |
|
3 | 5 | /// Class which defines the form factor breakpoints:
|
@@ -108,3 +110,98 @@ extension NavigationContextExtensions on BuildContext {
|
108 | 110 | /// (by removing the focus on this node by moving the primary focus to another node).
|
109 | 111 | void dismissKeyboard() => FocusScope.of(this).unfocus();
|
110 | 112 | }
|
| 113 | + |
| 114 | +extension FlashbarContextExtensions on BuildContext { |
| 115 | + void _showFlashbar( |
| 116 | + String message, { |
| 117 | + required Color iconColor, |
| 118 | + required IconData icon, |
| 119 | + int duration = 3, |
| 120 | + }) { |
| 121 | + showFlash<Flash>( |
| 122 | + context: this, |
| 123 | + duration: Duration(seconds: duration), |
| 124 | + transitionDuration: const Duration(milliseconds: 750), |
| 125 | + builder: (context, controller) { |
| 126 | + return Flash<Flash>.bar( |
| 127 | + controller: controller, |
| 128 | + backgroundColor: const Color(0xFF303030), |
| 129 | + borderRadius: BorderRadius.circular(10), |
| 130 | + margin: const EdgeInsets.all(Insets.l), |
| 131 | + child: FlashBar( |
| 132 | + content: Text( |
| 133 | + message, |
| 134 | + style: const TextStyle(fontSize: 14.0, color: Colors.white), |
| 135 | + ), |
| 136 | + icon: Icon( |
| 137 | + icon, |
| 138 | + color: iconColor, |
| 139 | + size: 28, |
| 140 | + ), |
| 141 | + ), |
| 142 | + ); |
| 143 | + }, |
| 144 | + ); |
| 145 | + } |
| 146 | + |
| 147 | + /// Shows a success flashbar/toast with a customizable text. |
| 148 | + /// |
| 149 | + /// It uses [flash](https://pub.dev/packages/flash). |
| 150 | + void showSuccessFlashbar({ |
| 151 | + required String message, |
| 152 | + int duration = 3, |
| 153 | + }) { |
| 154 | + _showFlashbar( |
| 155 | + message, |
| 156 | + duration: duration, |
| 157 | + icon: Icons.check_rounded, |
| 158 | + iconColor: Colors.green[400]!, |
| 159 | + ); |
| 160 | + } |
| 161 | + |
| 162 | + /// Shows an info flashbar/toast with a customizable text. |
| 163 | + /// |
| 164 | + /// It uses [flash](https://pub.dev/packages/flash). |
| 165 | + void showInfoFlashbar({ |
| 166 | + required String message, |
| 167 | + int duration = 3, |
| 168 | + }) { |
| 169 | + _showFlashbar( |
| 170 | + message, |
| 171 | + duration: duration, |
| 172 | + icon: Icons.info_outline_rounded, |
| 173 | + iconColor: Colors.blue[400]!, |
| 174 | + ); |
| 175 | + } |
| 176 | + |
| 177 | + /// Shows an error flashbar/toast with a customizable text (optional). |
| 178 | + /// |
| 179 | + /// It uses [flash](https://pub.dev/packages/flash). |
| 180 | + void showErrorFlashbar({ |
| 181 | + String message = 'Oops, something went wrong.', |
| 182 | + int duration = 3, |
| 183 | + }) { |
| 184 | + _showFlashbar( |
| 185 | + message, |
| 186 | + duration: duration, |
| 187 | + icon: Icons.error_outline_rounded, |
| 188 | + iconColor: Colors.red[400]!, |
| 189 | + ); |
| 190 | + } |
| 191 | + |
| 192 | + /// Shows a no connection flashbar/toast with a customizable text (optional). |
| 193 | + /// |
| 194 | + /// It uses [flash](https://pub.dev/packages/flash). |
| 195 | + void showNoConnectionFlashbar({ |
| 196 | + String message = |
| 197 | + 'A connection to the server cannot be established. Are you connected to the internet?', |
| 198 | + int duration = 3, |
| 199 | + }) { |
| 200 | + _showFlashbar( |
| 201 | + message, |
| 202 | + duration: duration, |
| 203 | + icon: Icons.wifi_off_rounded, |
| 204 | + iconColor: Colors.red[400]!, |
| 205 | + ); |
| 206 | + } |
| 207 | +} |
0 commit comments