cometchat-flutter-v5-theming

$npx mdskill add cometchat/cometchat-skills/cometchat-flutter-v5-theming

Customize visual appearance of CometChat Flutter UIKit v5 components.

  • Customize colors, spacing, and typography for CometChat v5 components.
  • Depends on CometChatColorPalette, CometChatSpacing, CometChatTypography, and ThemeExtension.
  • Uses CometChatThemeHelper to access and merge theme tokens.
  • Returns a custom theme object applied via Flutter's ThemeExtension system.

SKILL.md

.github/skills/cometchat-flutter-v5-themingView on GitHub ↗
---
name: cometchat-flutter-v5-theming
description: "Use when customizing the visual appearance of CometChat Flutter UIKit v5 components. Triggers on CometChatThemeHelper, CometChatColorPalette, CometChatSpacing, CometChatTypography, Style classes, merge()."
license: "MIT"
compatibility: "cometchat_uikit_shared ^5.2.3; flutter >=2.5.0"
metadata:
  author: "CometChat"
  version: "3.0.0"
  tags: "cometchat flutter v5 theme colors typography spacing dark-mode styling"
---

> **Ground truth:** `cometchat_chat_uikit: ^5.2` (legacy/maintenance-only; calls via raw `cometchat_calls_sdk ^5.0.2`) — pub-cache source + `ui-kit/flutter/v5`. **Official docs:** https://www.cometchat.com/docs/ui-kit/flutter/v5/overview · **Docs MCP:** `claude mcp add --transport http cometchat-docs https://www.cometchat.com/docs/mcp` (or fetch the URL directly without MCP). Verify symbols against the installed package/source before relying on them.

# CometChat Flutter UIKit v5 — Theming & Styling

How to customize the visual appearance of all CometChat v5 components.

## Theme System Architecture

Three layers, resolved via Flutter's `ThemeExtension` system:

1. `CometChatColorPalette` — colors (primary, neutral, alert, background, text, icon, button, border)
2. `CometChatSpacing` — spacing, padding, margin, and radius tokens
3. `CometChatTypography` — text styles (heading1-4, body, caption1-2, button, link, title)

Access via static helpers:
```dart
final colors = CometChatThemeHelper.getColorPalette(context);
final spacing = CometChatThemeHelper.getSpacing(context);
final typography = CometChatThemeHelper.getTypography(context);
```

**Important:** `getColorPalette()` creates a new object every call, resolving each token via `Theme.of(context)`. Cache in `didChangeDependencies()`, never call in `build()`.

## Applying a Custom Theme

Register `CometChatColorPalette` as a `ThemeExtension` on your `ThemeData`:

```dart
// ✅ CORRECT
MaterialApp(
  theme: ThemeData(
    extensions: [
      CometChatColorPalette(
        primary: const Color(0xFF6852D6),
        textPrimary: const Color(0xFF141414),
        textSecondary: const Color(0xFF727272),
      ),
    ],
  ),
  darkTheme: ThemeData(
    extensions: [
      CometChatColorPalette(
        primary: const Color(0xFF604CC3),
        textPrimary: const Color(0xFFFFFFFF),
        textSecondary: const Color(0xFFA0A0A0),
      ),
    ],
  ),
)
```

## Dark Mode

```dart
CometChatThemeMode.mode = ThemeMode.dark;   // Force dark
CometChatThemeMode.mode = ThemeMode.system;  // Follow system
```

## Commonly Used Color Tokens

| Token | Description | Light Default | Dark Default |
|-------|-------------|---------------|--------------|
| `primary` | Brand color | `#6852D6` | `#604CC3` |
| `background1`–`4` | Surface backgrounds | neutral50→neutral300 | neutral50→neutral300 |
| `textPrimary` | Main text | neutral900 | neutral900 |
| `textSecondary` | Secondary text | neutral600 | neutral600 |
| `borderLight` | Subtle borders | neutral200 | neutral200 |
| `iconPrimary` | Main icons | neutral900 | neutral900 |
| `iconSecondary` | Secondary icons | neutral500 | neutral500 |
| `iconHighlight` | Highlighted icons | primary | primary |
| `error` | Error states | `#F44649` | `#C73C3E` |
| `white` / `black` | Fixed (NOT brightness-aware) | `Colors.white` / `Colors.black` | Same |
| `transparent` | Transparent | `Colors.transparent` | Same |
| `neutral600` | Used for date styles | — | — |

Extended primary shades (`extendedPrimary50`–`900`) are auto-generated from `primary`. Override individually if needed.

## Commonly Used Spacing Tokens

| Token | Default |
|-------|---------|
| `padding` / `spacing` / `radius` | 2 |
| `padding1` / `spacing1` / `radius1` | 4 |
| `padding2` / `spacing2` / `radius2` | 8 |
| `padding3` / `spacing3` / `radius3` | 12 |
| `padding4` / `spacing4` / `radius4` | 16 |
| `padding5` / `spacing5` / `radius5` | 20 |
| `padding6` / `spacing6` | 24 |
| `radiusMax` / `spacingMax` | 1000 |

