fbmobile/lib/core/manager/dialog_manager.dart

65 lines
1.6 KiB
Dart
Raw Normal View History

2021-02-02 14:33:23 +00:00
import 'package:flutter/material.dart';
import '../../locator.dart';
import '../datamodels/dialog_request.dart';
import '../datamodels/dialog_response.dart';
import '../services/dialog_service.dart';
class DialogManager extends StatefulWidget {
final Widget? child;
2021-02-02 14:33:23 +00:00
DialogManager({Key? key, this.child}) : super(key: key);
2021-02-02 14:33:23 +00:00
_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!;
2021-02-02 14:33:23 +00:00
}
void _showDialog(DialogRequest request) {
List<Widget> actions = <Widget>[];
if (request.buttonTitleDeny != null && request.buttonTitleDeny!.isNotEmpty) {
Widget denyBtn = TextButton(
child: Text(request.buttonTitleDeny!),
2021-02-02 14:33:23 +00:00
onPressed: () {
_dialogService.dialogComplete(DialogResponse(confirmed: false));
},
);
actions.add(denyBtn);
}
Widget confirmBtn = TextButton(
child: Text(request.buttonTitleAccept!),
2021-02-02 14:33:23 +00:00
onPressed: () {
_dialogService.dialogComplete(DialogResponse(confirmed: true));
},
);
actions.add(confirmBtn);
AlertDialog alert = AlertDialog(
title: Text(request.title!),
content: Text(request.description!),
2021-02-02 14:33:23 +00:00
actions: actions,
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}