代码之家  ›  专栏  ›  技术社区  ›  amirhe

什么。。在飞镖语言中的意思?

  •  -1
  • amirhe  · 技术社区  · 4 年前

    什么是 .. flutter项目中dart语言的意思?

    考虑以下示例:

    @override
    void initState() {
      super.initState();
      _controller = AnimationController(
        duration: const Duration(milliseconds: 1000),
        vsync: this
      )..repeat();
    // ^^ here
    

    注意:

    我发现堆栈溢出中没有引用级联运算符,所以我添加了堆栈本身的问答可能对后人有帮助。

    2 回复  |  直到 4 年前
        1
  •  1
  •   Balaji    4 年前

    它被称为级联运算符

    例如,您可以像这样使用级联运算符,它提高了可读性

    class User {
      
      double? id;
      
      String? name;
    
      void printName(){
        print(name ?? 'Name is Null');
      }
      
    }
    
     // Instead of this
    
      User user = User();
      user.id = 5;
      user.name = 'Maverick';
      user.printName();
      
     // Using Cascade operator
    
      User user2 = User();
      user2
        ..id = 6
        ..name = 'Kenny'
        ..printName();
    
    
      // Another Example using cascade operator
    
      User user3 = User()..id = 7
                         ..name = 'Roger'
                         ..printName();
      
    
        2
  •  0
  •   amirhe    4 年前

    它被称为级联运算符,可以在中阅读 official doc

    在简单的形式中,它表示调用该方法,但不是返回方法的返回值-返回对象(类)的引用,而是在上调用它。

    这里虽然 repeat 将继续运行 AnimationController 它将返回 动画控制器 要存储的引用 _controller 。它允许访问和调用的另一种方法 动画控制器 在其他可以访问的部分 _控制器