Skip to content

Commit

Permalink
refactor: Migrate to sound null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
MMMzq committed Feb 2, 2021
1 parent c028162 commit 1cae874
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 244 deletions.
4 changes: 2 additions & 2 deletions example/lib/attached_toast/attached_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class _AttachedToastState extends State<AttachedToast> {
FlatButton.icon(
padding: EdgeInsets.all(5),
onPressed: (){
BotToast.showSimpleNotification(title: "Let's go travel together.😘");
BotToast.showSimpleNotification(title: "Tap favorite");
},
label: Text("favorite"),
icon: Icon(Icons.favorite,color: Colors.redAccent),
),
FlatButton.icon(
padding: EdgeInsets.all(5),
onPressed: (){
BotToast.showSimpleNotification(title: "Thank you for liking me.😝");
BotToast.showSimpleNotification(title: "Tap bookmark");
},
label: Text("bookmark"),
icon: Icon(Icons.bookmark,color: Colors.redAccent),
Expand Down
9 changes: 6 additions & 3 deletions example/lib/loading/custom_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class __CustomLoadWidgetState extends State<_CustomLoadWidget>
}),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Text("me too"),
child: Text("Tap loading toast"),
)
],
),
Expand All @@ -82,8 +82,11 @@ class __CustomLoadWidgetState extends State<_CustomLoadWidget>
onPressed: handleTap,
),
),
Text(
"i miss you",
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Loading",
),
)
],
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/notification/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class _NotificationState extends State<Notification> {
icon: Icon(Icons.favorite, color: Colors.redAccent),
onPressed: cancel,
)),
title: (_) => Text('I love u'),
subtitle: (_) => Text("let's be together"),
title: (_) => Text('Notification title'),
subtitle: (_) => Text("Notification subtitle"),
trailing: (cancel) => IconButton(
icon: Icon(Icons.cancel),
onPressed: cancel,
Expand Down
8 changes: 4 additions & 4 deletions example/lib/notification/simple_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class _SimpleNotificationState extends State<SimpleNotification> {
@override
void initState() {
BotToast.showSimpleNotification(
title: "do you still love me ?",
subTitle: "yes!",
title: "Notification title",
subTitle: "Notification subtitle",
enableSlideOff: enableSlideOff,
hideCloseButton: hideCloseButton,
onTap: () {
Expand Down Expand Up @@ -58,8 +58,8 @@ class _SimpleNotificationState extends State<SimpleNotification> {
RaisedButton(
onPressed: () {
BotToast.showSimpleNotification(
title: "do you still love me ?",
subTitle: "yes!",
title: "Notification title",
subTitle: "Notification subtitle",
enableSlideOff: enableSlideOff,
hideCloseButton: hideCloseButton,
onlyOne: onlyOne,
Expand Down
4 changes: 2 additions & 2 deletions example/lib/text/custom_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _CustomTextState extends State<CustomText> {
),
onPressed: () {
BotToast.showSimpleNotification(
title: "Yes, I do!",
title: "Notification one",
crossPage: crossPage,
closeIcon: Icon(
Icons.favorite,
Expand All @@ -68,7 +68,7 @@ class _CustomTextState extends State<CustomText> {
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8),
child: Text("propose marriage?"),
child: Text("Text one"),
),
],
),
Expand Down
6 changes: 3 additions & 3 deletions example/lib/text/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class _TextSampleState extends State<TextSample> {
RaisedButton(
onPressed: () {
BotToast.showText(
text: (index++).isOdd
? "Always together☺"
: "My mind is all about you.😘",
text: (++index).isOdd
? "Text one"
: "Text two",
duration: Duration(seconds: seconds),
onlyOne: onlyOne,
clickClose: clickClose,
Expand Down
15 changes: 7 additions & 8 deletions lib/src/bot_toast_init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import 'bot_toast_manager.dart';
final GlobalKey<BotToastManagerState> _key = GlobalKey<BotToastManagerState>();

BotToastManagerState get botToastManager {
assert(_key?.currentState != null);
return _key.currentState;
assert(_key.currentState != null);
return _key.currentState!;
}

class BotToastWidgetsBindingObserver with WidgetsBindingObserver {
BotToastWidgetsBindingObserver._() {
_listener = <PopTestFunc>[];
WidgetsBinding.instance.addObserver(this);
BotToastWidgetsBindingObserver._() : _listener = <PopTestFunc>[] {
WidgetsBinding.instance!.addObserver(this);
}

List<PopTestFunc> _listener;
final List<PopTestFunc> _listener;

static final BotToastWidgetsBindingObserver _singleton =
BotToastWidgetsBindingObserver._();
Expand Down Expand Up @@ -49,7 +48,7 @@ TransitionBuilder BotToastInit() {

//ignore: unnecessary_statements
BotToastWidgetsBindingObserver._singleton;
return (_, Widget child) {
return BotToastManager(key: _key, child: child);
return (_, Widget? child) {
return BotToastManager(key: _key, child: child!);
};
}
21 changes: 10 additions & 11 deletions lib/src/bot_toast_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

void safeRun(void Function() callback) {
SchedulerBinding.instance.addPostFrameCallback((_) {
SchedulerBinding.instance!.addPostFrameCallback((_) {
callback();
});
SchedulerBinding.instance.ensureVisualUpdate();
SchedulerBinding.instance!.ensureVisualUpdate();
}

class BotToastManager extends StatefulWidget {
final Widget child;

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

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

final int index;

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

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -62,7 +63,7 @@ class BotToastManagerState extends State<BotToastManager> {
_map[groupKey]?.remove(key);
},
);
_map[groupKey][key] = _IndexWidget(
_map[groupKey]![key] = _IndexWidget(
key: uniqueKey,
index: ++_nextAddIndex,
child: widget,
Expand Down Expand Up @@ -90,14 +91,12 @@ class BotToastManagerState extends State<BotToastManager> {
return;
}

_map[groupKey].removeWhere((key, _) => !_pending.contains(key));
_map[groupKey]!.removeWhere((key, _) => !_pending.contains(key));
_update();

if (_map[groupKey].isNotEmpty) {
_map[groupKey].forEach((key, value) {
return remove(groupKey, key);
});
}
_map[groupKey]!.forEach((key, value) {
return remove(groupKey, key);
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/keyboard_safe_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class KeyboardSafeArea extends StatelessWidget {

final bool enable;

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

@override
Widget build(BuildContext context) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/keyboard_visibility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class KeyboardVisibility extends StatefulWidget {
final Widget child;

const KeyboardVisibility(
{@required this.onKeyboardVisibilityChanged,
@required this.child,
Key key})
{required this.onKeyboardVisibilityChanged,
required this.child,
Key? key})
: super(key: key);

@override
Expand All @@ -18,7 +18,7 @@ class _KeyboardVisibilityState extends State<KeyboardVisibility>
with WidgetsBindingObserver {
@override
void initState() {
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance!.addObserver(this);
super.initState();
}

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

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}

Expand Down
Loading

0 comments on commit 1cae874

Please sign in to comment.