Stockholm UI Library

repository·master·Indexed 40 days ago

https://github.com/serverpod/stockholm

A desktop-optimized UI library providing widgets and themes for macOS and Windows, specifically tailored for the Serverpod GUI ecosystem. It includes specialized components such as StockholmButton, StockholmPopupMenuButton, StockholmPropertyInspector, and constrained input widgets for integers, doubles, and booleans.

Tokens
6.5K
Snippets
26
Records
33
Agent score
49%

What's inside Stockholm

  1. Overview of Stockholm widgets and themes

    master
    Stockholm is a collection of desktop-first widgets and themes optimized for macOS and Windows. The library provides UI components that feel comfortable on desktop platforms without attempting to perfectly replicate native OS components. It is primarily designed for use with the Serverpod GUI.
  2. How to use Stockholm widgets and themes

    master
    Stockholm widgets are designed to be used with specific theme classes. To ensure the UI renders correctly and looks as intended, you must use the provided theme classes. For a complete implementation guide, refer to the example project which demonstrates the usage of all available widgets.
  3. How StockholmPropertyInspector context works

    master
    The StockholmPropertyInspector acts as a provider for layout configuration. Specialized property widgets use StockholmPropertyInspector.of(context) to look up the nearest ancestor inspector. This allows child widgets to automatically adjust their alignment, padding, and name widths to match the parent inspector's configuration without manual passing of parameters.
  4. Display single-line properties with StockholmPIOneLineProp

    master

    Use StockholmPIOneLineProp for simple key-value pairs that fit on a single line. It aligns the property name and the value widget side-by-side.

    • name: The label for the property.
    • value: The widget displaying the value.
    • nameAlignment: The alignment of the name text (defaults to TextAlign.end).
    StockholmPIOneLineProp(
      name: 'Username',
      value: Text('jdoe'),
      nameAlignment: TextAlign.start,
    );
  5. Use the StockholmButton widget

    master

    The StockholmButton is a styled Material button used for primary actions. It supports different visual states such as important (primary color) and large (increased height and text style). It automatically adjusts its border radius based on the platform (Windows uses a radius of 3, others use 6).

    StockholmButton(
      onPressed: () => print('Pressed!'),
      child: Text('Click Me'),
      important: true,
      large: true,
      padding: EdgeInsets.symmetric(horizontal: 16),
    )
  6. Use the StockholmToolbarButton widget

    master

    The StockholmToolbarButton is a specialized button designed for use within a StockholmToolbar. It can display an icon, an optional text label, or both.

    Properties

    • icon: (Required) The IconData to display.
    • onPressed: (Required) The callback function triggered when the button is pressed.
    • label: An optional string to display next to the icon.
    • minWidth: The minimum width of the button (defaults to 32.0).
    • color: The color of the icon. If null, it uses the theme's iconTheme.color.
    • selected: A boolean that, if true, applies the theme's highlightColor to the button background.
    • iconSize: The size of the icon (defaults to 18.0).
    • iconScale: A multiplier to scale the icon via Transform.scale (defaults to 1.0).
    • padding: The internal padding of the button (defaults to EdgeInsets.symmetric(horizontal: 8)).
    • height: The height of the button (defaults to 32.0).
    StockholmToolbarButton(
      icon: Icons.settings,
      label: 'Settings',
      onPressed: () => handleSettings(),
      selected: isSettingsOpen,
    )
  7. Lighten or darken colors using ColorExt

    master

    The ColorExt extension adds utility methods to any Flutter Color to adjust its lightness using HSL manipulation.

    • darken([double amount = .1]): Returns a new color with reduced lightness. amount must be between 0.0 and 1.0.
    • lighten([double amount = .1]): Returns a new color with increased lightness. amount must be between 0.0 and 1.0.
    Color baseColor = Colors.blue;
    Color darkerColor = baseColor.darken(0.2);
    Color lighterColor = baseColor.lighten(0.1);
  8. Display lists of items with StockholmPIListProp

    master

    Use StockholmPIListProp to display a collection of widgets within a scrollable, styled container inside the inspector. If the list is empty or null, it displays a fallback text.

    • name: The label for the list.
    • fallbackText: Text to show when the list is empty.
    • list: The list of widgets to display.
    • height: The height of the list container (defaults to 200.0).
    • trailing: An optional widget to display next to the name.
    StockholmPIListProp(
      name: 'Tags',
      fallbackText: 'No tags assigned',
      list: [
        Text('Flutter'),
        Text('Dart'),
      ],
    );
  9. Use the StockholmToolbar widget

    master

    The StockholmToolbar is a container widget used to display a row of interactive elements or information. It supports different placements and automatic border styling based on its position.

    Configuration

    • children: A list of widgets to display in the toolbar.
    • backgroundColor: An optional color for the toolbar background.
    • placement: Determines where the toolbar is located and which border side is drawn. Use StockholmToolbarPlacement.top or StockholmToolbarPlacement.bottom.

    When placement is top, a bottom border is drawn using the theme's dividerColor. When bottom, a top border is drawn.

    StockholmToolbar(
      placement: StockholmToolbarPlacement.top,
      backgroundColor: Colors.white,
      children: [
        StockholmToolbarButton(
          icon: Icons.add,
          onPressed: () => print('Added'),
        ),
      ],
    )
  10. Use StockholmPICheckboxProp for boolean values

    master

    Use StockholmPICheckboxProp to display an interactive checkbox for boolean properties.

    • name: The label for the checkbox.
    • value: The current boolean state.
    • onChanged: Callback triggered when the user toggles the checkbox.
    • enabled: Whether the checkbox is interactive (defaults to true).
    StockholmPICheckboxProp(
      name: 'Active',
      value: isActive,
      onChanged: (bool? newValue) {
        setState(() => isActive = newValue ?? false);
      },
    );
  11. showStockholmProgressDialog

    master

    A helper function to display a StockholmProgressDialog using Flutter's showDialog. It sets barrierDismissible: false by default, ensuring the user cannot dismiss the progress dialog by tapping outside of it.

    showStockholmProgressDialog(
      context: context,
      builder: (context) => StockholmProgressDialog(
        title: Text('Title'),
        controller: myController,
      ),
    );
  12. Display multi-line or large properties with StockholmPILargeProp

    master

    Use StockholmPILargeProp when a property value requires more space (e.g., a large text block or a nested list). The name is placed above the value, and the value can span multiple lines.

    • name: The label for the property.
    • value: The widget containing the large value.
    • trailing: An optional widget to display on the same line as the name (e.g., an icon or badge).
    StockholmPILargeProp(
      name: 'Description',
      value: Text('This is a very long description that needs multiple lines.'),
      trailing: Icon(Icons.info),
    );