Skip to main content
Glama
parser.js1.28 kB
export function parseFlutterCode(code) { const structure = { widgets: [], methods: [], classes: [], imports: [], }; const importRegex = /import\s+['"]([^'"]+)['"]/g; const classRegex = /class\s+(\w+)\s+extends\s+(\w+)/g; const methodRegex = /(\w+)\s+(\w+)\s*\([^)]*\)\s*(?:async\s*)?\{/g; const widgetRegex = /(\w+)\s*\(/g; let match; while ((match = importRegex.exec(code)) !== null) { structure.imports.push(match[1]); } while ((match = classRegex.exec(code)) !== null) { structure.classes.push({ name: match[1], extends: match[2], isStateful: match[2] === 'StatefulWidget', isStateless: match[2] === 'StatelessWidget', }); } while ((match = methodRegex.exec(code)) !== null) { structure.methods.push({ returnType: match[1], name: match[2], isAsync: code.substring(match.index, match.index + 100).includes('async'), }); } const flutterWidgets = new Set([ 'Container', 'Row', 'Column', 'Stack', 'Scaffold', 'Text', 'Image', 'Icon', 'Button', 'ListView', ]); while ((match = widgetRegex.exec(code)) !== null) { if (flutterWidgets.has(match[1]) || match[1].endsWith('Widget')) { structure.widgets.push(match[1]); } } return structure; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dvillegastech/flutter_mcp_2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server