Skip to content

Commit 4f4c822

Browse files
authored
🚀 More text fields for showToast (#96)
1 parent b7dd446 commit 4f4c822

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.3.0
44

55
- Abstract `BuildContextPredicate`. (#95)
6+
- More text fields for `showToast`. (#96)
67

78
## 3.2.0
89

‎lib/src/core/toast.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,37 @@ ToastFuture showToast(
3939
BuildContextPredicate buildContextPredicate = _defaultContextPredicate,
4040
Duration? duration,
4141
ToastPosition? position,
42-
TextStyle? textStyle,
43-
EdgeInsetsGeometry? textPadding,
4442
Color? backgroundColor,
4543
double? radius,
4644
VoidCallback? onDismiss,
47-
TextDirection? textDirection,
4845
bool? dismissOtherToast,
49-
TextAlign? textAlign,
5046
OKToastAnimationBuilder? animationBuilder,
5147
Duration? animationDuration,
5248
Curve? animationCurve,
5349
BoxConstraints? constraints,
5450
EdgeInsetsGeometry? margin = const EdgeInsets.all(50),
51+
TextDirection? textDirection,
52+
EdgeInsetsGeometry? textPadding,
53+
TextAlign? textAlign,
54+
TextStyle? textStyle,
55+
int? textMaxLines,
56+
TextOverflow? textOverflow,
5557
}) {
5658
if (context == null) {
5759
_throwIfNoContext(_contextMap.values, 'showToast');
5860
}
5961
context ??= buildContextPredicate(_contextMap.values);
6062

6163
final ToastTheme theme = ToastTheme.of(context);
62-
textStyle ??= theme.textStyle;
63-
textAlign ??= theme.textAlign;
64-
textPadding ??= theme.textPadding;
6564
position ??= theme.position;
6665
backgroundColor ??= theme.backgroundColor;
6766
radius ??= theme.radius;
6867
textDirection ??= theme.textDirection;
68+
textPadding ??= theme.textPadding;
69+
textAlign ??= theme.textAlign;
70+
textStyle ??= theme.textStyle;
71+
textMaxLines ??= theme.textMaxLines;
72+
textOverflow ??= theme.textOverflow;
6973

7074
final Widget widget = Container(
7175
constraints: constraints,
@@ -75,7 +79,15 @@ ToastFuture showToast(
7579
borderRadius: BorderRadius.circular(radius),
7680
color: backgroundColor,
7781
),
78-
child: ClipRect(child: Text(msg, style: textStyle, textAlign: textAlign)),
82+
child: ClipRect(
83+
child: Text(
84+
msg,
85+
style: textStyle,
86+
textAlign: textAlign,
87+
maxLines: textMaxLines,
88+
overflow: textOverflow,
89+
),
90+
),
7991
);
8092

8193
return showToastWidget(
@@ -93,7 +105,7 @@ ToastFuture showToast(
93105
);
94106
}
95107

96-
/// Show [widget] with oktoast.
108+
/// Show a [widget] and returns a [ToastFuture].
97109
ToastFuture showToastWidget(
98110
Widget widget, {
99111
BuildContext? context,

‎lib/src/widget/theme.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ class ToastTheme extends InheritedWidget {
1818
this.duration = _defaultDuration,
1919
this.textPadding,
2020
this.textAlign,
21+
this.textMaxLines,
22+
this.textOverflow,
2123
});
2224

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

2628
final TextStyle textStyle;
27-
final Color backgroundColor;
29+
final TextDirection textDirection;
30+
final bool handleTouch;
2831
final double radius;
2932
final ToastPosition position;
33+
final Color backgroundColor;
3034
final bool dismissOtherOnShow;
3135
final bool movingOnWindowChange;
32-
final TextDirection textDirection;
33-
final EdgeInsets? textPadding;
34-
final TextAlign? textAlign;
35-
final bool handleTouch;
3636
final OKToastAnimationBuilder animationBuilder;
3737
final Duration animationDuration;
3838
final Curve animationCurve;
3939
final Duration duration;
40+
final TextAlign? textAlign;
41+
final EdgeInsets? textPadding;
42+
final int? textMaxLines;
43+
final TextOverflow? textOverflow;
4044

4145
@override
42-
bool updateShouldNotify(InheritedWidget oldWidget) => true;
46+
bool updateShouldNotify(ToastTheme oldWidget) => true;
4347
}

0 commit comments

Comments
 (0)