Issue void main() { var a=10; var b=2; var toplam=a+=b; var fark=a-=b; var carpim=a*=b; var bolme=a/=b; print("$toplam"); print("$fark"); print("$carpim"); print("$bolme"); } This code gives the following error when splitting: "A value of type ‘double’ can’t be assigned to a variable
Continue readingTag: operators
What does `operator () { … }` do in Dart?
Issue Here is a simple dart class: class MyOperatorClass { int operator () { return 5; } } I noticed today that this compiles without any issues. This led me to wonder, what does operator () mean? Usually in dart,
Continue readingAdding extra option to tenerary operator flutter
Issue Container( decoration: BoxDecoration( color: (page == _currentPage) ? Colors.blue.shade800 : Colors.green.shade600 ), I am trying to add another option to the tenerary operator since i have three pages that will change color. How can i add a third option
Continue readingSyntactic sugar for calling a function with a nullable value that might return null
Issue I am looking for syntactic sugar with null-safe-operators to do this: map["key"] == null ? default : (int.tryParse(map["key"]!) ?? default) This however accesses map twice and requires default twice. Better, but verbose code that also compiles: String? val =
Continue readingCan anyone please explain the use of null-shorting cascade in Dart?
Issue I’m confused about what the documentation says here: Solution Example class class Foo { String? text; List<String> classes = []; @override String toString() { return "text $text classLength ${classes.length}"; } } querySelector can return null instead of Foo Foo?
Continue readingCan someone please explain `List<BaseType>`
Issue In the Dart cheatsheet to null-aware-operators it says: Specifying types is handy when you initialize a list with contents of a subtype, but still want the list to be List<BaseType>: final aListOfBaseType = <BaseType>[SubType(), SubType()]; Could someone please elaborate
Continue readingWhat are the ?? double question marks in Dart?
Issue The following line of code has two question marks: final myStringList = prefs.getStringList(‘my_string_list_key’) ?? []; What is the meaning? Solution The ?? double question mark operator means "if null". Take the following expression, for example. String a = b
Continue readingError to use assignment operators ==? in Dart
Issue I am learning Dart and practicing with this video I came across this way of assigning a value when the variable is null void main() { int linus; linus ??= 100; print(linus); } When trying to test the code
Continue readingWhat is "!" in Dart Flutter?
Issue I know ! is used for NOT operation, but i find a code that use ! to fill variable with nullable type variable. When i read some code reference from internet i find this: NoteDetailPage(noteId: note.id!) This is what
Continue readingDart Operators : The name 'b' isn't a type and can't be used in an 'is' expression
Issue I’m new to dart and reading about dart operators. In the book fluter in Action by Eric Windmill (Chapter 2, 2.24, page 34) the auther says: is and is! verify that two objects are of the same type. They
Continue reading