Container
:
Container(
width: 200,
height: 200,
color: Colors.blue,
child: Text('Hello'),
)
Text
:
Text(
'Hello, World!',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
)
Image
:
Image.network(
'https://example.com/image.jpg',
width: 200,
height: 200,
)
ListView
:
ListView(
children: <Widget>[
Text('Item 1'),
Text('Item 2'),
Text('Item 3'),
],
)
Column
:
Column(
children: <Widget>[
Text('Item 1'),
Text('Item 2'),
Text('Item 3'),
],
)
Row
:
Row(
children: <Widget>[
Text('Item 1'),
Text('Item 2'),
Text('Item 3'),
],
)
Stack
:
Stack(
children: <Widget>[
Container(
width: 200,
height: 200,
color: Colors.blue,
),
Text('Hello'),
],
)
AppBar
:
AppBar(
title: Text('My App'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () {
},
),
],
)
TextField
:
TextField(
decoration: InputDecoration(
labelText: '请输入用户名',
),
onChanged: (value) {
},
)
Button
:
ElevatedButton(
onPressed: () {
print("按钮被点击了");
},
child: Text('点击我'),
)
AlertDialog
:
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('提示'),
content: Text('确定要删除吗?'),
actions: <Widget>[
TextButton(
child: Text('取消'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('确定'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
},
child: Text('显示对话框'),
)
SnackBar
:
ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('操作成功'),
),
);
},
child: Text('显示消息'),
)