Extension Syntax

Extension Syntax

Accessing the theme

All theming related properties are accessable through the context, using sensible naming conventions.

Context Extensions
  // Color examples
  // Styling examples;;;;
  // Dimensions examples;;
  // With responsive helper
  context.responsive(desktop: context.borderRadius.lg) ??;

Widget Modifiers

You can always apply styling directly to widgets using parameters like background and style directly. However for some some properties you can use extensions on the widget.

Right now this is limited to:

  • Setting the background color for surfaces inside widgets
  • Setting the foreground color inside widgets
  • Setting the text/icon style inside widgets

There are two reasons you might use this syntax:

  • You like how it looks and reads
  • You want to apply styles to all children of a layout widget such as a Row

Under the hood, these modifiers work by using a DefaultSurfaceStyle or DefaultSymbolStyle widget, which is why you can use them to style all children of the applied widget.

Widget Extensions
  // Heading with primary color
  Text('A heading').withStyleHeading().withColorPrimary(),
  // Create a button with a primary background and a text/icon style of heading
    onTap: () => print('Submit something'),
    label: 'Submit',
  // Makes every button within the row have a primary background and a text/icon style of heading
    children: [
        onTap: () => print('Submit something'),
        label: 'Submit',
        onTap: () => print('Cancel something'),
        label: 'Cancel',

Widget Creation

In the case of the Strings and IconData types, you can use extensions to create a Text and Icon widget respectively.

This provides little benefit besides subjective readablility but it is still an option.

Widget Creation
  // Create a Text widget with a heading style
  'A heading'.asHeading(),
  // Create an Icon widget with a display size
  // Once the Icon or Text widget has been created, you can style it further as needed.