fluent_ui

repository·master·Indexed 25 days ago

https://github.com/bdlukaa/fluent_ui

An unofficial implementation of Windows UI for Flutter based on official Microsoft Windows UI documentation. It provides a set of widgets, including Checkbox, Slider, and SplitButton, to help developers build native-looking Windows applications. The library supports extensive localization and customizable themes via FluentThemeData.

Tokens
5K
Snippets
14
Records
30
Agent score
85%

What's inside fluent_ui

  1. Run the fluent_ui showcase app

    master

    To run the showcase application for fluent_ui, you must first generate the platform-specific build files and then execute the application using the Flutter CLI.

    1. Generate platform-specific builds: flutter create .
    2. Run the application: flutter run
    flutter create .
    flutter run
  2. Install fluent_ui

    master

    Add fluent_ui to your Flutter project's dependencies. It is recommended to use the stable channel of Flutter when using this library.

    You can install it via pub.dev or directly from the GitHub repository.

    dependencies:
      fluent_ui: ^4.15.1

    OR

    dependencies:
      fluent_ui:
        git: https://github.com/bdlukaa/fluent_ui.git
  3. Add support for a new language localization

    master

    To contribute a new language localization to fluent_ui, follow these steps:

    1. Fork the repository.
    2. Copy the lib/l10n/intl_en.arb file into the lib/l10n folder using a new language code (following ISO 859-1 codes).
    3. Update the contents of the new .arb file, ensuring you update the @locale value with the corresponding ISO code.
    4. Run flutter gen-l10n or run your project to trigger code generation.
    5. Submit a pull request.
  4. Use the Expander widget

    master

    The Expander widget allows you to show or hide secondary content related to a primary header. The header remains visible, while the content area expands or collapses when the header is interacted with. It supports expanding either downwards or upwards and can contain complex, interactive UI, including nested expanders.

    Key features:

    • State Management: Maintains its own expanded/collapsed state. Use initiallyExpanded for the starting state and onStateChanged to listen to changes.
    • Persistence: Supports PageStorage to persist state across rebuilds.
    • Customization: You can customize the header/content shapes, background colors, animation duration, and direction.
    Expander(
      header: Text('Click to expand'),
      content: Text('This is the expanded content.'),
    )
  5. Customize the accent color in FluentThemeData

    master

    Common controls in fluent_ui use an accent color to convey state. By default, the accent color is Colors.blue. You can customize it by providing a FluentThemeData with a specific accentColor.

    To use the system's accent color, you can integrate the system_theme plugin and map its color values to a AccentColor.swatch.

    // Customizing with a specific color
    FluentThemeData(
      accentColor: Colors.blue,
    )
    
    // Using the system's accent color via system_theme plugin
    import 'package:system_theme/system_theme.dart';
    
    FluentThemeData(
      accentColor: AccentColor.swatch({
        'darkest': SystemTheme.accentColor.darkest,
        'darker': SystemTheme.accentColor.darker,
        'dark': SystemTheme.accentColor.dark,
        'normal': SystemTheme.accentColor.accent,
        'light': SystemTheme.accentColor.light,
        'lighter': SystemTheme.accentColor.lighter,
        'lightest': SystemTheme.accentColor.lightest,
      }),
    )
  6. Configure ToggleSwitchThemeData

    master

    Use ToggleSwitchThemeData to customize the visual properties of ToggleSwitch widgets. This includes decorations for both checked and unchecked states of the switch and the knob, as well as animation settings.

    Available properties:

    • checkedKnobDecoration: WidgetStateProperty<Decoration?>?
    • uncheckedKnobDecoration: WidgetStateProperty<Decoration?>?
    • checkedDecoration: WidgetStateProperty<Decoration?>?
    • uncheckedDecoration: WidgetStateProperty<Decoration?>?
    • padding: EdgeInsetsGeometry?
    • margin: EdgeInsetsGeometry?
    • animationDuration: Duration?
    • animationCurve: Curve?
    • foregroundColor: WidgetStateProperty<Color?>?
  7. Customize Slider appearance with SliderThemeData

    master

    You can customize the visual appearance of Slider widgets using SliderThemeData via the style property of a Slider or by wrapping a subtree in a SliderTheme widget.

    Available Styling Options

    PropertyTypeDescription
    thumbColorWidgetStateProperty<Color?>?The color of the slider thumb.
    thumbRadiusWidgetStateProperty<double?>?The radius of the slider thumb.
    trackHeightWidgetStateProperty<double?>?The height of the slider track.
    activeColorWidgetStateProperty<Color?>?The color of the active (filled) portion of the track.
    inactiveColorWidgetStateProperty<Color?>?The color of the inactive (unfilled) portion of the track.
    labelBackgroundColorColor?The background color of the value label.
    labelForegroundColorColor?The text color of the value label.
    useThumbBallbool?Whether to draw a ball-shaped thumb instead of a line.
    thumbBallInnerFactorWidgetStateProperty<double?>?Controls how much of the thumb ball is filled.
    marginEdgeInsetsGeometry?The margin around the slider.
  8. Supported languages for localization

    master

    FluentUI widgets support a wide range of languages out-of-the-box. Note that using an unsupported language may cause your app to crash.

    Supported languages include:

    • Arabic, Bahasa Indonesia, Belarusian, Czech, Croatian, Dutch, English, French, German, Greek, Hebrew, Hindi, Hungarian, Italian, Japanese, Korean, Malay, Nepali, Persian, Polish, Portuguese, Romanian, Russian, Simplified Chinese, Tagalog, Tamil, Traditional Chinese, Thai, Turkish, Spanish, Ukranian, Urdu, Uzbek.
  9. Configure Checkbox with content and labels

    master

    You can add a label or icon to the right of the checkbox using the content property. The content widget is affected by user touch, meaning clicking the label will also toggle the checkbox.

    Checkbox(
      checked: isAccepted,
      content: Text('I accept the terms and conditions'),
      onChanged: (value) => setState(() => isAccepted = value ?? false),
    )
  10. Use SliderTheme to style multiple Sliders

    master

    To apply a consistent style to all sliders within a specific part of your widget tree, wrap them in a SliderTheme widget.

    SliderTheme(
      data: SliderThemeData(
        activeColor: Colors.blue,
        thumbRadius: WidgetStatePropertyAll(15.0),
      ),
      child: Column(
        children: [
          Slider(value: 10, min: 0, max: 100, onChanged: (v) {}),
          Slider(value: 50, min: 0, max: 100, onChanged: (v) {}),
        ],
      ),
    )
  11. Implement a three-state Checkbox

    master

    To represent a group where the parent checkbox reflects the state of its children, use a nullable bool? for the checked property. When the checkbox is clicked, you can toggle between true and false, while null represents the indeterminate state.

    // null = indeterminate (some children checked)
    // true = all children checked
    // false = no children checked
    bool? parentChecked;
    
    Checkbox(
      checked: parentChecked,
      content: Text('Select all'),
      onChanged: (value) {
        setState(() {
          // When clicked, toggle between checked and unchecked
          parentChecked = value == true ? true : false;
        });
      },
    )
  12. Use the Slider widget

    master

    The Slider widget allows users to select a value from a continuous or discrete range by moving a thumb along a track. It supports both horizontal and vertical orientations.

    Basic Horizontal Slider

    double volume = 50;
    
    Slider(
      value: volume,
      min: 0,
      max: 100,
      onChanged: (value) => setState(() => volume = value),
      label: '${volume.round()}%',
    )

    Slider with Discrete Divisions

    Use the divisions property to create discrete steps. This is often used in conjunction with a label to show the current value.

    double rating = 3;
    
    Slider(
      value: rating,
      min: 1,
      max: 5,
      divisions: 4,
      label: rating.round().toString(),
      onChanged: (value) => setState(() => rating = value),
    )

    Vertical Slider

    Set the vertical property to true to use a vertical orientation.

    Slider(
      value: temperature,
      min: 0,
      max: 100,
      vertical: true,
      onChanged: (value) => setState(() => temperature = value),
    )
    double volume = 50;
    
    Slider(
      value: volume,
      min: 0,
      max: 100,
      onChanged: (value) => setState(() => volume = value),
      label: '${volume.round()}%',
    )