I have the following types:
class AddressEditor extends TextEditor {}
class TypeEditor extends TextEditor {}
I tried to identify the editors as such:
void validationErrorHandler( ValidationError e )
{
var editor = e.editor;
if( editor is AddressEditor )
print( editor.runtimeType.toString() ) // prints TextEditor
if( editor is TypeEditor )
print( editor.runtimeType.toString() ) // prints TextEditor
}
If I use mirrors
import 'dart:mirrors';
getTypeName(dynamic obj)
{
return reflect(obj).type.reflectedType.toString();
}
void validationErrorHandler( ValidationError e )
{
var editor = e.editor;
if( editor is AddressEditor )
print( getTypeName( editor ) ) // prints TextEditor
if( editor is TypeEditor )
print( getTypeName( editor ) ) // prints TextEditor
}
Why is the editor type TypeEditor and AddressEditor not being identified? Yes, I know that either is a TextEditor, but is there any way to identify the TypeEditor or the AddressEditor in Dart.
I need to make these identification to work with the result of the validation.
Thanks
UPDATE
It turns out that
TextEditorhas a methodnewInstance()which is called to acquire new editor instances byBWU Datagrid(basicallyTextEditoris a factory and the implementation in one).Because
TypeEditorandAddressEditordon't override this method, internally pureTextEditorinstances are created.To get the desired behavior you need to override
newInstanceand implement the constructor used by this method. Because the constructor inTextEditoris private it can not be reused and needs to be copied (I'll reconsider this design). The first two lines of the copied constructor need to be adapted a little.The AddressEditor would then look like
The
TypeEditoris the same just a different class and constructor name.ORIGINAL
I'm pretty sure that the above example with
isworks fine and that the problem lies somewhere else (that these values are notAddressEditorsorTypeEditorsbut justTextEditors.output