car_provider.dart 622 B

1234567891011121314151617181920212223
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_provider_demo/dao/car_dao.dart';
  3. import 'package:flutter_provider_demo/model/car_model.dart';
  4. /// Description: car provider
  5. /// Time : 09/04/2023 Monday
  6. /// Author : liuyuqi.gov@msn.cn
  7. class CarProvider extends ChangeNotifier {
  8. late List<CarModel> _cars;
  9. int _count = 0;
  10. Future<List<CarModel>> getCars() async {
  11. _cars = await CarDao.getCars();
  12. notifyListeners();
  13. return _cars;
  14. }
  15. void deleteCar(BuildContext context, CarModel car) async {
  16. await CarDao.deleteCar(car);
  17. _cars.remove(car);
  18. notifyListeners();
  19. }
  20. }