Flutter自定义卡片标题插件phoenix_card_title的使用

Flutter自定义卡片标题插件phoenix_card_title的使用

描述

phoenix_card_title 是一个用于创建自定义卡片标题的 Flutter 插件。它提供了灵活的配置选项,可以轻松地定制标题的样式和行为。

特性

  • 支持自定义标题文本样式。
  • 支持添加副标题或辅助信息。
  • 提供点击事件回调功能。
  • 可以设置箭头图标。

开始使用

添加依赖

pubspec.yaml 文件中添加以下依赖:

dependencies:
  phoenix_card_title: ^版本号

然后运行 flutter pub get 来安装依赖。

初始化

在应用启动时,需要初始化 BaseInit,并配置 CardTitleTotalConfig 来设置全局样式。

[@override](/user/override)
void initState() {
  super.initState();
  
  // 初始化全局配置
  BaseTotalConfig totalConfig = BaseTotalConfig();

  CardTitleTotalConfig titleTotalConfig = CardTitleTotalConfig(
      cardTitleConfig: CardTitleConfig(
          accessoryTextStyle: BaseTextStyle(color: Colors.red),
          detailTextStyle: BaseTextStyle(color: Colors.red),
          titleTextStyle: BaseTextStyle(color: Colors.red)));
  totalConfig.cardTitleTotalConfig = titleTotalConfig;

  BaseInit.register(totalConfig: totalConfig);
}

使用示例

以下是一个完整的示例代码,展示了如何使用 phoenix_card_title 插件来创建自定义卡片标题。

import 'package:flutter/material.dart';
import 'package:phoenix_card_title/phoenix_card_title.dart';
import 'package:phoenix_base/phoenix.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: TitleExample(),
    );
  }
}

class TitleExample extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('自定义卡片标题示例'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // 箭头标题
            ActionCardTitle(
              title: '箭头标题',
              onTap: () {
                // 点击事件处理
                print('ActionCardTitle is clicked');
              },
            ),

            // 非箭头标题
            CommonCardTitle(
              title: '非箭头非箭头',
              accessoryText: '状态标签',
              subTitleWidget: const Text('subTitle'),
              onTap: () {
                // 点击事件处理
                print('CommonCardTitle is clicked');
              },
            ),

            // 带详情文本的标题
            CommonCardTitle(
              title: '非箭头Title',
              detailTextString: '房产证地址与楼盘字房产证地址与楼盘字房产证地址与楼盘字房产证地址与楼盘字',
              subTitleWidget: const Text('subTitle'),
              onTap: () {
                // 点击事件处理
                print('CommonCardTitle with detail text is clicked');
              },
            )
          ],
        ),
      ),
    );
  }
}

更多关于Flutter自定义卡片标题插件phoenix_card_title的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter自定义卡片标题插件phoenix_card_title的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


phoenix_card_title 是一个 Flutter 插件,用于创建自定义卡片标题。它提供了丰富的样式和配置选项,可以轻松地在 Flutter 应用中创建漂亮的卡片标题。

安装插件

首先,你需要在 pubspec.yaml 文件中添加 phoenix_card_title 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  phoenix_card_title: ^0.0.1  # 请根据实际情况使用最新版本

然后运行 flutter pub get 来安装插件。

使用 phoenix_card_title 插件

在你的 Dart 文件中导入 phoenix_card_title 插件:

import 'package:phoenix_card_title/phoenix_card_title.dart';

然后你可以使用 PhoenixCardTitle 组件来创建一个自定义的卡片标题。

示例代码

以下是一个简单的示例,展示如何使用 PhoenixCardTitle 插件:

import 'package:flutter/material.dart';
import 'package:phoenix_card_title/phoenix_card_title.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Phoenix Card Title Example'),
        ),
        body: Center(
          child: PhoenixCardTitle(
            title: 'Card Title',
            subtitle: 'This is a subtitle',
            backgroundColor: Colors.blue,
            titleStyle: TextStyle(
              color: Colors.white,
              fontSize: 20,
              fontWeight: FontWeight.bold,
            ),
            subtitleStyle: TextStyle(
              color: Colors.white70,
              fontSize: 14,
            ),
            onTap: () {
              print('Card Title Tapped!');
            },
          ),
        ),
      ),
    );
  }
}
回到顶部