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

前端 未结 6 2108
孤独总比滥情好
孤独总比滥情好 2021-02-13 03:36

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

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


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 04:33

    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.

提交回复
热议问题