Coder Social home page Coder Social logo

Comments (4)

nekocode avatar nekocode commented on May 22, 2024 2

But I know that is not a good design because the bar instance here does not hold any properties. It just like an access helper.

JFYI. Close it now. Thanks for reply.

from flutter_gen.

nekocode avatar nekocode commented on May 22, 2024 1

Since all generated values look like needn't to be evaluated in runtime? (can be static).

from flutter_gen.

lcdsmao avatar lcdsmao commented on May 22, 2024

Hi @nekocode!
Thanks for your feedback.

It seems like this problem does not relate to the getter method, but related to the path like structure we want to achieve.

For example, after changing the getter into a field it still cannot be used as the default parameter:

class Foo {
  static const bar = Bar();
}

class Bar {
  const Bar();

  final value1 = "";
  String get value2 => "";
}

void test({
  String value1 = Foo.bar.value1, // The default value of an optional parameter must be constant.
  String value2 = Foo.bar.value2, // The default value of an optional parameter must be constant.
}) {
  //
}

Since Dart does not support the nested class, the Assets class needs to hold some instances which hold the real asset path. And this caused the inconvenience usage for the default value. 😢

Speaking back to the getter, we just followed this lint rule avoid_field_initializers_in_const_classes.

Any further suggestions welcome! 😀

from flutter_gen.

nekocode avatar nekocode commented on May 22, 2024

Actually I means why not use static const field:

class Foo {
  static const bar = Bar();
}

class Bar {
  const Bar();

  static const value1 = "";
}

So that we can access the const value1 by Foo.bar.value1.

from flutter_gen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.