forui Documentation

repository·main·Indexed 25 days ago

https://github.com/duobaseio/forui

A minimalistic, shadcn/ui-inspired UI library for Flutter featuring over 40 customizable widgets, CLI-based theme generation, and native integration with Flutter Hooks via the forui_hooks package. It supports both imperative controllers and declarative state management using lifted controls.

Tokens
60K
Snippets
207
Records
475
Agent score
81%

What's inside forui

  1. Overview of Forui

    main

    Forui is a minimalistic, platform-agnostic UI library for Flutter. It provides over 40+ beautifully crafted widgets inspired by shadcn/ui, but optimized for touch-first interactions on mobile and tablet devices.

    Key features include:

    • Platform Agnostic Design: Consistent UI across all devices.
    • Touch-First Interaction: Optimized for mobile and tablet responsiveness.
    • Minimalistic Aesthetics: Clean and uncluttered design principles.
    • Extensibility: Highly customizable components.
    • CLI Support: A bundled CLI to generate themes and styling boilerplate.
    • I10n Support: Built-in internationalization support.
    • Flutter Hooks Integration: First-class support via the forui_hooks package.
  2. Explore the documentation project structure

    main

    The documentation site is built using Next.js and Fumadocs. Key files and routes include:

    • lib/source.ts: Contains the code for the content source adapter. The loader() function provides the interface to access your content.
    • lib/layout.shared.tsx: Contains shared options for layouts.
    • app/(home): Route group for the landing page and other primary pages.
    • app/docs: The main documentation layout and pages.
    • app/api/search/route.ts: The Route Handler responsible for search functionality.
  3. What is a style template in Forui?

    main

    A style template is a generated snippet of styling code for a specific widget. Instead of manually chaining multiple .copyWith(...) and .transform(...) calls to customize a widget's appearance, you can use a template.

    Templates are typically copies of a style's inherit(...) constructor, providing a structured way to tailor a style to a unique use-case. This approach scales better as the number of properties you need to modify increases.

  4. Configure Slider appearance and variants

    main

    The Slider supports several visual variants to match different UI states and requirements:

    • Labelled: Includes a label for the slider.
    • Disabled: A non-interactive state.
    • Error: A visual state indicating an error condition.
    • Tooltip: Displays a tooltip during interaction.
    • Marks: Uses FSliderMark to show ticks and optional labels on the track.
  5. The problem with manual widget style modification in Forui

    main
    Modifying widget appearances manually in Forui is often cumbersome and difficult to read. Developers typically have to retrieve the existing style and chain multiple .copyWith(...) and .transform(...) calls to reach nested properties. This introduces significant boilerplate and 'noise' in the codebase.
  6. Use Forui with Flutter Hooks

    main
    Forui provides first-class integration with the flutter_hooks package. All Forui controllers are exposed as hooks through a companion package called forui_hooks. You can find this package on pub.dev.
  7. Understand Forui Controls and state management

    main

    In Forui, Controls are abstractions over controllers (like TextEditingController) that define where a widget's state lives. Instead of passing raw controllers directly to widgets, you pass a Control object. This abstraction allows for different patterns of state ownership: either the widget owns the state, or the application logic owns the state.

    There are two primary types of controls:

    1. Lifted: The widget is "dumb" and only reflects the values passed to it. The state is managed externally by your application logic. This is similar to React's controlled components.
    2. Managed: The widget manages its own state. This can happen in two ways:
      • Internal Controller: The widget creates and manages its own controller internally, using provided initial values.
      • External Controller: You pass in an existing controller. In this case, you are responsible for managing the lifecycle (creation and disposal) of that controller.
  8. State Independence Principle in Forui

    main

    Forui follows the State Independence Principle when using declarative (lifted) modes:

    1. No Implicit Sync: Each value/callback pair is isolated. If you lift multiple related states (e.g., a selected date and the currently displayed month in a calendar), changing one will not automatically update the other. You must wire the synchronization manually in your onChange callbacks.
    2. Sensible Defaults for Omitted States: If you omit a specific state pair in .lifted() mode, the widget manages that specific part internally with sensible defaults. For example, in FCalendar, if you omit displayedMonth, the widget will auto-scroll to the selected date. If you provide displayedMonth, the widget will no longer auto-scroll, giving you full control.
    // Example: FCalendar behavior with omitted vs provided state
    
    // displayedMonth omitted -> widget auto-scrolls to selected date
    FCalendar(control: FCalendarControl.liftedSingle(value: date, onChange: setDate));
    
    // displayedMonth provided -> user controls, no auto-scroll
    FCalendar(control: FCalendarControl.liftedSingle(
      value: date,
      onChange: setDate,
      displayedMonth: month,
      onDisplayedMonthChange: setMonth,
    ));
    
    // Manual sync required if both are lifted
    FCalendar(control: FCalendarControl.liftedSingle(
      value: date,
      onChange: (d) {
        setDate(d);
        setMonth(d);  // manual sync
      },
      displayedMonth: month,
      onDisplayedMonthChange: setMonth,
    ));