'Why are the elements removed on booth Lists?
Why does it remove the list element from booth lists?
Is it in Darts just a pointer?
How to fix it?
class _ResultsState extends State<Results> {
var _league;
var originalLeague;
@override
void initState() {
super.initState();
_league = API_Manager.getLeagueFull(widget.leagueId, widget.seasonId, context);
}
void filterData(String teamName) async {
if (originalLeague == null) {
_league = await _league;
originalLeague = List.from(_league);
}
List<LeagueModel> leagues = List.from(originalLeague);
print('List length: ${originalLeague[0].dates.length}');
if (teamName != 'Kein Filter') {
leagues[0].dates.removeWhere((element) => !element.guestTeam.contains(teamName) && !element.homeTeam.contains(teamName));
}
print('List length now: ${originalLeague[0].dates.length}');
print('New List length: ${leagues[0].dates.length}');
setState(() {
_league = filteredList(leagues);
});
}
Future<List<LeagueModel>> filteredList( List<LeagueModel> list) async {
return list;
}
}
Console Output:
flutter: List length: 30
flutter: List length now: 10
flutter: New List length: 10
Edit:
As recommendet i testet [...data] and List.from(data) but it still removes the elements from booth lists. Updated the code above
Solution 1:[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

