Search code examples
flutterarrow-functions

What is the meaning of this line of code in Flutter?


_counterState createState() => _counterState();

So I know what => does. It is an arrow function, and a shorthand version of curly braces + return.

So this line is essentially returning _counterState()

What I don't understand is why is there _counterState before createState(). What does it mean? I know createState is a function in Flutter.

I am a beginner in coding and know basics. Although this line confused me alot. Can you guys please help?

I will provide any other additional info you need.


Solution

  • Things like _counterState or bool, String, int etc. means the function return type which is before function f.e.

    int returnNumber() => 2; It means that the function "RetrunNumber" will return a value which is a int.

    More info you will find: https://dart.dev/guides/language/language-tour#a-basic-dart-program