Skip to content

Commit 1cae874

Browse files
committed
refactor: Migrate to sound null safety
1 parent c028162 commit 1cae874

19 files changed

+224
-244
lines changed

example/lib/attached_toast/attached_toast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class _AttachedToastState extends State<AttachedToast> {
5151
FlatButton.icon(
5252
padding: EdgeInsets.all(5),
5353
onPressed: (){
54-
BotToast.showSimpleNotification(title: "Let's go travel together.😘");
54+
BotToast.showSimpleNotification(title: "Tap favorite");
5555
},
5656
label: Text("favorite"),
5757
icon: Icon(Icons.favorite,color: Colors.redAccent),
5858
),
5959
FlatButton.icon(
6060
padding: EdgeInsets.all(5),
6161
onPressed: (){
62-
BotToast.showSimpleNotification(title: "Thank you for liking me.😝");
62+
BotToast.showSimpleNotification(title: "Tap bookmark");
6363
},
6464
label: Text("bookmark"),
6565
icon: Icon(Icons.bookmark,color: Colors.redAccent),

example/lib/loading/custom_loading.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class __CustomLoadWidgetState extends State<_CustomLoadWidget>
5959
}),
6060
Padding(
6161
padding: const EdgeInsets.symmetric(horizontal: 8.0),
62-
child: Text("me too"),
62+
child: Text("Tap loading toast"),
6363
)
6464
],
6565
),
@@ -82,8 +82,11 @@ class __CustomLoadWidgetState extends State<_CustomLoadWidget>
8282
onPressed: handleTap,
8383
),
8484
),
85-
Text(
86-
"i miss you",
85+
Padding(
86+
padding: const EdgeInsets.all(8.0),
87+
child: Text(
88+
"Loading",
89+
),
8790
)
8891
],
8992
),

