Flutter基础控件

Text:文字

Text("Flutter")

 Text是最常用也是最基础的,目前学习阶段只用来加载文字数据,更多属性和样式设置请查看源码自己探索。

Button:按钮

 ElevatedButton:普通按钮

ElevatedButton(
  onPressed: () {
    if (kDebugMode) {
      print("ElevatedButton");
    }
  },
  child: const Text("普通按钮"),
),

TextButton:文本按钮

TextButton(
  onPressed: () {
    if (kDebugMode) {
      print("TextButton");
    }
  },
  child: const Text("文本按钮"),
),

 OutlinedButton:带边框按钮

OutlinedButton(
  onPressed: () {
    if (kDebugMode) {
      print("OutlinedButton");
    }
  },
  child: const Text("带边框的按钮"),
),

 IconButton:图片按钮

IconButton(
  onPressed: () {
    if (kDebugMode) {
      print("IconButton");
    }
  },
  icon: const Icon(Icons.thumb_up),
)

 带图片的文本按钮,只需要在各控件后加.icon就可以了

ElevatedButton.icon(
  onPressed: () {
    if (kDebugMode) {
      print('点击了发送按钮');
    }
  },
  icon: const Icon(Icons.send),
  label: const Text("发送"),
),

 自定义样式按钮

 ElevatedButton(
   style: ButtonStyle(
     backgroundColor: MaterialStateProperty.all(Colors.red), //背景颜色
     foregroundColor:
         MaterialStateProperty.all(Colors.white), //文字图标颜色
   ),
   onPressed: () {
     if (kDebugMode) {
       print("ElevatedButton");
     }
   },
   child: const Text("普通按钮"),
 )

大按钮和设置按钮大小可以在容器里面设置按钮 

Container(
  width: 100,
  height: 60,
  margin: const EdgeInsets.all(10),
  child: ElevatedButton.icon(
    onPressed: () {},
    icon: const Icon(Icons.search),
    label: const Text("搜索"),
  ),

 加样式的各种圆角和边框按钮

Row(
  mainAxisAlignment: MainAxisAlignment.spaceAround,
  children: [
    ElevatedButton(
      style: ButtonStyle(
        shape: MaterialStateProperty.all(
          RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
        ),
      ),
      onPressed: () {},
      child: const Text("圆角"),
    ),
    ElevatedButton(
      style: ButtonStyle(
        shape: MaterialStateProperty.all(
          const RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

举儿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值