address.dart 673 B

1234567891011121314151617181920212223242526272829303132
  1. import 'package:flutter/material.dart';
  2. import 'package:twong/api/index.dart';
  3. import 'package:twong/models/index.dart';
  4. import 'package:twong/utils/index.dart';
  5. class AddressModel with ChangeNotifier {
  6. List<Address> _list;
  7. AddressModel();
  8. List<Address> get list => _list;
  9. void set(List list) {
  10. _list = list;
  11. notifyListeners();
  12. }
  13. void update(int id, Address info) {
  14. var idx = _list.indexWhere((element) => element.id == id);
  15. if(idx < 0) {
  16. _list.add(info);
  17. } else {
  18. _list[idx] = info;
  19. }
  20. notifyListeners();
  21. }
  22. void delete(int id) {
  23. _list.removeWhere((element) => element.id == id);
  24. notifyListeners();
  25. }
  26. }