From 7f4c356739a3760b33789985079238f87be5d5e7 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 7 Sep 2022 14:32:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=80=20More=20fields=20for=20`showT?= =?UTF-8?q?oast`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/core/toast.dart | 30 +++++++++++++++++++++--------- lib/src/widget/theme.dart | 16 ++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/src/core/toast.dart b/lib/src/core/toast.dart index 66524b7..0cd7a32 100644 --- a/lib/src/core/toast.dart +++ b/lib/src/core/toast.dart @@ -30,19 +30,21 @@ ToastFuture showToast( BuildContext? context, 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'); @@ -50,13 +52,15 @@ ToastFuture showToast( context ??= _contextMap.values.first; 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, @@ -66,7 +70,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( @@ -83,7 +95,7 @@ ToastFuture showToast( ); } -/// Show [widget] with oktoast. +/// Show a [widget] and returns a [ToastFuture]. ToastFuture showToastWidget( Widget widget, { BuildContext? context, diff --git a/lib/src/widget/theme.dart b/lib/src/widget/theme.dart index 307f64c..3555e20 100644 --- a/lib/src/widget/theme.dart +++ b/lib/src/widget/theme.dart @@ -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() ?? 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; } From 36ed2f8592197fd5a373f319243671f5e56a5d83 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 7 Sep 2022 15:21:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a73fefd..1547b94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 3.3.0 - Abstract `BuildContextPredicate`. (#95) +- More text fields for `showToast`. (#96) ## 3.2.0