website icon indicating copy to clipboard operation
website copied to clipboard

Mistake on flutter tutorial impedes progression

Open emagnu opened this issue 3 years ago • 1 comments

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

image

emagnu avatar May 16 '22 13:05 emagnu

@domesticmouse, can you handle this?

sfshaza2 avatar May 16 '22 20:05 sfshaza2

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!

parlough avatar Jan 08 '23 00:01 parlough