website
website copied to clipboard
Mistake on flutter tutorial impedes progression
Describe the problem
Wrong code on this page: https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2#4 As this is mainly aimed at beginners who might find difficult to spot the mistake i thought wise to report it. The code in the first windows on the page reads:
return ListTile(
title: Text(
_suggestions[index].asPascalCase,
style: _biggerFont,
),
trailing: Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
semanticLabel: alreadySaved ? 'Remove from saved' : 'Save',
),
onTap: () { // NEW from here ...
setState(() {
if (alreadySaved) {
_saved.remove(_suggestions[index]);
} else {
_saved.add(_suggestions[index]);
}
}); // to here. // THIS IS THE LINE CONTAINING THE MISTAKE
},
);
Expected fix
to work the code should read:
return ListTile(
title: Text(
_suggestions[index].asPascalCase,
style: _biggerFont,
),
trailing: Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
semanticLabel: alreadySaved ? 'Remove from saved' : 'Save',
),
onTap: () { // NEW from here ...
setState(() {
if (alreadySaved) {
_saved.remove(_suggestions[index]);
} else {
_saved.add(_suggestions[index]);
}
});
}, // to here. // THIS IS THE LINE THAT NEEDS CHANGING!
);
Additional context

@domesticmouse, can you handle this?
This codelab has been replaced by a the newly written Your first Flutter app which doesn't have this issue. Check it out and let us know what you think!
Thanks again for opening the issue!