GlassChart class
Wraps any chart widget — child can be an fl_chart LineChart,
BarChart, PieChart, a custom painter, or anything else — in a
properly-styled liquid glass surface, with an optional title and legend.
GlassChart(
title: 'Weekly Active Users',
legend: const [
GlassChartLegendEntry(color: Colors.blue, label: 'This week'),
GlassChartLegendEntry(color: Colors.grey, label: 'Last week'),
],
child: SizedBox(height: 220, child: LineChart(myChartData)),
)
GlassChart is chart-library-agnostic by design — it never imports
fl_chart or any other charting package, so adding it doesn't add a new
dependency to apps that don't chart anything. It just supplies glass
chrome and AdaptiveGlassText for the title/legend text it owns.
The chart library's own axis-tick labels are drawn by the chart library
itself, outside GlassChart's reach — for those, use
GlassChart.adaptiveAxisLabel in the chart's own label-builder callback
(e.g. fl_chart's SideTitles.getTitlesWidget) so tick labels get the
same backdrop-aware contrast as the title and legend:
SideTitles(
getTitlesWidget: (value, meta) =>
GlassChart.adaptiveAxisLabel(context, value.toStringAsFixed(0)),
)
Both title/legend text and adaptiveAxisLabel are built on
AdaptiveGlassText (in turn built on GlassLuminanceSampler) — the same
mechanism GlassA11yScope uses, applied here to a second, independent
consumer.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- GlassChart
Constructors
-
GlassChart({Key? key, required Widget child, String? title, (Color, Color)? titleColor, List<
GlassChartLegendEntry> ? legend, EdgeInsetsGeometry padding = const EdgeInsets.all(16), LiquidGlassSettings? settings, GlassQuality? quality, bool useOwnLayer = true}) -
Creates a glass chart surface around
child.const
Properties
- child → Widget
-
The chart content.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
legend
→ List<
GlassChartLegendEntry> ? -
Optional legend rows shown below child.
final
- padding → EdgeInsetsGeometry
-
Padding around the whole surface.
final
- quality → GlassQuality?
-
Rendering quality for the glass effect.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- settings → LiquidGlassSettings?
-
Custom glass settings for the surface.
final
- title → String?
-
Optional title shown above child.
final
- titleColor → (Color, Color)?
-
Light/dark color pair for title. Defaults to label/secondaryLabel
Cupertino colors.
final
- useOwnLayer → bool
-
Whether to create its own layer or use grouped glass.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
adaptiveAxisLabel(
BuildContext context, String text, {Color? lightColor, Color? darkColor, TextStyle? style}) → Widget - Builds a chart axis-tick label with the same backdrop-aware contrast as GlassChart's own title/legend text.