Flutter框架跨平台鸿蒙开发——Button组件基础

一、Button组件概述

Flutter提供了多种按钮组件,满足不同场景的需求。

Button类型

Button组件
ElevatedButton
TextButton
OutlinedButton
IconButton
FloatingActionButton

二、ElevatedButton

基础用法

dart 复制代码
ElevatedButton(
  onPressed: () {},
  child: Text('点击'),
)

带图标的按钮

dart 复制代码
ElevatedButton.icon(
  icon: Icon(Icons.add),
  label: Text('添加'),
  onPressed: () {},
)

三、TextButton

基础用法

dart 复制代码
TextButton(
  onPressed: () {},
  child: Text('文本按钮'),
)

四、OutlinedButton

基础用法

dart 复制代码
OutlinedButton(
  onPressed: () {},
  child: Text('轮廓按钮'),
)

五、完整示例

dart 复制代码
class ButtonBasicsExample extends StatelessWidget {
  const ButtonBasicsExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Button基础')),
      body: ListView(
        padding: EdgeInsets.all(16),
        children: [
          Card(
            child: Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('ElevatedButton'),
                  SizedBox(height: 16),
                  Row(
                    children: [
                      ElevatedButton(
                        onPressed: () {},
                        child: Text('普通'),
                      ),
                      SizedBox(width: 16),
                      ElevatedButton.icon(
                        icon: Icon(Icons.add),
                        label: Text('带图标'),
                        onPressed: () {},
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
          SizedBox(height: 16),
          Card(
            child: Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('TextButton'),
                  SizedBox(height: 16),
                  TextButton(
                    onPressed: () {},
                    child: Text('文本按钮'),
                  ),
                ],
              ),
            ),
          ),
          SizedBox(height: 16),
          Card(
            child: Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('OutlinedButton'),
                  SizedBox(height: 16),
                  OutlinedButton(
                    onPressed: () {},
                    child: Text('轮廓按钮'),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

欢迎加入开源鸿蒙跨平台社区:https://openharmonycrossplatform.csdn.net

相关推荐
四眼肥鱼5 小时前
flutter 利用flutter_libserialport 实现SQ800 串口通信
前端·flutter
二流小码农6 小时前
鸿蒙开发:上传一张参考图片便可实现页面功能
android·ios·harmonyos
万少16 小时前
HarmonyOS 开发必会 5 种 Builder 详解
前端·harmonyos
火柴就是我20 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
王晓枫21 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
shankss1 天前
Flutter 下拉刷新库 pull_to_refresh_plus 设计与实现分析
flutter
Huang兄1 天前
鸿蒙-List和Grid拖拽排序:仿微信小程序删除效果
harmonyos·arkts·arkui
忆江南2 天前
iOS 深度解析
flutter·ios
明君879972 天前
Flutter 实现 AI 聊天页面 —— 记一次 Markdown 数学公式显示的踩坑之旅
前端·flutter
恋猫de小郭2 天前
移动端开发稳了?AI 目前还无法取代客户端开发,小红书的论文告诉你数据
前端·flutter·ai编程