Skip to content

immutable keyword for classes #1269

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

Closed
moneer-muntazah opened this issue Oct 27, 2020 · 1 comment
Closed

immutable keyword for classes #1269

moneer-muntazah opened this issue Oct 27, 2020 · 1 comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@moneer-muntazah
Copy link

Hello everyone,

I'm working on a big flutter application, and I have a lot of models that look like this:

import 'package:flutter/foundation.dart';

@immutable
class Address {
  final String id;
  final String firstName;
  final String lastName;
  final String email;
  final String phoneNumber;
  final String country;
  final String state;
  final String city;
  final String zipCode;
  final String street;
  final List<String> streetList;
  final String county;
  final String district;
  final String cardNumber;
  Address(
      {this.id, this.firstName,
      this.lastName,
      this.email,
      this.street,
      this.streetList,
      this.city,
      this.state,
      this.country,
      this.district,
      this.phoneNumber,
      this.zipCode,
      this.county,
      this.cardNumber});
}

is it possible to have an immutable key word like so:

immutable class Address {
 String id;
 String firstName;
 String lastName;
 String email;
 String phoneNumber;
 String country;
 String state;
 String city;
 String zipCode;
 String street;
 List<String> streetList;
 String county;
 String district;
 String cardNumber;
}

Such that I don't have to write the constructor, or final on each property.

I realize that I could cut down the boilerplate by listing similar types in one line, but in practice, I have annotations on my
properties so I can't do that.

Thank you all :)

@moneer-muntazah moneer-muntazah added the feature Proposed language feature that solves one or more problems label Oct 27, 2020
@lrhn
Copy link
Member

lrhn commented Oct 27, 2020

It's definitely possible. I think this is actually pretty close to "data classes" (#314), so I'll close it as a duplicate.
Might also be supported by something like #698. The feature-set is definitely on the table, the specific design is likely to be more general than just immutability.

@lrhn lrhn closed this as completed Oct 27, 2020
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants