@@ -14,6 +14,9 @@ const DocumentCommentSpecification _docCommentSpec =
1414/// Name for codec class.
1515const String _codecBaseName = 'MessageCodec' ;
1616
17+ /// Name of the standard codec from the Flutter SDK.
18+ const String _standardCodecName = 'FlStandardMessageCodec' ;
19+
1720/// Options that control how GObject code will be generated.
1821class GObjectOptions {
1922 /// Creates a [GObjectOptions] object
@@ -282,7 +285,12 @@ class GObjectHeaderGenerator extends StructuredGenerator<GObjectOptions> {
282285 Root root,
283286 Indent indent, {
284287 required String dartPackageName,
285- }) {}
288+ }) {
289+ final String module = _getModule (generatorOptions, dartPackageName);
290+ indent.newln ();
291+ _writeDeclareFinalType (indent, module, _codecBaseName,
292+ parentClassName: _standardCodecName);
293+ }
286294
287295 @override
288296 void writeFlutterApi (
@@ -508,6 +516,9 @@ class GObjectHeaderGenerator extends StructuredGenerator<GObjectOptions> {
508516 final String methodPrefix = _getMethodPrefix (module, api.name);
509517 final String vtableName = _getVTableName (module, api.name);
510518
519+ indent.newln ();
520+ _writeDeclareFinalType (indent, module, api.name);
521+
511522 final bool hasAsyncMethod =
512523 api.methods.any ((Method method) => method.isAsynchronous);
513524 if (hasAsyncMethod) {
@@ -950,13 +961,9 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
950961
951962 final Iterable <EnumeratedType > customTypes = getEnumeratedTypes (root);
952963
953- indent.newln ();
954- _writeDeclareFinalType (indent, module, _codecBaseName,
955- parentClassName: 'FlStandardMessageCodec' );
956-
957964 indent.newln ();
958965 _writeObjectStruct (indent, module, _codecBaseName, () {},
959- parentClassName: 'FlStandardMessageCodec' );
966+ parentClassName: _standardCodecName );
960967
961968 indent.newln ();
962969 _writeDefineType (indent, module, _codecBaseName,
@@ -971,7 +978,7 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
971978 ? '$customTypeName *'
972979 : 'FlValue*' ;
973980 indent.writeScoped (
974- 'static gboolean ${codecMethodPrefix }_write_$snakeCustomTypeName (FlStandardMessageCodec * codec, GByteArray* buffer, $valueType value, GError** error) {' ,
981+ 'static gboolean ${codecMethodPrefix }_write_$snakeCustomTypeName ($ _standardCodecName * codec, GByteArray* buffer, $valueType value, GError** error) {' ,
975982 '}' , () {
976983 indent.writeln ('uint8_t type = ${customType .enumeration };' );
977984 indent.writeln ('g_byte_array_append(buffer, &type, sizeof(uint8_t));' );
@@ -989,7 +996,7 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
989996
990997 indent.newln ();
991998 indent.writeScoped (
992- 'static gboolean ${codecMethodPrefix }_write_value(FlStandardMessageCodec * codec, GByteArray* buffer, FlValue* value, GError** error) {' ,
999+ 'static gboolean ${codecMethodPrefix }_write_value($ _standardCodecName * codec, GByteArray* buffer, FlValue* value, GError** error) {' ,
9931000 '}' , () {
9941001 indent.writeScoped (
9951002 'if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM) {' , '}' , () {
@@ -1027,7 +1034,7 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
10271034 _snakeCaseFromCamelCase (customTypeName);
10281035 indent.newln ();
10291036 indent.writeScoped (
1030- 'static FlValue* ${codecMethodPrefix }_read_$snakeCustomTypeName (FlStandardMessageCodec * codec, GBytes* buffer, size_t* offset, GError** error) {' ,
1037+ 'static FlValue* ${codecMethodPrefix }_read_$snakeCustomTypeName ($ _standardCodecName * codec, GBytes* buffer, size_t* offset, GError** error) {' ,
10311038 '}' , () {
10321039 if (customType.type == CustomTypes .customClass) {
10331040 indent.writeln (
@@ -1055,7 +1062,7 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
10551062
10561063 indent.newln ();
10571064 indent.writeScoped (
1058- 'static FlValue* ${codecMethodPrefix }_read_value_of_type(FlStandardMessageCodec * codec, GBytes* buffer, size_t* offset, int type, GError** error) {' ,
1065+ 'static FlValue* ${codecMethodPrefix }_read_value_of_type($ _standardCodecName * codec, GBytes* buffer, size_t* offset, int type, GError** error) {' ,
10591066 '}' , () {
10601067 indent.writeScoped ('switch (type) {' , '}' , () {
10611068 for (final EnumeratedType customType in customTypes) {
@@ -1473,9 +1480,6 @@ class GObjectSourceGenerator extends StructuredGenerator<GObjectOptions> {
14731480 });
14741481 }
14751482
1476- indent.newln ();
1477- _writeDeclareFinalType (indent, module, api.name);
1478-
14791483 indent.newln ();
14801484 _writeObjectStruct (indent, module, api.name, () {
14811485 indent.writeln ('const ${className }VTable* vtable;' );
0 commit comments