diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs index 4e34035cc6..08fc97fd9b 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs @@ -40,6 +40,7 @@ pub(crate) struct ApiDartOutputSpecItem { pub funcs: Vec, pub classes: Vec, pub imports: DartBasicHeaderCode, + pub preamble: String, pub unused_types: Vec, pub needs_freezed: bool, } @@ -134,6 +135,7 @@ fn generate_item( funcs, classes, imports, + preamble: context.config.dart_preamble.clone(), unused_types, needs_freezed, }) diff --git a/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs b/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs index dca717eaaf..9aef083dd6 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/text_generator.rs @@ -59,8 +59,10 @@ fn generate_end_api_text( // TODO use relative path calculation let path_frb_generated = "../".repeat(path_chunks_len - 2) + "frb_generated.dart"; + let preamble = &item.preamble.as_str(); let mut header = DartBasicHeaderCode { file_top: generate_code_header() + + if !preamble.is_empty() {"\n\n"} else {""} + preamble + "\n\n// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import\n", import: format!( "