| 1 | import 'package:another_flushbar/flushbar.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | |
| 4 | Future<T?> showBar<T>(BuildContext context, String messageText, |
| 5 | {bool isDark = false, |
| 6 | Duration? duration = |
| 7 | const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite |
| 8 | bool isDismissible = true, |
| 9 | String? titleText}) async { |
| 10 | final bar = Flushbar<T>( |
| 11 | boxShadows: [ |
| 12 | BoxShadow( |
| 13 | color: Theme.of(context).colorScheme.surface, |
| 14 | blurRadius: 8, |
| 15 | offset: Offset(0, 2), |
| 16 | ) |
| 17 | ], |
| 18 | backgroundColor: Theme.of(context).colorScheme.surfaceContainer, |
| 19 | borderRadius: BorderRadius.circular(35), |
| 20 | margin: EdgeInsets.all(50), |
| 21 | titleText: titleText != null |
| 22 | ? Text( |
| 23 | titleText, |
| 24 | textAlign: TextAlign.center, |
| 25 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 26 | fontWeight: FontWeight.bold, |
| 27 | fontSize: 24.0, |
| 28 | ), |
| 29 | ) |
| 30 | : null, |
| 31 | messageText: Text( |
| 32 | messageText, |
| 33 | textAlign: TextAlign.center, |
| 34 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 35 | fontSize: 16, |
| 36 | ), |
| 37 | ), |
| 38 | duration: duration, |
| 39 | isDismissible: isDismissible, |
| 40 | flushbarPosition: FlushbarPosition.TOP, |
| 41 | flushbarStyle: FlushbarStyle.FLOATING, |
| 42 | ); |
| 43 | |
| 44 | return bar.show(context); |
| 45 | } |
| 46 | |
| 47 | Flushbar<T> createBar<T>( |
| 48 | String text, |
| 49 | BuildContext context, { |
| 50 | bool isDark = false, |
| 51 | Duration? duration = |
| 52 | const Duration(seconds: 1), // pass explicitly by null to make the duration indefinite |
| 53 | bool isDismissible = true, |
| 54 | }) { |
| 55 | return Flushbar<T>( |
| 56 | boxShadows: [ |
| 57 | BoxShadow( |
| 58 | color: Theme.of(context).colorScheme.surface, |
| 59 | blurRadius: 8, |
| 60 | offset: Offset(0, 2), |
| 61 | ) |
| 62 | ], |
| 63 | backgroundColor: Theme.of(context).colorScheme.surfaceContainer, |
| 64 | borderRadius: BorderRadius.circular(35), |
| 65 | margin: EdgeInsets.all(50), |
| 66 | messageText: Text( |
| 67 | text, |
| 68 | textAlign: TextAlign.center, |
| 69 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 70 | color: Theme.of(context).colorScheme.onSurface, |
| 71 | ), |
| 72 | ), |
| 73 | duration: duration, |
| 74 | isDismissible: isDismissible, |
| 75 | flushbarPosition: FlushbarPosition.TOP, |
| 76 | flushbarStyle: FlushbarStyle.FLOATING, |
| 77 | ); |
| 78 | } |