Skip to content

Commit

Permalink
🚀 More text fields for showToast (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Sep 7, 2022
1 parent b7dd446 commit 4f4c822
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.3.0

- Abstract `BuildContextPredicate`. (#95)
- More text fields for `showToast`. (#96)

## 3.2.0

Expand Down
30 changes: 21 additions & 9 deletions lib/src/core/toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,37 @@ ToastFuture showToast(
BuildContextPredicate buildContextPredicate = _defaultContextPredicate,
Duration? duration,
ToastPosition? position,
TextStyle? textStyle,
EdgeInsetsGeometry? textPadding,
Color? backgroundColor,
double? radius,
VoidCallback? onDismiss,
TextDirection? textDirection,
bool? dismissOtherToast,
TextAlign? textAlign,
OKToastAnimationBuilder? animationBuilder,
Duration? animationDuration,
Curve? animationCurve,
BoxConstraints? constraints,
EdgeInsetsGeometry? margin = const EdgeInsets.all(50),
TextDirection? textDirection,
EdgeInsetsGeometry? textPadding,
TextAlign? textAlign,
TextStyle? textStyle,
int? textMaxLines,
TextOverflow? textOverflow,
}) {
if (context == null) {
_throwIfNoContext(_contextMap.values, 'showToast');
}
context ??= buildContextPredicate(_contextMap.values);

final ToastTheme theme = ToastTheme.of(context);
textStyle ??= theme.textStyle;
textAlign ??= theme.textAlign;
textPadding ??= theme.textPadding;
position ??= theme.position;
backgroundColor ??= theme.backgroundColor;
radius ??= theme.radius;
textDirection ??= theme.textDirection;
textPadding ??= theme.textPadding;
textAlign ??= theme.textAlign;
textStyle ??= theme.textStyle;
textMaxLines ??= theme.textMaxLines;
textOverflow ??= theme.textOverflow;

final Widget widget = Container(
constraints: constraints,
Expand All @@ -75,7 +79,15 @@ ToastFuture showToast(
borderRadius: BorderRadius.circular(radius),
color: backgroundColor,
),
child: ClipRect(child: Text(msg, style: textStyle, textAlign: textAlign)),
child: ClipRect(
child: Text(
msg,
style: textStyle,
textAlign: textAlign,
maxLines: textMaxLines,
overflow: textOverflow,
),
),
);

return showToastWidget(
Expand All @@ -93,7 +105,7 @@ ToastFuture showToast(
);
}

/// Show [widget] with oktoast.
/// Show a [widget] and returns a [ToastFuture].
ToastFuture showToastWidget(
Widget widget, {
BuildContext? context,
Expand Down
16 changes: 10 additions & 6 deletions lib/src/widget/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ class ToastTheme extends InheritedWidget {
this.duration = _defaultDuration,
this.textPadding,
this.textAlign,
this.textMaxLines,
this.textOverflow,
});

static ToastTheme of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ToastTheme>() ?? defaultTheme;

final TextStyle textStyle;
final Color backgroundColor;
final TextDirection textDirection;
final bool handleTouch;
final double radius;
final ToastPosition position;
final Color backgroundColor;
final bool dismissOtherOnShow;
final bool movingOnWindowChange;
final TextDirection textDirection;
final EdgeInsets? textPadding;
final TextAlign? textAlign;
final bool handleTouch;
final OKToastAnimationBuilder animationBuilder;
final Duration animationDuration;
final Curve animationCurve;
final Duration duration;
final TextAlign? textAlign;
final EdgeInsets? textPadding;
final int? textMaxLines;
final TextOverflow? textOverflow;

@override
bool updateShouldNotify(InheritedWidget oldWidget) => true;
bool updateShouldNotify(ToastTheme oldWidget) => true;
}

0 comments on commit 4f4c822

Please sign in to comment.