mirror of
https://github.com/hmalik144/days_left_flutter.git
synced 2025-12-10 03:05:21 +00:00
- Implementation of firebase - Implementation of dependency injection Took 11 hours 26 minutes
54 lines
1.7 KiB
Dart
54 lines
1.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:days_left/model/DialogModels.dart';
|
|
|
|
class DialogService {
|
|
GlobalKey<NavigatorState> _dialogNavigationKey = GlobalKey<NavigatorState>();
|
|
Function(DialogRequest) _showDialogListener;
|
|
Completer<DialogResponse> _dialogCompleter;
|
|
|
|
GlobalKey<NavigatorState> get dialogNavigationKey => _dialogNavigationKey;
|
|
|
|
/// Registers a callback function. Typically to show the dialog
|
|
void registerDialogListener(Function(DialogRequest) showDialogListener) {
|
|
_showDialogListener = showDialogListener;
|
|
}
|
|
|
|
/// Calls the dialog listener and returns a Future that will wait for dialogComplete.
|
|
Future<DialogResponse> showDialog({
|
|
String title,
|
|
String description,
|
|
String buttonTitle = 'Ok',
|
|
}) {
|
|
_dialogCompleter = Completer<DialogResponse>();
|
|
_showDialogListener(DialogRequest(
|
|
title: title,
|
|
description: description,
|
|
buttonTitle: buttonTitle,
|
|
));
|
|
return _dialogCompleter.future;
|
|
}
|
|
|
|
/// Shows a confirmation dialog
|
|
Future<DialogResponse> showConfirmationDialog(
|
|
{String title,
|
|
String description,
|
|
String confirmationTitle = 'Ok',
|
|
String cancelTitle = 'Cancel'}) {
|
|
_dialogCompleter = Completer<DialogResponse>();
|
|
_showDialogListener(DialogRequest(
|
|
title: title,
|
|
description: description,
|
|
buttonTitle: confirmationTitle,
|
|
cancelTitle: cancelTitle));
|
|
return _dialogCompleter.future;
|
|
}
|
|
|
|
/// Completes the _dialogCompleter to resume the Future's execution call
|
|
void dialogComplete(DialogResponse response) {
|
|
_dialogNavigationKey.currentState.pop();
|
|
_dialogCompleter.complete(response);
|
|
_dialogCompleter = null;
|
|
}
|
|
} |