flutter常用小组件


  1. Container
Container(
  width: 200,
  height: 200,
  color: Colors.blue,
  child: Text('Hello'),
)
  1. Text
Text(
  'Hello, World!',
  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
)
  1. Image
Image.network(
  'https://example.com/image.jpg',
  width: 200,
  height: 200,
)
  1. ListView
ListView(
  children: <Widget>[
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
  ],
)
  1. Column
Column(
  children: <Widget>[
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
  ],
)
  1. Row
Row(
  children: <Widget>[
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
  ],
)
  1. Stack
Stack(
  children: <Widget>[
    Container(
      width: 200,
      height: 200,
      color: Colors.blue,
    ),
    Text('Hello'),
  ],
)
  1. AppBar
AppBar(
  title: Text('My App'),
  actions: <Widget>[
    IconButton(
      icon: Icon(Icons.settings),
      onPressed: () {
        // 打开设置页面
      },
    ),
  ],
)
  1. TextField
TextField(
  decoration: InputDecoration(
    labelText: '请输入用户名',
  ),
  onChanged: (value) {
    // 处理输入改变事件
  },
)
  1. Button
ElevatedButton(
  onPressed: () {
    // 按钮点击事件处理代码
    print("按钮被点击了");
  },
  child: Text('点击我'),
)
  1. 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('显示对话框'),
)
  1. SnackBar
ElevatedButton(
  onPressed: () {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text('操作成功'),
      ),
    );
  },
  child: Text('显示消息'),
)
  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃西瓜不吐籽_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值