floating action and bottom bar release

4.4
Serik.Uvaissov 2020-05-26 20:33:03 +06:00
parent 3e7007ab63
commit 28bffdf0f7
4 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import 'user.dart';
class AuthResponse {
final AuthBody body;
final int status;
final bool operation;
AuthResponse( {this.body, this.status, this.operation});
factory AuthResponse.fromJson(Map<String, dynamic> json) {
return AuthResponse(
operation: json['operation'],
status: json['status'],
body: AuthBody.fromJson(json['body'])
);
}
}
List<String> parseListString(json){
if(json==null) return null;
return new List<String>.from(json);
}
class AuthBody {
final List<String> email;
final List<String> password;
final String message;
final User user;
AuthBody({this.message, this.user, this.email, this.password});
factory AuthBody.fromJson(Map<String, dynamic> json) {
return AuthBody(
email: json['email']!=null ? parseListString(json['email']): null,
message: json['message'],
password: json['password']!=null ? parseListString(json['password']): null,
user: json['user']!=null ? User.fromJson(json['user']) : null
);
}
}

View File

@ -0,0 +1,26 @@
import 'package:flutter/foundation.dart';
class DialogRequest {
final String title;
final String description;
final String buttonTitle;
final String cancelTitle;
DialogRequest(
{@required this.title,
@required this.description,
@required this.buttonTitle,
this.cancelTitle});
}
class DialogResponse {
final String fieldOne;
final String fieldTwo;
final bool confirmed;
DialogResponse({
this.fieldOne,
this.fieldTwo,
this.confirmed,
});
}

View File

@ -0,0 +1,54 @@
import 'dart:async';
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
import 'package:flutter/cupertino.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;
}
}

View File

@ -0,0 +1,53 @@
import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
import 'package:flutter/material.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));
},
),
],
));
}
}