[SOLVED] In flutter what is the use “..” instead of “.”?


This Content is from Stack Overflow. Question asked by Geek

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).


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()

          text: 'Tap here.',
          recognizer: tapGes,

This Question was asked in StackOverflow by Geek and Answered by Phan Kiet It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?