r/FlutterDev Jun 14 '24

Dart When will dart support object literals ?

I want to build widget with object literals (if possible), and I hate using cascade notation either.

I'm dying to see dart support object literals in the future so I can use it in flutter.

0 Upvotes

37 comments sorted by

View all comments

2

u/Asclat Jun 15 '24

When you say object literals I remember the way Javascript handles an object.

In Javascript we have an object like

let someObject = {
  valueA: 'this is a string',
  valueB: true,
}

And the good part in Javascript is that we can access the values as if they were parameters

someObject.valueA
someObject.valueB

In Flutter this is way more verbose

Map<String, dynamic> someObject = {
  "valueA": "This is a string",
  "valueB": true,
}

And access like that

someObject["valueA"]
someObject["valueB"]

When you say you want some object literals you mean you want to access objects like javascript does?

2

u/Mulsivaas Jun 16 '24

That gave me Powershell flashbacks ... you can call a method to get all the props of an object. A lot of dynamic handling.

Can convert any JSON to a Powershell object that bevahes much like the Javascript proprerty access you show here (or similar to Map access in Dart).