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
TextEditor
has a methodnewInstance()
which is called to acquire new editor instances byBWU Datagrid
(basicallyTextEditor
is a factory and the implementation in one).Because
TypeEditor
andAddressEditor
don't override this method, internally pureTextEditor
instances are created.To get the desired behavior you need to override
newInstance
and implement the constructor used by this method. Because the constructor inTextEditor
is 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
TypeEditor
is the same just a different class and constructor name.ORIGINAL
I'm pretty sure that the above example with
is
works fine and that the problem lies somewhere else (that these values are notAddressEditors
orTypeEditors
but justTextEditors
.output