Flutter/Dart - Difference between () {} and () => {}

前端 未结 6 2319
挽巷
挽巷 2021-02-13 03:44

In Flutter/Dart the examples sometimes show fat arrow and sometimes dont. Here are examples:

RaisedButton(
  onPressed: () {
    setState(() {
      _myTxt = \"         


        
6条回答
  •  萌比男神i
    2021-02-13 04:38

    They are both for expressing anonymous functions. The fat arrow is for returning a single line, braces are for returning a code block.

    A fat arrow trying to return a code block will not compile.

提交回复
热议问题