Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creditcard #63

Open
wants to merge 9 commits into
base: developer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/bndes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/diners.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/elo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/hipercard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/mastercard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/credit_card_flags/visa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
683 changes: 683 additions & 0 deletions lib/pages/edit_dialog_box.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/widgets.dart';
import 'add_card_repository.dart';
import 'add_card_model.dart';

class AddCardController {
AddCardRepository repository = AddCardRepository();

ValueNotifier<AddCardStates> addCardState =
ValueNotifier(AddCardInitialState());

Future<void> addCard(AddCardModel operation) async {
addCardState.value = AddCardLoadingState();
String addCreditCard =
await repository.addCreditCard(operation: operation);
if ( addCreditCard == 'success') {
addCardState.value = AddCardSuccessState();
} else {
addCardState.value = AddCardErrorState();
}
}
}

abstract class AddCardStates {}

class AddCardInitialState implements AddCardStates {}

class AddCardLoadingState implements AddCardStates {}

class AddCardSuccessState implements AddCardStates {}

class AddCardErrorState implements AddCardStates {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:convert';

class AddCardModel {
String cardName;
String description;
String limit;
String account;
AddCardModel({
this.cardName = '',
this.description = '',
this.limit = '',
this.account = '',
});

Map<String, dynamic> toMap() {
final result = <String, dynamic>{};
result.addAll({'cardName': cardName});
result.addAll({'description': description});
result.addAll({'limit': limit});
result.addAll({'account': account});

return result;
}

factory AddCardModel.fromMap(Map<String, dynamic> map) {
return AddCardModel(
description: map['description'] ?? '',
limit: map['email'] ?? '',
account: map['account'] ?? '',
);
}

String toJson() => json.encode(toMap());

factory AddCardModel.fromJson(String source) =>
AddCardModel.fromMap(json.decode(source));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'add_card_model.dart';

class AddCardRepository {
final _firebase = FirebaseAuth.instance;
final _database = FirebaseFirestore.instance;

Future<String> addCreditCard({required AddCardModel operation}) async {
try {
final userData =
_database.collection('users').doc(_firebase.currentUser!.uid);
userData
.collection('card')
.doc(operation.cardName)
.set({
'description': operation.description,
'limit': operation.limit,
'account': operation.account,
});
return 'success';
} catch (e) {
return 'error';
}
}
}
Loading