Skip to content

Commit

Permalink
Merge pull request #92 from MMMzq/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MMMzq authored Nov 4, 2020
2 parents c53079e + 7e7eb8a commit c028162
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.0.5]
* fix: cancel the use of `nullOk` attribute

* feat: optimize `toast` display sequence logic

* feat: add options for users to style titles

## [3.0.4]
* fix:  The bug that `ProxyDispose.disposeCallback` callback cannot be triggered

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Loading|Text|CustomWidget
#### 1. add dependencies into you project pubspec.yaml file
``` dart
dependencies:
bot_toast: ^3.0.4
bot_toast: ^3.0.5
```

#### 2. import BotToast lib
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Loading|Text|CustomWidget
#### 1. pubspec.yaml文件里添加依赖
``` dart
dependencies:
bot_toast: ^3.0.4
bot_toast: ^3.0.5
```

#### 2. 导入BotToast库
Expand Down
30 changes: 25 additions & 5 deletions lib/src/bot_toast_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,31 @@ class BotToastManager extends StatefulWidget {
BotToastManagerState createState() => BotToastManagerState();
}

class _IndexWidget extends StatelessWidget {
final Widget child;

final int index;

const _IndexWidget({Key key, this.child, this.index}) : super(key: key);

@override
Widget build(BuildContext context) {
return child;
}
}

class BotToastManagerState extends State<BotToastManager> {
final Map<String, Map<UniqueKey, Widget>> _map = {};
final Map<String, Map<UniqueKey, _IndexWidget>> _map = {};

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

List<Widget> get _children => _map.values.fold([], (value, items) {
int _nextAddIndex = 0;

List<_IndexWidget> get _children =>
_map.values.fold<List<_IndexWidget>>(<_IndexWidget>[], (value, items) {
return value..addAll(items.values);
});
})
..sort((a, b) => a.index.compareTo(b.index));

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

widget = ProxyDispose(
key: uniqueKey,
child: widget,
disposeCallback: () {
_map[groupKey]?.remove(key);
},
);
_map[groupKey][key] = widget;
_map[groupKey][key] = _IndexWidget(
key: uniqueKey,
index: ++_nextAddIndex,
child: widget,
);
_pending.add(key);
_update();
});
Expand Down
5 changes: 2 additions & 3 deletions lib/src/keyboard_safe_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class KeyboardSafeArea extends StatelessWidget {
if (!enable) {
return child;
}
MediaQueryData data = MediaQuery.of(context, nullOk: true);
MediaQueryData data = MediaQuery.of(context);
return Padding(
padding: EdgeInsets.only(
bottom: (data != null ? data.viewInsets.bottom : 0.0)),
padding: EdgeInsets.only(bottom: data.viewInsets.bottom),
child: child,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class BotToast {
title: (_) => Text(title, style: titleStyle),
subtitle: subTitle == null
? null
: (_) => Text(subTitle, style: subTitleStyle ?? titleStyle),
: (_) => Text(subTitle, style: subTitleStyle),
trailing: hideCloseButton
? null
: (cancel) => IconButton(
Expand Down
8 changes: 4 additions & 4 deletions lib/src/toast_widget/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Widget textAnimation(
child: child,
);

Widget loadingAnimation(AnimationController controller, CancelFunc cancelFunc,
Widget child) =>
Widget loadingAnimation(
AnimationController controller, CancelFunc cancelFunc, Widget child) =>
FadeAnimation(
controller: controller,
child: child,
);

Widget attachedAnimation(AnimationController controller, CancelFunc cancelFunc,
Widget child) =>
Widget attachedAnimation(
AnimationController controller, CancelFunc cancelFunc, Widget child) =>
FadeAnimation(
controller: controller,
child: child,
Expand Down
16 changes: 12 additions & 4 deletions lib/src/toast_widget/attached.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ Offset positionToastBox(
case "Left":
direction += canPlaceRight(extraSpace: targetRect.width)
? "Left"
: canPlaceLeft(extraSpace: targetRect.width) ? "Right" : "Center";
: canPlaceLeft(extraSpace: targetRect.width)
? "Right"
: "Center";
break;
case "Center":
direction += "Center";
break;
case "Right":
direction += canPlaceLeft(extraSpace: targetRect.width)
? "Right"
: canPlaceRight(extraSpace: targetRect.width) ? "Left" : "Center";
: canPlaceRight(extraSpace: targetRect.width)
? "Left"
: "Center";
break;
}
} else {
Expand All @@ -135,15 +139,19 @@ Offset positionToastBox(
case "Top":
direction += canPlaceBottom(extraSpace: targetRect.height)
? "Top"
: canPlaceTop(extraSpace: targetRect.height) ? "Bottom" : "Center";
: canPlaceTop(extraSpace: targetRect.height)
? "Bottom"
: "Center";
break;
case "Center":
direction += "Center";
break;
case "Bottom":
direction += canPlaceTop(extraSpace: targetRect.height)
? "Bottom"
: canPlaceBottom(extraSpace: targetRect.height) ? "Top" : "Center";
: canPlaceBottom(extraSpace: targetRect.height)
? "Top"
: "Center";
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A really easy to use flutter toast library.Easy to use and feature
homepage: https://github.com/MMMzq/bot_toast
email: [email protected]

version: 3.0.4
version: 3.0.5

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down

0 comments on commit c028162

Please sign in to comment.