I am having this simple code, where I want to use the extension method within the Test Class.
Although I am not getting any code errors I am getting a compiling error.
I run this on https://dartpad.dartlang.org/ but got the following error:
Error compiling to JavaScript: main.dart:7:21: Error: Method not found: 'isTrue'. bool isItThough = isTrue(); ^^^^^^ Error: Compilation failed.
void main() {
//print(Test().isTrue);
print(Test().isItThough);
}
class Test {
bool isItThough = isTrue();
}
extension on Test {
bool isTrue() => true;
}
if you try to paste this code not in DartPad but IDE so may see a warning
The instance member 'isTrue' can't be accessed in an initializer.
so, as option, you can modify the code like this
class Test {
bool get isItThough => isTrue();
}
Related
I need help with an error I get while running a flutter project. I made a clone of
https://github.com/miketraverso/devfestapp.
After getting all the packages updated - I got the following error: Compiler message:
lib/views/scheduled_session_widget.dart:51:34: Error: The method '[]' isn't defined for the class 'dart.core::int'.
Try correcting the name to the name of an existing method, or defining a method named '[]'.
mSessions[sessionIter['0'].toString()]; // ignore: undefined_operator
Could someone explain what I could do to solve this error ?
It seems that sessions is collection of ints: List<int> sessions; in class TimeSlot, and later you have forEach on it so you can replace that code with:
timeSlot.sessions.forEach((sessionIter) {
Session session = mSessions[sessionIter.toString()];
if (session != null) {
Widget sessionCard = buildSessionCard(timeSlot, session);
sessionCards.add(sessionCard);
}
});
Just out of curiosity I tried to place a local class within one of my controller's actions, e.g.:
def index() {
class TestClass {
TestClass() {
// do something
}
doSomething() { ... }
}
TestClass test = new TestClass()
test.doSomething()
respond anything
}
However, compilation always fails giving me an error like this:
Error Compilation error: startup failed: class TestClass ...
^
Have you got any ideas?
You can't define classes inside methods
Move it outside the method
Why the next program produce the runtime error message "Error (R3) : Calling Function without definition !: init"
load "guilib.ring"
new qApp() {
new qWidget() {
setWindowTitle("First App!")
resize(400,400)
show()
}
exec()
}
The next code will fix your problem
Load "guilib.ring"
New qApp {
New qWidget() {
setWindowTitle("First App!")
resize(400,400)
show()
}
exec()
}
Using () after the class name means calling the init() method in the class and passing parameters to this method, using () while no init() method in the class will generate a runtime error message.
the class qApp don’t have this method while the other classes have it because they need it to create an object using a function that return a pointer to that object and this pointer will be stored in an attribute called pObject, for more information see ring_qt.ring file which contains the classes.
I started with a functioning bindings project, but I needed to add a global int for a status flag and I can't get it to bind without error. I started with the sample code and can't get this to work.
The code I add to my bindings file is:
[Static]
interface CameraEffects {
[Field ("kCameraEffectsZoomFactorKey", "CameraLibrary")]
NSString ZoomFactorKey { get; }
}
I get three errors:
obj/Debug/ios/PDFExpert/CameraEffects.g.cs(34,94): error CS0117: `MonoTouch.Constants' does not contain a definition for `CameraLibraryLibrary'
obj/Debug/ios/PDFExpert/CameraEffects.g.cs(34,76): error CS1502: The best overloaded method match for `MonoTouch.ObjCRuntime.Dlfcn.dlopen(string, int)' has some invalid arguments
obj/Debug/ios/PDFExpert/CameraEffects.g.cs(34,76): error CS1503: Argument `#1' cannot convert `object' expression to type `string'
If I leave the library off it tried to assign it to another unknown constant. This seems really screwed up as it is strait from the documentation.
I guess this should be bound like this
[Static]
interface CameraEffects {
[Field ("kCameraEffectsZoomFactorKey", "__Internal")]
NSString ZoomFactorKey { get; }
}
This is due to on the final app, the executable and the libxxx.a will be linked and merged together so it should work.
Alex
Another option that allows both assignment and retrieval of the value is to use the internal marshalling that MonoTouch uses. I got this from a Xamarin support person, notice that this is for manipulating an int, but should be a pattern you can use if you get the right marshalling code.
public unsafe static partial class RDPDFGlobal
{
static readonly IntPtr __Internal_libraryHandle = Dlfcn.dlopen (null, 0);
public static int RDPDFFeatures {
get {
return Dlfcn.GetInt32 (__Internal_libraryHandle, "RDPDFKitEnabledFeatures");
}
set {
var indirect = Dlfcn.dlsym (__Internal_libraryHandle, "RDPDFKitEnabledFeatures");
if (indirect == IntPtr.Zero)
throw new Exception ("Field 'RDPDFKitEnabledFeatures' not found.");
Marshal.WriteInt32 (indirect, value);
}
}
I've encountered a Groovy meta-programming problem which I'm unable to solve.
When adding the static method foo() to the class FooBar, then FooBar.foo() works as expected:
FooBar.metaClass.static.foo = {
println "hello"
}
FooBar.foo()
However, I instead add the same static method foo() to the class Object, then FooBar.foo() fails with an MissingMethodException:
Object.metaClass.static.foo = {
println "hello"
}
FooBar.foo()
// groovy.lang.MissingMethodException:
// No signature of method: FooBar.foo() is applicable for argument types:
// () values: []
Why is that? Shouldn't Object.metaClass.static.foo = { .. } add foo() also to FooBar?
In order to get the behavior you're looking for you need to call ExpandoMetaClass.enableGlobally()
Keep in mind doing this has a bigger memory footprint than normal meta-programming.
http://groovy.codehaus.org/api/groovy/lang/ExpandoMetaClass.html#enableGlobally()