I have a class that inherits from ChangeNotifier and does simple list control. This class works very well if I don’t call ModalRoute.of(context)?.settings.arguments before it, but when calling ModalRoute it simply stops working.
import 'package:flutter/material.dart';
class ListController extends ChangeNotifier {
final List _list = [];
int _changedIndex = 0;
String _command = "";
void addAll(List list) {
_command = "addAll";
_list.addAll(list);
notifyListeners();
}
String get command{
return _command;
}
void reloadGrid(){
_command = "reload";
notifyListeners();
}
void clear() {
_command = "clear";
_list.clear();
notifyListeners();
}
void add(Map<String, dynamic> item) {
_command = "add";
_changedIndex = 0;
_list.insert(0,item);
notifyListeners();
}
void update(int index, Map<String, dynamic> item) {
_command = "update";
_changedIndex = index;
_list[index] = item;
notifyListeners();
}
void removeAt(int index) {
_command = "removeAt";
_changedIndex = index;
_list.removeAt(index);
notifyListeners();
}
List get list{
return [..._list];
}
int get changedIndex{
return _changedIndex;
}
}
@override
Widget build(BuildContext context) {
final arguments =
ModalRoute.of(context)?.settings.arguments as List<Object?>;
final ListController detailController = ListController();
...
body: Padding(
padding: const EdgeInsets.all(8.0),
child: DetailComponent(columns: columns, controller: detailController),
),
I expected it to work fine even calling ModalRoute.of(context)?.settings.arguments
New contributor
Iury Soares Azevedo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.