Consider following code:
class AppState extends ChangeNotifier {
List<int> collection = [];
AppState() {
Timer.periodic(
const Duration(seconds: 1),
(Timer t) async => await mutateCollection(),
);
}
Future mutateCollection() async {
collection.add(DateTime.now().millisecond);
notifyListeners();
}
void mutateCollectionFromUI() {
collection.add(DateTime.now().millisecond);
notifyListeners();
}
void createNewCollectionFromUI() {
collection = [];
notifyListeners();
}
}
Is it thread safe?