Skip to content

Commit c028162

Browse files
authored
Merge pull request #92 from MMMzq/dev
Dev
2 parents c53079e + 7e7eb8a commit c028162

File tree

9 files changed

+54
-20
lines changed

9 files changed

+54
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [3.0.5]
2+
* fix: cancel the use of `nullOk` attribute
3+
4+
* feat: optimize `toast` display sequence logic
5+
6+
* feat: add options for users to style titles
7+
18
## [3.0.4]
29
* fix:  The bug that `ProxyDispose.disposeCallback` callback cannot be triggered
310

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Loading|Text|CustomWidget
5151
#### 1. add dependencies into you project pubspec.yaml file
5252
``` dart
5353
dependencies:
54-
bot_toast: ^3.0.4
54+
bot_toast: ^3.0.5
5555
```
5656

5757
#### 2. import BotToast lib

README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Loading|Text|CustomWidget
5555
#### 1. pubspec.yaml文件里添加依赖
5656
``` dart
5757
dependencies:
58-
bot_toast: ^3.0.4
58+
bot_toast: ^3.0.5
5959
```
6060

6161
#### 2. 导入BotToast库

lib/src/bot_toast_manager.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,31 @@ class BotToastManager extends StatefulWidget {
1818
BotToastManagerState createState() => BotToastManagerState();
1919
}
2020

21+
class _IndexWidget extends StatelessWidget {
22+
final Widget child;
23+
24+
final int index;
25+
26+
const _IndexWidget({Key key, this.child, this.index}) : super(key: key);
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return child;
31+
}
32+
}
33+
2134
class BotToastManagerState extends State<BotToastManager> {
22-
final Map<String, Map<UniqueKey, Widget>> _map = {};
35+
final Map<String, Map<UniqueKey, _IndexWidget>> _map = {};
2336

2437
final Set<UniqueKey> _pending = Set<UniqueKey>();
2538

26-
List<Widget> get _children => _map.values.fold([], (value, items) {
39+
int _nextAddIndex = 0;
40+
41+
List<_IndexWidget> get _children =>
42+
_map.values.fold<List<_IndexWidget>>(<_IndexWidget>[], (value, items) {
2743
return value..addAll(items.values);
28-
});
44+
})
45+
..sort((a, b) => a.index.compareTo(b.index));
2946

3047
void insert(String groupKey, UniqueKey key, Widget widget) {
3148
safeRun(() {
@@ -40,13 +57,16 @@ class BotToastManagerState extends State<BotToastManager> {
4057
);
4158

4259
widget = ProxyDispose(
43-
key: uniqueKey,
4460
child: widget,
4561
disposeCallback: () {
4662
_map[groupKey]?.remove(key);
4763
},
4864
);
49-
_map[groupKey][key] = widget;
65+
_map[groupKey][key] = _IndexWidget(
66+
key: uniqueKey,
67+
index: ++_nextAddIndex,
68+
child: widget,
69+
);
5070
_pending.add(key);
5171
_update();
5272
});

lib/src/keyboard_safe_area.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ class KeyboardSafeArea extends StatelessWidget {
1313
if (!enable) {
1414
return child;
1515
}
16-
MediaQueryData data = MediaQuery.of(context, nullOk: true);
16+
MediaQueryData data = MediaQuery.of(context);
1717
return Padding(
18-
padding: EdgeInsets.only(
19-
bottom: (data != null ? data.viewInsets.bottom : 0.0)),
18+
padding: EdgeInsets.only(bottom: data.viewInsets.bottom),
2019
child: child,
2120
);
2221
}

lib/src/toast.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class BotToast {
114114
title: (_) => Text(title, style: titleStyle),
115115
subtitle: subTitle == null
116116
? null
117-
: (_) => Text(subTitle, style: subTitleStyle ?? titleStyle),
117+
: (_) => Text(subTitle, style: subTitleStyle),
118118
trailing: hideCloseButton
119119
? null
120120
: (cancel) => IconButton(

lib/src/toast_widget/animation.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Widget textAnimation(
1616
child: child,
1717
);
1818

19-
Widget loadingAnimation(AnimationController controller, CancelFunc cancelFunc,
20-
Widget child) =>
19+
Widget loadingAnimation(
20+
AnimationController controller, CancelFunc cancelFunc, Widget child) =>
2121
FadeAnimation(
2222
controller: controller,
2323
child: child,
2424
);
2525

26-
Widget attachedAnimation(AnimationController controller, CancelFunc cancelFunc,
27-
Widget child) =>
26+
Widget attachedAnimation(
27+
AnimationController controller, CancelFunc cancelFunc, Widget child) =>
2828
FadeAnimation(
2929
controller: controller,
3030
child: child,

lib/src/toast_widget/attached.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@ Offset positionToastBox(
117117
case "Left":
118118
direction += canPlaceRight(extraSpace: targetRect.width)
119119
? "Left"
120-
: canPlaceLeft(extraSpace: targetRect.width) ? "Right" : "Center";
120+
: canPlaceLeft(extraSpace: targetRect.width)
121+
? "Right"
122+
: "Center";
121123
break;
122124
case "Center":
123125
direction += "Center";
124126
break;
125127
case "Right":
126128
direction += canPlaceLeft(extraSpace: targetRect.width)
127129
? "Right"
128-
: canPlaceRight(extraSpace: targetRect.width) ? "Left" : "Center";
130+
: canPlaceRight(extraSpace: targetRect.width)
131+
? "Left"
132+
: "Center";
129133
break;
130134
}
131135
} else {
@@ -135,15 +139,19 @@ Offset positionToastBox(
135139
case "Top":
136140
direction += canPlaceBottom(extraSpace: targetRect.height)
137141
? "Top"
138-
: canPlaceTop(extraSpace: targetRect.height) ? "Bottom" : "Center";
142+
: canPlaceTop(extraSpace: targetRect.height)
143+
? "Bottom"
144+
: "Center";
139145
break;
140146
case "Center":
141147
direction += "Center";
142148
break;
143149
case "Bottom":
144150
direction += canPlaceTop(extraSpace: targetRect.height)
145151
? "Bottom"
146-
: canPlaceBottom(extraSpace: targetRect.height) ? "Top" : "Center";
152+
: canPlaceBottom(extraSpace: targetRect.height)
153+
? "Top"
154+
: "Center";
147155
break;
148156
}
149157
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A really easy to use flutter toast library.Easy to use and feature
33
homepage: https://github.com/MMMzq/bot_toast
44
email: vivask770@163.com
55

6-
version: 3.0.4
6+
version: 3.0.5
77

88
environment:
99
sdk: ">=2.1.0 <3.0.0"

0 commit comments

Comments
 (0)