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 customerList = List(); CustomerChangingViewModel(customer) { this.customer = customer; } Future addCustomer() async { this.customer = customer; final Customer modelCustomer = customer.getCustomer(); await CustomerApi().addCustomer(modelCustomer); } Future saveCustomer() async { this.customer = customer; final Customer modelCustomer = customer.getCustomer(); await CustomerApi().saveCustomer(modelCustomer); } Future> 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); } }