Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the route exists before calling isDismissed or isShowing #20

Merged
merged 1 commit into from
Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/flushbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ class Flushbar<T extends Object> extends StatefulWidget {
/// Dismisses the flushbar causing is to return a future containing [result].
/// When this future finishes, it is guaranteed that Flushbar was dismissed.
Future<T> dismiss([T result]) async {
// If route was never initialized, do nothing
if (_flushbarRoute == null) {
return null;
}

if (_flushbarRoute.isCurrent) {
_flushbarRoute.navigator.pop(result);
return _flushbarRoute.completed;
Expand All @@ -407,12 +412,12 @@ class Flushbar<T extends Object> extends StatefulWidget {

/// Checks if the flushbar is visible
bool isShowing() {
return _flushbarRoute.currentStatus == FlushbarStatus.SHOWING;
return _flushbarRoute?.currentStatus == FlushbarStatus.SHOWING;
}

/// Checks if the flushbar is dismissed
bool isDismissed() {
return _flushbarRoute.currentStatus == FlushbarStatus.DISMISSED;
return _flushbarRoute?.currentStatus == FlushbarStatus.DISMISSED;
}

@override
Expand Down
7 changes: 5 additions & 2 deletions test/flushbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('Test Flushbar basic inicialization', () {
test('Test Flushbar basic inicialization', () async {
final flushbar = new Flushbar(message: "This is a test");
expect(flushbar.title, null);
expect(flushbar.message, "This is a test");
Expand All @@ -26,7 +26,10 @@ void main() {
expect(flushbar.progressIndicatorController, null);
expect(flushbar.progressIndicatorBackgroundColor, null);
expect(flushbar.progressIndicatorValueColor, null);
expect(flushbar.isShowing(), false);
expect(flushbar.isDismissed(), false);
expect(await flushbar.dismiss(), null);
});


}