workouttest_app/lib/viewmodel/customer_changing_view_model.dart
2020-05-24 10:04:37 +02:00

37 lines
1.2 KiB
Dart

import 'package:aitrainer_app/service/customer_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:aitrainer_app/model/customer.dart';
import 'customer_view_model.dart';
class CustomerChangingViewModel extends ChangeNotifier {
CustomerViewModel customer = CustomerViewModel();
List<CustomerViewModel> customerList = List<CustomerViewModel>();
CustomerChangingViewModel(customer) {
this.customer = customer;
}
Future<void> addCustomer() async {
this.customer = customer;
final Customer modelCustomer = customer.getCustomer();
await CustomerApi().addCustomer(modelCustomer);
}
Future<void> saveCustomer() async {
this.customer = customer;
final Customer modelCustomer = customer.getCustomer();
await CustomerApi().saveCustomer(modelCustomer);
}
Future<List<CustomerViewModel>> getCustomers() async {
final results = await CustomerApi().getRealCustomers("");
this.customerList = results.map((item) => CustomerViewModel(customer: item)).toList();
notifyListeners();
return this.customerList;
}
addNewCustomerToList(CustomerViewModel customerViewModel) {
customerList.add(customerViewModel);
}
}