Geek
Geek

Reputation: 1

In flutter what is the use ".." instead of "."?

Gesture detection in Flutter TextSpan I found this code

import 'package:flutter/gestures.dart';
...

new RichText(
      text: new TextSpan(text: 'Non touchable. ', children: [
        new TextSpan(
          text: 'Tap here.',
          recognizer: new TapGestureRecognizer()..onTap = () => print('Tap Here onTap'),
        )
      ]),
    );

Why here double dot ".." is used to access onTap and why It's giving error when I use "." (single dot).

Upvotes: 0

Views: 209

Answers (1)

Phan Kiet
Phan Kiet

Reputation: 196

Double dots(..) i.e cascade operator “.. ”is known as cascade notation(allow you to make a sequence of operations on the same object). It allows you to not repeat the same target if you want to call several methods on the same object.This often saves you the step of creating a temporary variable and allows you to write more fluid code. Normally, we use the below way to define several methods on the same object.

var tapGes = TapGestureRecognizer()
tapGes.onTap = func()


var tapGes = TapGestureRecognizer()
  ..onTap = func()



...
TextSpan(
          text: 'Tap here.',
          recognizer: tapGes,
        )
...

Upvotes: 2

Related Questions