antd_theme 0.1.0-beta.1
antd_theme: ^0.1.0-beta.1 copied to clipboard
Ant Design v6 theme system for Flutter. Theme data, shadow tokens, responsive breakpoints, and screen adaptation.
antd_theme #
Ant Design v6 theme system for Flutter — theme data, theme injection, responsive breakpoints, and screen adaptation, built on top of antd_tokens and antd_color.
Beta — This package is under active development. APIs may change before the stable release.
Features #
- AntThemeData — Complete theme data generated from a seed token via the antd Seed → Map → Alias derivation chain. Provides
light(),dark(), andfromSeed()factories, plus convenient accessors for every alias token (colors, fonts, radius, sizes, control heights, spacing, line widths, motion, shadows, z-index, screen breakpoints). - AntTheme / AntThemeBuilder —
InheritedWidgetthat injectsAntThemeDatainto the widget tree. Retrieve the current theme withAntTheme.of(context)or useAntThemeBuilderfor a build-time shortcut. - AntBreakpoint / AntBreakpoints — antd responsive breakpoint enum (xs ~ xxxl) with
fromWidth/ofand comparison operators, plusisUp/isDown/isBetweenutilities. - AntScreenUtilInit — Screen adaptation wrapper around
flutter_screenutilwith built-in desktop auto-adaptation (scale factor = 1 on desktop). Only.w/.sp/.rextensions are supported.
Getting started #
dependencies:
antd_theme: ^0.1.0-beta.1
import 'package:antd_theme/antd_theme.dart';
Usage #
Theme data #
// Default light theme — identical to antd defaults
final light = AntThemeData.light();
// Dark theme
final dark = AntThemeData.dark();
// Custom seed
final custom = AntThemeData.fromSeed(
const AntSeedToken(colorPrimary: '#722ed1', borderRadius: 8),
);
// Access tokens directly
Container(
color: light.colorBgContainer,
padding: EdgeInsets.all(light.padding),
child: Text(
'Hello',
style: TextStyle(
fontSize: light.fontSizeLG,
color: light.colorText,
),
),
);
Theme injection #
AntTheme(
data: AntThemeData.light(),
child: MaterialApp(
home: AntThemeBuilder(builder: (context, theme) {
return Scaffold(
backgroundColor: theme.colorBgLayout,
body: Center(
child: Text(
'Themed!',
style: TextStyle(color: theme.colorPrimary),
),
),
);
}),
),
);
Responsive breakpoints #
// Current breakpoint from context
final bp = AntBreakpoint.of(context);
if (bp >= AntBreakpoint.md) {
// ≥768 layout
}
// Utility checks
if (AntBreakpoints.isDown(context, AntBreakpoint.sm)) {
// <576 mobile layout
}
if (AntBreakpoints.isBetween(context, AntBreakpoint.md, AntBreakpoint.lg)) {
// 768 ≤ width < 992
}
Screen adaptation #
AntScreenUtilInit(
builder: (context, child) => AntTheme(
data: AntThemeData.light(),
child: MaterialApp(...),
),
);
// Use .w / .sp / .r extensions (never .h)
SizedBox(width: 100.w);
Text('Hello', style: TextStyle(fontSize: 14.sp));
BorderRadius.circular(6.r);
On desktop (window width ≥ 768 by default), the scale factor is automatically set to 1 so components keep their logical pixel sizes. Set desktopBreakpoint: null to disable this behavior.
License #
MIT