if (ElementId.op_Inequality(primaryViewId, ElementId.InvalidElementId))
Error: 'Autodesk.Revit.DB.ElementId.operator !=(Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId)': cannot explicitly call operator or accessor
Have you tried this:
if (primaryViewId != ElementId.InvalidElementId)
Related
Error: Method 'replaceFirst' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.)
.replaceFirst(r'$selectedRowCount', formatDecimal(selectedRowCount));
As Saffron-codes says, you cant do a replaceFirst on a 'String?' variable since it can be null, and dart is null safe.
There's two options for you to do. You can either make the variable a 'String' instead, if you do this you'll have to give it a value when initiating it:
String variableName = ''
Instead of:
String? variableName
You could also do a null-check (adding a questionmark before .replaceFirst) when calling replaceFirst, this is what it suggests doing in the error message 'Try calling using ?. instead.':
variableName?.replaceFirst(r'$selectedRowCount', formatDecimal(selectedRowCount));
Add the ! operator before . to make it non-nullable
!.replaceFirst(r'$selectedRowCount', formatDecimal(selectedRowCount));
I want to feed Two to the function. When function receives Two as the data, it should print success to the console. But seems like it's not the correct way.
Error: Conditions must have a static type of 'bool'. Try changing the condition.
List
enum ButtonList {One, Two, Three}
Calling function
testFunc(ButtonList.Two)),
Function
testFunc( ButtonList type) {
if (type = ButtonList.Two ){print('sucess ')};
}
It should be:
testFunc(ButtonList type) {
if (type == ButtonList.Two) {
print('sucess ')
};
}
There's a big difference between = (assigning a value to a variable) and == (equality comparison). if expects a condition (==), not the assigning operation (=).
Formatting is important to read and understand the code. Please read Dart best code style practices: https://dart.dev/guides/language/effective-dart/style
You are trying to assign with =, use == instead
How would I handle the objectA[0].name (a string) in the build method if the array is empty?
Text(objectB.objectC.objectA[0].name),
Assuming the array is objectC you can do something like:
Text(objectC.isEmpty? "" :objectC[0].name)
You can read more about ternary operators in dart here
There isn't a great way to do this inline but with a simple extension method to return the original null or the iterable depending on whether the item is null or empty you can make it work.
First
Extension Method
(requires dart v2.7 - update in your pubspec.yaml file)
extension IterableExtension<T> on Iterable<T> {
Iterable<T> get nullWhenEmpty =>
this == null || this.isEmpty ? null : this;
}
Second
To handle null values while you're traversing an object you can use the Dart's conditional member access operator (?.). This operator will only continue with the right-hand side if the left-hand side of the operator is not null. Use the elementAt method on a an iterable to be able to use the ?. operator in the chain. Then, use the ?. operations with the if null operator (??) to get your default value.
Solution
final String value = objectB?.objectC?.objectA?.nullWhenEmpty?.elementAt(0)?.name;
Text(value ?? 'Default Text');
You can, of course, inline the above code instead of using an additional variable.
Resources
Dart Language Tour: Other Operators
Dart Language Tour: Classes
Maybe checking if the list has an element, using isNotEmpty
child: (objectB.objectC.objectA.isNotEmpty)
? Text(objectB.objectC.objectA[0].name)
: Container(),
if cake == "delicious":
return "yes"
SyntaxError: 'return' outside function
Why I get like this?
You can create some functions like this.
text ="delicious"
def check(text):
if text=="delicious":
return 'yes'
check(text)
return is a keyword which can only appear in a function definition (as the syntax error says). You can simply print your output in an if/else block
if cake == 'delicious': print('yes')
My condition for break :
event instanceof org.geomajas.gwt.client.widget.event.SearchEvent
I have tried other variations like event instanceof SearchEvent / with parantheses and with/out ";"
The error : Evaluations must contain either an expression or a block of well-formed statements
The solution: ?
BTW I'm using jdk 1.6.25
return event instanceof org.geomajas.gwt.client.widget.event.SearchEvent;
should do the trick