Build: Simple Widget Tree Screen
This screen shows a basic widget tree with a title and two buttons arranged vertically.
Target UI
--------------------- | Simple Widget Tree | | | | [Button One] | | | | [Button Two] | | | ---------------------
--------------------- | Simple Widget Tree | | | | [Button One] | | | | [Button Two] | | | ---------------------
import 'package:flutter/material.dart'; class SimpleWidgetTreeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( // TODO: Add your widget tree here ), ); } }
import 'package:flutter/material.dart'; class SimpleWidgetTreeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text('Simple Widget Tree', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), SizedBox(height: 20), ElevatedButton( onPressed: () {}, child: Text('Button One'), ), SizedBox(height: 10), ElevatedButton( onPressed: () {}, child: Text('Button Two'), ), ], ), ), ); } }
We use a Center widget to center the whole column on the screen. Inside it, a Column arranges children vertically. The mainAxisAlignment and crossAxisAlignment center the children inside the column. We add a Text widget for the title, then two ElevatedButton widgets with labels. SizedBox widgets add space between elements for better look.
This simple widget tree shows how widgets nest inside each other to build UI.
--------------------- | Simple Widget Tree | | | | [Button One] | | | | [Button Two] | | | ---------------------
Column(
children: [
Text('A'),
Row(
children: [
Text('B'),
Text('C')
]
),
Text('D')
]
)Column(
children: [
Text('Hello'),
Icon(Icons.star),
Text('World')
]
mainAxisAlignment: MainAxisAlignment.center,
)Pass the test and this pattern moves unknown