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

Add extra bottom margin to account for keyboard #131

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion example/lib/src/features/home/views/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _HomeScreenState extends State<HomeScreen> {
Widget build(BuildContext context) {
return ToastificationConfigProvider(
config: ToastificationConfig(
marginBuilder: (alignment) => const EdgeInsets.fromLTRB(0, 16, 0, 110),
marginBuilder: (context, alignment) => const EdgeInsets.fromLTRB(0, 16, 0, 110),
MrLightful marked this conversation as resolved.
Show resolved Hide resolved
),
child: const Scrollbar(
child: Scaffold(
Expand Down
15 changes: 7 additions & 8 deletions lib/src/core/toastification_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const _itemAnimationDuration = Duration(milliseconds: 600);
const _defaultWidth = 400.0;
const _defaultClipBehavior = Clip.none;


/// you can use [ToastificationConfig] class to change default values of [Toastification]
///
/// when you are using [show] or [showCustom] methods,
Expand Down Expand Up @@ -36,7 +37,7 @@ class ToastificationConfig extends Equatable {
final Clip clipBehavior;
final Duration animationDuration;
final ToastificationAnimationBuilder animationBuilder;
final EdgeInsetsGeometry Function(AlignmentGeometry alignment) marginBuilder;
final EdgeInsetsGeometry Function(BuildContext context, AlignmentGeometry alignment) marginBuilder;

// Copy with method for ToastificationConfig
ToastificationConfig copyWith({
Expand All @@ -45,7 +46,7 @@ class ToastificationConfig extends Equatable {
Clip? clipBehavior,
Duration? animationDuration,
ToastificationAnimationBuilder? animationBuilder,
EdgeInsetsGeometry Function(AlignmentGeometry alignment)? marginBuilder,
EdgeInsetsGeometry Function(BuildContext context, AlignmentGeometry alignment)? marginBuilder,
}) {
return ToastificationConfig(
alignment: alignment ?? this.alignment,
Expand Down Expand Up @@ -81,22 +82,20 @@ Widget _defaultAnimationBuilderConfig(
}

/// Default margin builder for [Toastification]
EdgeInsetsGeometry _defaultMarginBuilder(AlignmentGeometry alignment) {
EdgeInsetsGeometry _defaultMarginBuilder(BuildContext context, AlignmentGeometry alignment) {
final y = alignment is Alignment
? alignment.y
: alignment is AlignmentDirectional
? alignment.y
: 0.0;
MrLightful marked this conversation as resolved.
Show resolved Hide resolved
Alignment.topCenter;
final kbdBottomMargin = MediaQuery.of(context).viewInsets.bottom;

log('Margin builder called with y: $y');
log('Margin builder called with alignment: $alignment');

return switch (y) {
>= -1 => const EdgeInsets.only(top: 12),
>= -0.5 => const EdgeInsets.only(top: 12),
<= 0.5 => const EdgeInsets.only(bottom: 12),
<= 1 => const EdgeInsets.only(bottom: 12),
<= -0.5 => const EdgeInsets.only(top: 12),
>= 0.5 => EdgeInsets.only(bottom: 12 + kbdBottomMargin),
MrLightful marked this conversation as resolved.
Show resolved Hide resolved
_ => EdgeInsets.zero,
};
MrLightful marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion lib/src/core/toastification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ToastificationManager {
Widget overlay = Align(
alignment: alignment,
child: Container(
margin: config.marginBuilder(alignment),
margin: config.marginBuilder(context, alignment),
constraints: BoxConstraints.tightFor(
width: config.itemWidth,
),
Expand Down