Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart: What do these square brackets do in the constructor? [duplicate]

Tags:

dart

  Minesweeper([List<String> _input]){
    //...
  }

I've checked the Dart's official documentation in the sections "classes" and "lists" but neither seem to have a reference to such a syntax. I guess it's a "direct initializer"(?) so the _input field is filled without writing it explicitly in the constructor?

like image 734
aderchox Avatar asked Feb 01 '20 05:02

aderchox


People also ask

What does colon mean in DART?

It is a , -separated list of expressions that can access constructor parameters and can assign to instance fields, even final instance fields. This is handy to initialize final fields with calculated values.

What is initializer list in Dart?

An initializer list allows you to assign properties to a new instance variables before the constructor body runs, but after creation. This is handy when you want to set a final variables value, but the value isn't a compile-time constant.

How do you define a constructor in darts?

Dart defines a constructor with the same name as that of the class. A constructor is a function and hence can be parameterized. However, unlike a function, constructors cannot have a return type. If you don't declare a constructor, a default no-argument constructor is provided for you.

What is factory constructor in Dart How will you create a factory?

A factory constructor is a constructor that can be used when you don't necessarily want a constructor to create a new instance of your class. This might be useful if you hold instances of your class in memory and don't want to create a new one each time (or if the operation of creating an instance is costly).


1 Answers

[ ] denotes positional optional parameters { } denotes named optional parameters

See - What is the difference between named and positional parameters in Dart?

like image 173
Trevor Avatar answered Oct 16 '22 13:10

Trevor