I have a list of objects that inherit from ChangeNotifier. I have removed the types just to simplify stuff.
class TaskListsState with ChangeNotifier {
List _lists = List();
_currentList;
List get lists => _lists;
get currentList => _currentList;
set lists(List newValue) {
this._lists = newValue;
notifyListeners();
}
set currentList(newValue) {
this._currentList = newValue;
notifyListeners();
}
TaskListsState() {
this._lists = [
ToDoListState(),
ToCreateListState(),
ToDecideListState(),
BalancedMeListState()
];
this._currentList = this._lists[0];
}
}
All of the objects inherit from a base class but generally, this is how they look
class ToCreateListState with ChangeNotifier implements TaskListState {
String title = "TO CREATE LIST";
String alias = "tocreate";
bool _loading = false;
List<TaskState> _tasks;
bool get loading => _loading;
List<TaskState> get tasks => _tasks;
set tasks(List<TaskState> newValue) {
this._tasks = newValue;
notifyListeners();
}
set loading(bool newValue) {
_loading = newValue;
notifyListeners();
}
ToCreateListState();
removeTask(TaskState task) {
this._tasks.remove(task);
notifyListeners();
}
}
Now, when I update one of the list objects, they don't update in the UI. How can I fix this, please?
Currently, this is how I am using it in the view:
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => TaskListsState(),
),
],
child: MaterialApp(
title: '',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Montserrat',
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: defaultHome,
onGenerateRoute: onGenerateRoute,
),
);
Then when I want to use one of the items in my screen I would do Provider.of<TaskListsState>(context).lists[index].whateverValue =. anotherValue;
However, it doesn't update.