flutterWidgetDeclaration method
Implementation
AstWidget flutterWidgetDeclaration() {
Token name =
consume(TokenType.identifier, "Expect widget name after 'flutter::'.");
final parameters = _parseParameterNodes();
switch (name.lexeme) {
case 'Text':
return Text(name, parameters['text']!);
case 'Column':
return Column(name, parameters['children']!);
case 'Row':
return Row(name, parameters['children']!);
case 'Container':
return Container(name, parameters['child'] as AstWidget);
case 'Image':
return Image(name, parameters['url']!);
case 'Padding':
return Padding(name, parameters['padding'] as EdgeInsets,
parameters['child'] as AstWidget);
case 'Center':
return Center(name, parameters['child'] as AstWidget);
case 'SizedBox':
return SizedBox(name,
width: parameters['width'],
height: parameters['height'],
child: parameters['child'] as AstWidget?);
case 'Expanded':
return Expanded(
name,
parameters['child'] as AstWidget,
parameters['flex'],
);
case 'ElevatedButton':
return ElevatedButton(name, parameters['child'] as AstWidget,
parameters['onPressed'] as FunctionDeclaration);
case 'Card':
return Card(
name, parameters['child'] as AstWidget, parameters['elevation']);
case 'ListView':
return ListView(name, parameters['children'] as AstNode);
case 'GridView':
final optionalParam = parameters['maxCrossAxisExtent'];
final mainCrossAxisExtent = optionalParam ?? const Literal(100.0);
return GridView(
name, parameters['children'] as AstNode, mainCrossAxisExtent);
case 'ListViewBuilder':
return ListViewBuilder(
name,
parameters['itemBuilder'] as FunctionDeclaration,
parameters['itemCount'] as AstNode);
case 'GridViewBuilder':
final optionalParam = parameters['maxCrossAxisExtent'];
final mainCrossAxisExtent = optionalParam ?? const Literal(100.0);
return GridViewBuilder(
name,
parameters['itemBuilder'] as FunctionDeclaration,
parameters['itemCount'] as AstNode,
mainCrossAxisExtent);
default:
throw error(name, "Unknown Flutter widget: ${name.lexeme}");
}
}