首页 > 解决方案 > 编写这样的代码有什么好处?

问题描述

我正在阅读一篇关于颤振 bloc 编程的文章。https://bloclibrary.dev/#/flutterfirestoretodostutorial

Todo 类在文章中定义如下。

class Todo {
  final bool complete;
  final String id;
  final String note;
  final String task;

  Todo(this.task, {this.complete = false, String note = '', String id})
      : this.note = note ?? '',
        this.id = id;

  //... other code ...

我想知道像上面这样写构造函数的好处,对比下面的方式。我在那个网站上发现了很多类似的情况。

Todo(this.task, {this.complete = false, this.note = '', this.id});

谢谢。

标签: flutterdartbloc

解决方案


推荐阅读