## Typography Tokens

`CometChatTypography` provides: `heading1`–`heading4`, `body`, `caption1`, `caption2`, `button`, `link`, `title`.

Each has `.bold`, `.medium`, `.regular` variants:
```dart
typography.body?.regular?.fontSize
typography.heading2?.bold?.fontWeight
typography.caption1?.regular?.fontFamily
```

## Theme Caching Pattern (from package source)

All UIKit components cache theme unconditionally in `didChangeDependencies()`:

```dart
// ✅ CORRECT — matches actual package pattern
@override
void didChangeDependencies() {
  super.didChangeDependencies();
  colorPalette = CometChatThemeHelper.getColorPalette(context);
  spacing = CometChatThemeHelper.getSpacing(context);
  typography = CometChatThemeHelper.getTypography(context);
}
```

Do NOT use a `_themeInitialized` flag — it prevents theme updates on system theme changes.

## Component Style Classes — merge() Pattern

Every component has a `CometChat{Component}Style` extending `ThemeExtension`. Resolved internally:

```dart
// Inside component's didChangeDependencies():
style = CometChatThemeHelper.getTheme<CometChatConversationsStyle>(
    context: context,
    defaultTheme: CometChatConversationsStyle.of,
).merge(widget.conversationsStyle);
```

Pass overrides via constructor:
```dart
CometChatConversations(
  conversationsStyle: CometChatConversationsStyle(
    backgroundColor: Colors.black,
  ),
)
```

## Gotchas

- `colorPalette.white` / `black` / `transparent` are NOT brightness-aware — use `neutral50` for brightness-aware white
- Extended primary shades auto-generated from `primary` by blending with white (light) or black (dark)

## Checklist — Theming

- [ ] Colors from `CometChatThemeHelper.getColorPalette(context)`, never hardcoded
- [ ] Theme cached in `didChangeDependencies()`, not `build()`
- [ ] Custom theme registered as `ThemeExtension` on both `theme` and `darkTheme`
- [ ] Component styles passed via constructor props

More from cometchat/cometchat-skills

SkillDescription
cometchatEntry-point for CometChat integration in any React, React Native, Angular, Android, Flutter, or iOS project — web (React/Next.js/React Router/Astro), React Native (Expo/bare), Angular (12-15), native Android (V6 stable, V5 legacy), Flutter (V6 stable, V5 legacy), and native iOS (V5 stable). Detects the framework, gathers requirements through an interactive conversation, and writes production-quality integration code.
cometchat-a11yAccessibility (a11y) for CometChat UI Kit integrations across all families — React, React Native, Angular, Android (V5/V6), iOS, Flutter. Covers WCAG 2.1 AA targets, keyboard navigation in chat, screen reader announcements (live regions for new messages), color contrast, focus management on call screens, motion-reduction support, and the cross-family checks that catch the common production a11y bugs. Cross-family — applies wherever the agent is checking accessibility.
cometchat-android-v5Entry-point dispatcher for CometChat Android UI Kit v5. Detects project setup, understands what the dev is building, and routes to the right sub-skills.
cometchat-android-v5-callsCometChat Calls SDK v5 integration for native Android (V5 stable, Java + Kotlin Views). Covers SDK setup (Cloudsmith Maven, CallAppSettings, init), the dual-SDK ringing pattern (Chat SDK initiateCall + Calls SDK joinSession), session settings, event listeners, call logs, recording, screen sharing, picture-in-picture, foreground service for ongoing calls, VoIP push via FCM + ConnectionService, audio/video/participant controls, custom UI, and in-call chat. Use in standalone mode (calls is the product) or additive mode (calls layered on top of an existing CometChat Android v5 chat integration).
cometchat-android-v5-componentsComplete catalog of CometChat Android UI Kit v5 components. Reference before writing integration code — never invent component names.
cometchat-android-v5-coreFoundational rules for CometChat Android UI Kit v5. Initialization, login, UIKitSettings builder, dependency setup, and anti-patterns. Read this first.
cometchat-android-v5-customizationCustomize CometChat components beyond theming — custom message templates, DataSource decorators, event listeners, and custom view slots.
cometchat-android-v5-extensionsExtension architecture for CometChat Android — ExtensionsDataSource, decorators, built-in extensions, and how to create custom extensions.
cometchat-android-v5-featuresAdd features (calls, reactions, polls, file sharing, AI, etc.) to an already-integrated CometChat project. Routes to the right sub-flow based on feature type.
cometchat-android-v5-placementWhere to put CometChat in your Android app — Activity, Fragment, BottomSheet, Dialog, Tab, or embedded patterns.