https://github.com/vantuan88291/flutter_dropdown_alert
Flutter Dropdown Alert help to notify to user when success, warning or error like in app push notification
https://github.com/vantuan88291/flutter_dropdown_alert
alert dropdown flutter local-push-notifications notification push-notification widget
Last synced: 4 months ago
JSON representation
Flutter Dropdown Alert help to notify to user when success, warning or error like in app push notification
- Host: GitHub
- URL: https://github.com/vantuan88291/flutter_dropdown_alert
- Owner: vantuan88291
- License: mit
- Created: 2021-03-02T07:18:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T06:31:19.000Z (over 3 years ago)
- Last Synced: 2023-08-20T21:58:02.636Z (almost 3 years ago)
- Topics: alert, dropdown, flutter, local-push-notifications, notification, push-notification, widget
- Language: Dart
- Homepage:
- Size: 284 KB
- Stars: 13
- Watchers: 3
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dartlang.org/packages/flutter_dropdown_alert)
# flutter_dropdown_alert
A dropdown alert package for flutter
Dropdown alert will help to notify to user when you call api success, error or something like that, such as in app notification. It's will similar with push notification but you can custom more than that. You can show alert at anywhere without widget.
## Demo
### Top:

### Bottom:

## How to use it.
```yaml
# pubspec.yaml
dependencies:
flutter:
sdk: flutter
flutter_dropdown_alert:
```
Just create a `Stack` widget and add `DropdownAlert()` inside `MaterialApp` which should be in main.dart like this:
```dart
import 'package:flutter_dropdown_alert/dropdown_alert.dart';
```
```dart
MaterialApp(
title: 'Dropdown Alert Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
builder: (context, child) => Stack(
children: [
child!,
DropdownAlert()
],
),
home: MyHomePage(title: 'Flutter Dropdown Alert Demo'),
);
```
## Full example source code:
https://github.com/vantuan88291/flutter_bloc_modular
## Show alert anywhere, even inside bloc without widget:
Next, import 'alert_controller.dart' into your dart code
```dart
import 'package:flutter_dropdown_alert/alert_controller.dart';
```
```dart
AlertController.show("Title", "message here!", TypeAlert.success, payload);
```
The `payload` param is `Map`, this param is optional, should use to give data into the alert and get it when click on alert.
## Hide alert:
The alert will automatically hide, but if you use `delayDismiss: 0`, it will freeze and not auto hide, you have to hide the alert by this code:
```dart
AlertController.hide();
```
## Listener when click on alert:
There are 2 ways to do that:
- Using listener of controller, put this code inside `initState()` of widget:
```dart
AlertController.onTabListener((Map? payload, TypeAlert type) {
print("$payload - $type");
});
```
- Using param `onTap`:
```dart
DropdownAlert(onTap: (Map payload?, TypeAlert type) {
print("$payload - $type");
},)
```
## TypeAlert
| Type | description |
| -------------------------- | ------------------------------------------------------------------------------------- |
| TypeAlert.success | Type when action success, the background of alert will green |
| TypeAlert.warning | Type when action warning, the background of alert will brown |
| TypeAlert.error | Type when action error, the background of alert will red |
## parameters
| parameter | description | default |
| -------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| onTap | Callback when tab to alert, will give: Function(Map, TypeAlert) | null |
| successImage | Image.asset() of success alert, uri of assets image | Icon widget |
| warningImage | Image.asset() of warning alert, uri of assets image | Icon widget |
| errorImage | Image.asset() of error alert, uri of assets image | Icon widget |
| closeImage | Image.asset() of close image, when showCloseButton is true | Icon widget |
| errorBackground | Color of background when error | Colors.red |
| successBackground | | Colors.green |
| warningBackground | | 0xFFCE863D |
| titleStyle | TextStyle of title | |
| contentStyle | TextStyle of content | |
| maxLinesTitle | | null |
| maxLinesContent | | null |
| duration | duration of animation | 300 |
| delayDismiss | delay time when alert auto dismiss, set to 0 if you want to freeze alert | 3000 |
| position | show the position of alert, include: AlertPosition.TOP, AlertPosition.BOTTOM | AlertPosition.TOP |
| showCloseButton | When close button is present, only can click on button close to hide the alert | false |
| avoidBottomInset | Add optional variable for inset overlap | false |
`The ideal from react-native-dropdownalert`