
import 'package:flutter/material.dart';
import 'package:twong/api/index.dart';
import 'package:twong/models/index.dart';
import 'package:twong/utils/index.dart';

class AddressModel with ChangeNotifier {
  List<Address> _list;
  AddressModel();

  List<Address> get list => _list;

  void set(List list) {
    _list = list;
    notifyListeners();
  }

  void update(int id, Address info) {
    var idx = _list.indexWhere((element) => element.id == id);
    if(idx < 0) {
      _list.add(info);
    } else {
      _list[idx] = info;
    }
    notifyListeners();
  }

  void delete(int id) {
    _list.removeWhere((element) => element.id == id);
    notifyListeners();
  }
}