get方法获取数据,封装存储和移除方法用于操作数据缓存列表(需要优化,仅参考)
/*
使用Provider进行本地缓存
*/
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class TestDataBaseModel{
String name;
String version;
TestDataBaseModel(this.name, this.version);
}
class CYDataBaseProvider with ChangeNotifier,DiagnosticableTreeMixin{
List<TestDataBaseModel> _dataList= [];
List<TestDataBaseModel> get dataList{
return _dataList;
}
void addData(TestDataBaseModel dataModel){//添加数据
_dataList.add(dataModel);
notifyListeners();
}
void removeData(TestDataBaseModel dataModel){//移除数据
_dataList.remove(dataModel);
notifyListeners();
}
}