Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SnackBar style notifications #39

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.0.3] - 20202/3/13
* expose toastTheme. by [juvs](https://github.com/juvs)

## [1.0.2] - 2019/10/23

* fix Toast hidden behind ime #20
Expand Down
1 change: 1 addition & 0 deletions lib/overlay_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'src/notification/overlay_notification.dart';
export 'src/notification/notification.dart';
export 'src/overlay.dart';
export 'src/toast/toast.dart';
export 'src/theme.dart';

///The length of time the notification is fully displayed
Duration kNotificationDuration = const Duration(milliseconds: 2000);
Expand Down
22 changes: 21 additions & 1 deletion lib/src/notification/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,27 @@ class TopSlideNotification extends StatelessWidget {
}
}

/// Can be dismiss by left or right slide.
/// a notification show in front of screen and shown at the bottom
class BottomSlideNotification extends StatelessWidget {
///build notification content
final WidgetBuilder builder;

final Animation<double> animation;

const BottomSlideNotification({Key key, @required this.builder, this.animation}) : super(key: key);

@override
Widget build(BuildContext context) {
return SlideTransition(
position: Tween<Offset>(begin: const Offset(0, 1), end: const Offset(0, 0))
.chain(CurveTween(curve: Curves.ease))
.animate(animation),
child: builder(context),
);
}
}

/// Can be dismiss by left or right slide
class SlideDismissible extends StatelessWidget {
final Widget child;

Expand Down
16 changes: 13 additions & 3 deletions lib/src/notification/overlay_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ import 'package:overlay_support/src/overlay.dart';
///if null , will be set to [kNotificationDuration]
///if zero , will not auto dismiss in the future
///
/// [showAtBottom] show notification at the bottom of screen like a SnackBar
///
OverlaySupportEntry showOverlayNotification(
WidgetBuilder builder, {
Duration duration,
Key key,
bool showAtBottom = false,
}) {
if (duration == null) {
duration = kNotificationDuration;
}
return showOverlay((context, animation) {
MainAxisAlignment alignment = MainAxisAlignment.start;
if (showAtBottom) alignment = MainAxisAlignment.end;
return Column(
mainAxisAlignment: alignment,
children: <Widget>[
TopSlideNotification(builder: builder, animation: animation),
!showAtBottom
? TopSlideNotification(builder: builder, animation: animation)
: BottomSlideNotification(builder: builder, animation: animation)
],
);
}, duration: duration, key: key);
Expand All @@ -42,6 +50,7 @@ OverlaySupportEntry showOverlayNotification(
/// [elevation] the elevation of notification, see more [Material.elevation]
/// [autoDismiss] true to auto hide after duration [kNotificationDuration]
/// [slideDismiss] support left/right to dismiss notification
/// [isSnackBar] support for SnackBar style notification, which displays at bottom of screen
///
OverlaySupportEntry showSimpleNotification(Widget content,
{Widget leading,
Expand All @@ -53,7 +62,8 @@ OverlaySupportEntry showSimpleNotification(Widget content,
double elevation = 16,
Key key,
bool autoDismiss = true,
bool slideDismiss = false}) {
bool slideDismiss = false,
bool isSnackBar = false}) {
final entry = showOverlayNotification((context) {
return SlideDismissible(
enable: slideDismiss,
Expand All @@ -76,6 +86,6 @@ OverlaySupportEntry showSimpleNotification(Widget content,
)),
),
);
}, duration: autoDismiss ? null : Duration.zero, key: key);
}, duration: autoDismiss ? null : Duration.zero, key: key, showAtBottom: isSnackBar);
return entry;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: overlay_support
description: proivder support for overlay, easy to build toast and internal notification
version: 1.0.2
version: 1.0.3
author: YangBin <[email protected]>
homepage: https://github.com/boyan01/overlay_support

Expand Down