Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter: Expected to find '}'. in if else condition

Tags:

flutter

dart

In GestureDetector in onTap event i have a if condition like this:

Positioned(
  left: 1.0,
  top: -20.0,
  child: GestureDetector(
    onTap: () => {
      if (widget.status == RemoteStatus.edit)
        {
          showChooseProfileScreen(0).then((val) {
            if (val != null && val) {
              print("------> $val");
            }
          })
        }
      else {
        if (!onTapRaised)
        {
          sendCommand(54); //Expected to find '}'. error
          onTapRaised = true;
          releaseTapRaised(onTapRaised);
        }
      }
    },
    child: Container(
      margin: EdgeInsets.only(left: 20.0, top: 20.0),

Someone knows why i got error Expected to find '}'. in sendCommand(54); part?

enter image description here

I run flutter clean before but i still got this error.

like image 564
Cyrus the Great Avatar asked Oct 18 '25 09:10

Cyrus the Great


1 Answers

Change

onTap: () => {

to

onTap: () {

Because otherwise Dart interprets it as if you were returning map literal, not executing set of instructions.

Example:

Map foo() => {'key': 'value'}; // returns Map
void bar() { print('just executes set of instructions'); } // returns void

Refer to Functions section in the Language tour.

like image 55
Andrey Ozornin Avatar answered Oct 21 '25 03:10

Andrey Ozornin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!