Use Named Sections for Manipulation
mainNamed sections allow you to target specific parts of the code.
- Define in code: Use comments like
// [START section_name]and// [END section_name]. - Parse in controller: Pass a parser like
BracketsStartEndNamedSectionParserto theCodeController.
Sections can be used to make specific parts of the code read-only or to hide everything except that section.
final text = '''
class MyClass {
// [START section1]
void myMethod() {}
// [END section1]
}
''';
final controller = CodeController(
text: text,
language: java,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
);