Using flutter/dart vscode shows "method isn't defined" when i check for a specific mixin before calling it - flutter

This is my first time messing with dart and i'm stuck with this silly error. I'm 90% confident that the error lies on the vscode part of it, because there aren't errors showing when running the app.
Maybe I'm approaching the problem in the wrong way, I simply want to call a mixin function in objects that implements the mixin. In java for example it would be required to cast the component variable, but I couldn't get cast to work in this situation.
Code
Error
The method 'onPanUpdate' isn't defined for the class 'Component'.
Try correcting the name to the name of an existing method, or defining a method named 'onPanUpdate'.
Source Code
Repo link
Component class source

Maybe I'm approaching the problem in the wrong way, I simply want to call a mixin function in objects that implements the mixin. In java for example it would be required to cast the component variable, but I couldn't get cast to work in this situation.
For this to work it must be done with the following code:
for (var component in this.components) {
if (component is PanDetector) {
(component as PanDetector).onPanUpdate(details);
}
}
Especial thanks to #Moqbel

Related

LibGDX how do I use one boolean in all class

I have one class that I put the Boolean in but I need to use it
In a different class so can anyone tell me what to do
To get the boolean to work for the other classes to
https://i.stack.imgur.com/8clF1.png image 2 https://i.stack.imgur.com/wxA3N.png
First of all check this post, we discourage screenshots of code and/or errors so please post code in future instead of screenshot.
From screenshot on is non-static data member of playbutton class. You can't use non-static data member in all class.
You need an object of playbutton, if you want to access any non-static data member.
playbutton x=new playbutton();
x.on=true;
I'll recommend you to follow naming conventions in java for better coding experience.

How to get application "namespace" in Swift implicitly?

Short version:
Assuming I have an app called MyApp. In some situation I have a duplicate class name so that one is MyClass where the other is MyApp.MyClass. How can I call MyApp.MyClass having MyApp constant (do not need to change the code if I change the app name).
Why and what happened (long version):
So assume we are in this MyApp application having following code (the real one is way way longer and used allover the app):
class MyClass {
}
class SomeOtherClass {
class MyClass {
}
func findMyClass(fromMyClass: MyApp.MyClass) -> MyClass {
...
}
}
Because there are two classes called MyClass in inner scope we need to call MyApp.MyClass to get the outer one which is all good.
But it seems a bit silly when MyApp changes which is my case.
Why did it change? I actually added a new target by duplicating the original one because I wanted to have some extra and some different settings (pretty standard procedure). So I renamed the new one to have MyApp-dev where I then got an error Use of undeclared type 'MyApp'.
So is there a keyword that can replace MyApp?
My current solution is to define a typealias on file scope that is then used inside the class to replace MyApp. The problem is that the method is not private so the typealias may not be private either which means I just have an extra name defined globally in the project.
EDIT:
Also there is a setting in Xcode build settings called Product Module Name which may be overridden to explicit naming which fixes the issue. Still this not really a good general solution; I can see cases where you might reuse the same code in multiple modules (creating libraries) which has the same issue. This would still meant that code would need to be fixed for each of these modules.

Different field instances in class and parent/Call super constructor with method

I am trying to call the super constructor from a class using a method. The whole setup looks like this:
class Straight(hand: Hand) extends Combination(Straight.makeHandAceLowIfNeeded(hand), 5)
object Straight {
private def makeHandAceLowIfNeeded(hand: Hand): Hand = {
...
}
}
While this does compile, it has some rather odd runtime behaviour. While debugging, I noticed that the Straight instances have the "hand" property defined twice. Can somebody tell me what is going on, and what the proper way is to call the super constructor with different arguments?
In my use case, I want to call the super constructor with a modified hand in which I replaced a card compared to the original constructor argument.
Debugger screenshot with duplicate field:
.
It's a perfectly fine way to call the superclass constructor. These are two private fields and they don't conflict, though you can rename one of them to avoid confusion during debugging (or if you want to access the superclass' value from the subclass). However, the field should only be generated for a class parameter if it's used outside a constructor, and in your case it doesn't appear to be. Did you simplify the definition of Straight?

Using a class function to find a file, and include it so the class in that file can be used

So far this one seems to go against the grain of Php OOP. Let me explain further with an example.
class main has a function called get($name), what I would like get to do is based on the value of $name, (e.g. 'path/file') would find the corresponding file and include it, so the class in path/file can be used.
My goal with this and the reason I want to do this, is when I call $main->get('path/file'), I'd like an object returned of the class within the file, so far the only solution I can figure out is to use
include($main->get('path/file'));
And within said file would be an object defined outside the class body within path/file.php, but that doesn't really solve the issue as it limits me to using the object defined in that file, and I can only use this include call outside a class body. Does anyone have any ideas on how this can be approached?

Eclipse JDT AST: how to find a calling method returns value of an instance variable?

I'm using Eclipse JDT AST to parse a given java source code. While parsing the code, when it hits a method invocation, I want to find out whether that particular method returns or sets a value of an instance variable (basically to find out whether the callee method is a getter/setter of the same class of caller method).
E.g.:
public void test(){
//when parsing the following line I want to check whether "getName"
//returns a value of an instance variable.
String x = getName();
//when parsing the following line I want to check whether "setName"
//sets the value of an instance variable.
setName("some-name");
}
I've used the AST plugin also find out a possible path which would help me to refer it from the API, but couldn't.
Please let me know whether this is possible and if so, which approach that would help me to get the required information.
Don't think that there is an api which tells you whether a method is a getter or a setter.
You will have to write code to do this. For a getter, you can probably simply check if the last statement in the method is a return statement which returns an instance variable.