Skip to content

Commit

Permalink
Merge pull request #59 from SviatManiuk/release/3.1.0
Browse files Browse the repository at this point in the history
Release/3.1.0
  • Loading branch information
vizhan-lanars committed Jun 30, 2023
2 parents 6dbfa07 + 48d25cc commit eed8efe
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 3.1.0 - 30.06.2023
* Enhancement: Add `snackBarPosition` parameter by [fox-avokadik](https://github.com/fox-avokadik)
* Correct errors in the example
* Update README.md

## 3.0.0+1 - 27.12.2022
* Update README.md

Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -17,7 +17,7 @@ but we have a CustomSnackBar for example.

```dart
showTopSnackBar(
context,
Overlay.of(context),
CustomSnackBar.success(
message:
"Good job, your release is successful. Have a nice day",
Expand All @@ -27,7 +27,7 @@ showTopSnackBar(

```dart
showTopSnackBar(
context,
Overlay.of(context),
CustomSnackBar.info(
message:
"There is some information. You need to do something with that",
Expand All @@ -37,7 +37,7 @@ showTopSnackBar(

```dart
showTopSnackBar(
context,
Overlay.of(context),
CustomSnackBar.error(
message:
"Something went wrong. Please check your credentials and try again",
Expand All @@ -52,7 +52,7 @@ AnimationController localAnimationController;
TapBounceContainer(
onTap: () {
showTopSnackBar(
context,
Overlay.of(context),
CustomSnackBar.info(
message: "Persistent SnackBar",
),
Expand Down
Binary file modified example/assets/top-snackbar-example.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Expand Up @@ -8,14 +8,14 @@ void main() {
}

class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);

@override
MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
AnimationController localAnimationController;
late AnimationController localAnimationController;

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Expand Up @@ -19,7 +19,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text && widget.data.startsWith('Running on:'),
widget is Text && (widget.data?.startsWith('Running on:') ?? false),
),
findsOneWidget,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/custom_snack_bar.dart
Expand Up @@ -128,7 +128,7 @@ class CustomSnackBarState extends State<CustomSnackBar> {
padding: widget.messagePadding,
child: Text(
widget.message,
style: theme.textTheme.bodyText2?.merge(widget.textStyle),
style: theme.textTheme.bodyMedium?.merge(widget.textStyle),
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
maxLines: widget.maxLines,
Expand Down
1 change: 1 addition & 0 deletions lib/safe_area_values.dart
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';

/// A data class that is used to pass safe area values for snackbar
class SafeAreaValues {
const SafeAreaValues({
this.left = true,
Expand Down
1 change: 1 addition & 0 deletions lib/tap_bounce_container.dart
Expand Up @@ -17,6 +17,7 @@ class TapBounceContainer extends StatefulWidget {
TapBounceContainerState createState() => TapBounceContainerState();
}

/// State for a [TapBounceContainer].
class TapBounceContainerState extends State<TapBounceContainer>
with SingleTickerProviderStateMixin {
late double _scale;
Expand Down
35 changes: 27 additions & 8 deletions lib/top_snack_bar.dart
Expand Up @@ -6,8 +6,12 @@ import 'package:top_snackbar_flutter/tap_bounce_container.dart';

typedef ControllerCallback = void Function(AnimationController);

/// Represents possible triggers to dismiss the snackbar.
enum DismissType { onTap, onSwipe, none }

/// Represents possible vertical position of snackbar.
enum SnackBarPosition { top, bottom }

OverlayEntry? _previousEntry;

/// The [overlayState] argument is used to add specific overlay state.
Expand Down Expand Up @@ -42,10 +46,13 @@ OverlayEntry? _previousEntry;
/// The [safeAreaValues] argument is used to specify the arguments of the
/// [SafeArea] widget that wrap the snackbar.
///
/// The [dismissType] argument specify which action to trigger to
/// The [dismissType] argument specifies which action to trigger to
/// dismiss the snackbar. Defaults to `TopSnackBarDismissType.onTap`
///
/// The [dismissDirection] argument specify in which direction the snackbar
/// The [snackBarPosition] argument specifies the vertical position of the snackbar.
/// Defaults to [SnackBarPosition.top]
///
/// The [dismissDirection] argument specifies in which direction the snackbar
/// can be dismissed. This argument is only used when [dismissType] is equal
/// to `DismissType.onSwipe`. Defaults to `[DismissDirection.up]`
void showTopSnackBar(
Expand All @@ -62,6 +69,7 @@ void showTopSnackBar(
Curve reverseCurve = Curves.linearToEaseOut,
SafeAreaValues safeAreaValues = const SafeAreaValues(),
DismissType dismissType = DismissType.onTap,
SnackBarPosition snackBarPosition = SnackBarPosition.top,
List<DismissDirection> dismissDirection = const [DismissDirection.up],
}) {
late OverlayEntry _overlayEntry;
Expand All @@ -83,6 +91,7 @@ void showTopSnackBar(
reverseCurve: reverseCurve,
safeAreaValues: safeAreaValues,
dismissType: dismissType,
snackBarPosition: snackBarPosition,
dismissDirections: dismissDirection,
child: child,
);
Expand Down Expand Up @@ -111,6 +120,7 @@ class _TopSnackBar extends StatefulWidget {
required this.reverseCurve,
required this.safeAreaValues,
required this.dismissDirections,
required this.snackBarPosition,
this.onTap,
this.persistent = false,
this.onAnimationControllerInit,
Expand All @@ -131,19 +141,19 @@ class _TopSnackBar extends StatefulWidget {
final SafeAreaValues safeAreaValues;
final DismissType dismissType;
final List<DismissDirection> dismissDirections;
final SnackBarPosition snackBarPosition;

@override
_TopSnackBarState createState() => _TopSnackBarState();
}

class _TopSnackBarState extends State<_TopSnackBar>
with SingleTickerProviderStateMixin {
class _TopSnackBarState extends State<_TopSnackBar> with SingleTickerProviderStateMixin {
late final Animation<Offset> _offsetAnimation;
late final AnimationController _animationController;

Timer? _timer;

final _offsetTween = Tween(begin: const Offset(0, -1), end: Offset.zero);
late final Tween<Offset> _offsetTween;

@override
void initState() {
Expand All @@ -170,6 +180,15 @@ class _TopSnackBarState extends State<_TopSnackBar>

widget.onAnimationControllerInit?.call(_animationController);

switch(widget.snackBarPosition) {
case SnackBarPosition.top:
_offsetTween = Tween<Offset>(begin: const Offset(0, -1), end: Offset.zero);
break;
case SnackBarPosition.bottom:
_offsetTween = Tween<Offset>(begin: const Offset(0, 1), end: Offset.zero);
break;
}

_offsetAnimation = _offsetTween.animate(
CurvedAnimation(
parent: _animationController,
Expand All @@ -193,7 +212,8 @@ class _TopSnackBarState extends State<_TopSnackBar>
@override
Widget build(BuildContext context) {
return Positioned(
top: widget.padding.top,
top: widget.snackBarPosition == SnackBarPosition.top ? widget.padding.top : null,
bottom: widget.snackBarPosition == SnackBarPosition.bottom ? widget.padding.bottom : null,
left: widget.padding.left,
right: widget.padding.right,
child: SlideTransition(
Expand All @@ -204,8 +224,7 @@ class _TopSnackBarState extends State<_TopSnackBar>
left: widget.safeAreaValues.left,
right: widget.safeAreaValues.right,
minimum: widget.safeAreaValues.minimum,
maintainBottomViewPadding:
widget.safeAreaValues.maintainBottomViewPadding,
maintainBottomViewPadding: widget.safeAreaValues.maintainBottomViewPadding,
child: _buildDismissibleChild(),
),
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
@@ -1,10 +1,10 @@
name: top_snackbar_flutter
description: Top snack bar package was created for nice and convenient way to inform users about what happened.
version: 3.0.0+1
version: 3.1.0
homepage: https://github.com/LanarsInc/top-snackbar-flutter

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.15.0 <4.0.0'

dependencies:
flutter:
Expand Down
6 changes: 4 additions & 2 deletions test/top_snackbar_flutter_test.dart
Expand Up @@ -7,12 +7,14 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (message) async {
return '42';
});
});

tearDown(() {
channel.setMockMethodCallHandler(null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});
}

0 comments on commit eed8efe

Please sign in to comment.