mirror of
https://github.com/hmalik144/days_left_flutter.git
synced 2026-03-18 07:26:19 +00:00
- Introduction on base view model and stateless widget classes
- Implementation of firebase - Implementation of dependency injection Took 11 hours 26 minutes
This commit is contained in:
54
lib/managers/DialogManager.dart
Normal file
54
lib/managers/DialogManager.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
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));
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user