首页
Preview

Flutter封装组件之:常用标题组件

常用标题GRTitle组件

Simulator Screen Shot - iPhone 14 Pro Max - 2022-12-24 at 17.34.51.png

使用方法

GRTitle(
  leftTitle: '可点击右侧',
  leftIcon: Icon(Icons.bookmark_border),
  rightTitle: '换一换',
  onTap: (){print('1111');},
  rightIcon: Icon(Icons.refresh,color: Colors.black45,size: 18),
),
//设置颜色
GRTitle(
  leftTitle: '有图标标题',
  leftTitleColor: Colors.red,
  leftIcon: Icon(Icons.bookmark_border),
  rightTitle: '查看更多',
  rightIcon: Icon(Icons.chevron_right,color: Colors.black45),
  rightTitleColor: Colors.green,
),

组件参数

参数名描述
leftTitle左边标题
leftTitleSize左边标题大小
leftTitleColor左边标题颜色
leftIcon左边图标
rightTitle右边标题
rightTitleSize右边标题大小
rightTitleColor右边标题颜色
rightIcon右边图标
onTap右边可点击事件

组件源码

  • 自定义标题组件 GRTitle
/**
 * author: jing
 * created on: 2022/12/24 15:40
 * description: 自定义标题组件
 */
import 'package:flutter/material.dart';
class GRTitle extends StatelessWidget {
  const GRTitle({
    Key? key,
    this.onTap,
    this.leftTitle = '左边标题',
    this.leftTitleColor = const Color(0xFF000000),
    this.leftIcon,
    this.rightTitle = '更多',
    this.rightTitleColor = const Color(0x8A000000),
    this.rightIcon,
    this.leftTitleSize = 16,
    this.rightTitleSize = 14,
  }) : super(key: key);
  //点击事件
  final VoidCallback? onTap;
  //左边标题
  final String leftTitle;
  //左边标题大小
  final double leftTitleSize;
  //左边标题颜色
  final Color leftTitleColor;
  //左边图标
  final Widget? leftIcon;
  //右边标题
  final String? rightTitle;
  //右边标题颜色
  final Color rightTitleColor;
  //右边标题大小
  final double rightTitleSize;
  //右边图标
  final Widget? rightIcon;
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Row(
          children: [
            leftIcon ?? Container(),
            //如果觉得间距不够大可以加上
            // const SizedBox(width: 5.0),
            Text(leftTitle,style: TextStyle(fontSize: leftTitleSize,color: leftTitleColor),)
          ],
        ),
        GestureDetector(
          onTap:onTap,
          child: Row(
            children: [
              Text(rightTitle!,style: TextStyle(fontSize: rightTitleSize,color: rightTitleColor),),
              // const SizedBox(width: 5.0),
              rightIcon ?? Container(),
            ],
          ),
        )
      ],
    );
  }
}

版权声明:本文内容由TeHub注册用户自发贡献,版权归原作者所有,TeHub社区不拥有其著作权,亦不承担相应法律责任。 如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

点赞(0)
收藏(0)
小橙子
大概是个无趣的人。

评论(0)

添加评论