Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit constructor page #5718

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/misc/lib/language_tour/classes/employee.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Map fetchDefaultData() => {}; // stub

// #docregion super
class Person {
String? firstName;

Person.fromJson(Map data) {
print('in Person');
}

String? firstName;
}

// #docregion method-then-constructor
Expand Down
4 changes: 2 additions & 2 deletions examples/misc/lib/language_tour/classes/immutable_point.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ImmutablePoint {
static const ImmutablePoint origin = ImmutablePoint(0, 0);

final double x, y;

const ImmutablePoint(this.x, this.y);

final double x, y;
}
4 changes: 2 additions & 2 deletions examples/misc/lib/language_tour/classes/logger.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// #docregion constructors
class Logger {
Logger._internal(this.name);

final String name;
bool mute = false;

Expand All @@ -15,8 +17,6 @@ class Logger {
return Logger(json['name'].toString());
}

Logger._internal(this.name);

void log(String msg) {
if (!mute) print(msg);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/misc/lib/language_tour/classes/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ const double yOrigin = 0;

// #docregion class-with-distance-to, constructor-initializer
class Point {
final double x;
final double y;

// Sets the x and y instance variables
// before the constructor body runs.
Comment on lines -11 to -15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing from the multiple Point class examples on the page.

image

The comment is helpful and shouldn't be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-added it, but it doesn't appear anywhere that I could see after.

// #docregion class-with-distance-to, named-constructor
Point(this.x, this.y);
// #enddocregion class-with-distance-to, constructor-initializer
Expand All @@ -24,6 +19,11 @@ class Point {
y = yOrigin;
// #enddocregion named-constructor

// Sets the x and y instance variables
// before the constructor body runs.
final double x;
final double y;

// Initializer list sets instance variables before
// the constructor body runs.
Point.fromJson(Map<String, double> json)
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/lib/language_tour/classes/point_alt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
///
// #docregion idiomatic-constructor
class Point {
double x = 0;
double y = 0;

// Generative constructor with initializing formal parameters:
Point(this.x, this.y);

double x = 0;
double y = 0;
// #enddocregion idiomatic-constructor

// #docregion initializer-list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Point {
double x, y;

// The main constructor for this class.
Point(this.x, this.y);

double x, y;

// Delegates to the main constructor.
Point.alongXAxis(double x) : this(x, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import 'dart:math';

class Point {
Point(this.x, this.y) : distanceFromOrigin = sqrt(x * x + y * y);

final double x;
final double y;
final double distanceFromOrigin;

Point(double x, double y)
: x = x,
y = y,
distanceFromOrigin = sqrt(x * x + y * y);
}

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class Vector2d {

// #enddocregion named
// #docregion positional
Vector2d(this.x, this.y);

final double x;
final double y;

Vector2d(this.x, this.y);
// #enddocregion positional

// #docregion named
Expand Down
Loading