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
55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:days_left/services/DialogService.dart';
|
|
|
|
import '../locator.dart';
|
|
import '../model/DialogModels.dart';
|
|
|
|
class DialogManager extends StatefulWidget {
|
|
final Widget child;
|
|
DialogManager({Key key, this.child}) : super(key: key);
|
|
|
|
_DialogManagerState createState() => _DialogManagerState();
|
|
}
|
|
|
|
class _DialogManagerState extends State<DialogManager> {
|
|
DialogService _dialogService = locator<DialogService>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_dialogService.registerDialogListener(_showDialog);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return widget.child;
|
|
}
|
|
|
|
void _showDialog(DialogRequest request) {
|
|
var isConfirmationDialog = request.cancelTitle != null;
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text(request.title),
|
|
content: Text(request.description),
|
|
actions: <Widget>[
|
|
if (isConfirmationDialog)
|
|
FlatButton(
|
|
child: Text(request.cancelTitle),
|
|
onPressed: () {
|
|
_dialogService
|
|
.dialogComplete(DialogResponse(confirmed: false));
|
|
},
|
|
),
|
|
FlatButton(
|
|
child: Text(request.buttonTitle),
|
|
onPressed: () {
|
|
_dialogService
|
|
.dialogComplete(DialogResponse(confirmed: true));
|
|
},
|
|
),
|
|
],
|
|
));
|
|
}
|
|
}
|