example/lib/notification/notification.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class _NotificationState extends State<Notification> {
3838
icon: Icon(Icons.favorite, color: Colors.redAccent),
3939
onPressed: cancel,
4040
)),
41-
title: (_) => Text('I love u'),
42-
subtitle: (_) => Text("let's be together"),
41+
title: (_) => Text('Notification title'),
42+
subtitle: (_) => Text("Notification subtitle"),
4343
trailing: (cancel) => IconButton(
4444
icon: Icon(Icons.cancel),
4545
onPressed: cancel,

example/lib/notification/simple_notification.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class _SimpleNotificationState extends State<SimpleNotification> {
2020
@override
2121
void initState() {
2222
BotToast.showSimpleNotification(
23-
title: "do you still love me ?",
24-
subTitle: "yes!",
23+
title: "Notification title",
24+
subTitle: "Notification subtitle",
2525
enableSlideOff: enableSlideOff,
2626
hideCloseButton: hideCloseButton,
2727
onTap: () {
@@ -58,8 +58,8 @@ class _SimpleNotificationState extends State<SimpleNotification> {
5858
RaisedButton(
5959
onPressed: () {
6060
BotToast.showSimpleNotification(
61-
title: "do you still love me ?",
62-
subTitle: "yes!",
61+
title: "Notification title",
62+
subTitle: "Notification subtitle",
6363
enableSlideOff: enableSlideOff,
6464
hideCloseButton: hideCloseButton,
6565
onlyOne: onlyOne,

example/lib/text/custom_text.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class _CustomTextState extends State<CustomText> {
5757
),
5858
onPressed: () {
5959
BotToast.showSimpleNotification(
60-
title: "Yes, I do!",
60+
title: "Notification one",
6161
crossPage: crossPage,
6262
closeIcon: Icon(
6363
Icons.favorite,
@@ -68,7 +68,7 @@ class _CustomTextState extends State<CustomText> {
6868
Padding(
6969
padding:
7070
const EdgeInsets.symmetric(horizontal: 8),
71-
child: Text("propose marriage?"),
71+
child: Text("Text one"),
7272
),
7373
],
7474
),

example/lib/text/text.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class _TextSampleState extends State<TextSample> {
4040
RaisedButton(
4141
onPressed: () {
4242
BotToast.showText(
43-
text: (index++).isOdd
44-
? "Always together☺"
45-
: "My mind is all about you.😘",
43+
text: (++index).isOdd
44+
? "Text one"
45+
: "Text two",
4646
duration: Duration(seconds: seconds),
4747
onlyOne: onlyOne,
4848
clickClose: clickClose,

lib/src/bot_toast_init.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import 'bot_toast_manager.dart';
66
final GlobalKey<BotToastManagerState> _key = GlobalKey<BotToastManagerState>();
77

88
BotToastManagerState get botToastManager {
9-
assert(_key?.currentState != null);
10-
return _key.currentState;
9+
assert(_key.currentState != null);
10+
return _key.currentState!;
1111
}
1212

1313
class BotToastWidgetsBindingObserver with WidgetsBindingObserver {
14-
BotToastWidgetsBindingObserver._() {
15-
_listener = <PopTestFunc>[];
16-
WidgetsBinding.instance.addObserver(this);
14+
BotToastWidgetsBindingObserver._() : _listener = <PopTestFunc>[] {
15+
WidgetsBinding.instance!.addObserver(this);
1716
}
1817

19-
List<PopTestFunc> _listener;
18+
final List<PopTestFunc> _listener;
2019

2120
static final BotToastWidgetsBindingObserver _singleton =
2221
BotToastWidgetsBindingObserver._();
@@ -49,7 +48,7 @@ TransitionBuilder BotToastInit() {
4948

5049
//ignore: unnecessary_statements
5150
BotToastWidgetsBindingObserver._singleton;
52-
return (_, Widget child) {
53-
return BotToastManager(key: _key, child: child);
51+
return (_, Widget? child) {
52+
return BotToastManager(key: _key, child: child!);
5453
};
5554
}

lib/src/bot_toast_manager.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import 'package:flutter/material.dart';
33
import 'package:flutter/scheduler.dart';
44

55
void safeRun(void Function() callback) {
6-
SchedulerBinding.instance.addPostFrameCallback((_) {
6+
SchedulerBinding.instance!.addPostFrameCallback((_) {
77
callback();
88
});
9-
SchedulerBinding.instance.ensureVisualUpdate();
9+
SchedulerBinding.instance!.ensureVisualUpdate();
1010
}
1111

1212
class BotToastManager extends StatefulWidget {
1313
final Widget child;
1414

15-
const BotToastManager({Key key, this.child}) : super(key: key);
15+
const BotToastManager({Key? key, required this.child}) : super(key: key);
1616

1717
@override
1818
BotToastManagerState createState() => BotToastManagerState();
@@ -23,7 +23,8 @@ class _IndexWidget extends StatelessWidget {
2323

2424
final int index;
2525

26-
const _IndexWidget({Key key, this.child, this.index}) : super(key: key);
26+
const _IndexWidget({Key? key, required this.child, required this.index})
27+
: super(key: key);
2728

2829
@override
2930
Widget build(BuildContext context) {
@@ -62,7 +63,7 @@ class BotToastManagerState extends State<BotToastManager> {
6263
_map[groupKey]?.remove(key);
6364
},
6465
);
65-
_map[groupKey][key] = _IndexWidget(
66+
_map[groupKey]![key] = _IndexWidget(
6667
key: uniqueKey,
6768
index: ++_nextAddIndex,
6869
child: widget,
@@ -90,14 +91,12 @@ class BotToastManagerState extends State<BotToastManager> {
9091
return;
9192
}
9293

93-
_map[groupKey].removeWhere((key, _) => !_pending.contains(key));
94+
_map[groupKey]!.removeWhere((key, _) => !_pending.contains(key));
9495
_update();
9596

96-
if (_map[groupKey].isNotEmpty) {
97-
_map[groupKey].forEach((key, value) {
98-
return remove(groupKey, key);
99-
});
100-
}
97+
_map[groupKey]!.forEach((key, value) {
98+
return remove(groupKey, key);
99+
});
101100
});
102101
}
103102

lib/src/keyboard_safe_area.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class KeyboardSafeArea extends StatelessWidget {
66

77
final bool enable;
88

9-
const KeyboardSafeArea({Key key, this.child, this.enable}) : super(key: key);
9+
const KeyboardSafeArea({Key? key,required this.child,required this.enable}) : super(key: key);
1010

1111
@override
1212
Widget build(BuildContext context) {

lib/src/keyboard_visibility.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class KeyboardVisibility extends StatefulWidget {
55
final Widget child;
66

77
const KeyboardVisibility(
8-
{@required this.onKeyboardVisibilityChanged,
9-
@required this.child,
10-
Key key})
8+
{required this.onKeyboardVisibilityChanged,
9+
required this.child,
10+
Key? key})
1111
: super(key: key);
1212

1313
@override
@@ -18,7 +18,7 @@ class _KeyboardVisibilityState extends State<KeyboardVisibility>
1818
with WidgetsBindingObserver {
1919
@override
2020
void initState() {
21-
WidgetsBinding.instance.addObserver(this);
21+
WidgetsBinding.instance!.addObserver(this);
2222
super.initState();
2323
}
2424

@@ -34,7 +34,7 @@ class _KeyboardVisibilityState extends State<KeyboardVisibility>
3434

3535
@override
3636
void dispose() {
37-
WidgetsBinding.instance.removeObserver(this);
37+
WidgetsBinding.instance!.removeObserver(this);
3838
super.dispose();
3939
}
4040

0 commit comments

Comments
 (0)