# Flutter

> The sosialoka_ui package gives Flutter apps the Sosialoka themes for shadcn_ui and Material.

The `sosialoka_ui` package gives a Flutter app the Sosialoka theme of its product, for `shadcn_ui` widgets and for Material widgets, in light and dark mode.

## Install

The package installs from the design system repository:

```yaml
dependencies:
  shadcn_ui: ^0.59.0
  sosialoka_ui:
    git:
      url: https://gitlab.com/sosialoka/design-system.git
      path: flutter
```

## Set the theme

Pick your product with `SosialokaBrand`, or `SosialokaBrand.neutral` for an app that belongs to no product. `SosialokaTheme.shad` builds the `shadcn_ui` theme, and `SosialokaTheme.material` builds a matching Material theme for screens that still use Material widgets.

```dart
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:sosialoka_ui/sosialoka_ui.dart';

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    const brand = SosialokaBrand.coverclearance;
    return ShadApp.custom(
      theme: SosialokaTheme.shad(brand, Brightness.light),
      darkTheme: SosialokaTheme.shad(brand, Brightness.dark),
      appBuilder: (context) => MaterialApp(
        theme: SosialokaTheme.material(brand, Brightness.light),
        darkTheme: SosialokaTheme.material(brand, Brightness.dark),
        builder: (context, child) => ShadAppBuilder(child: child!),
        home: const HomeScreen(),
      ),
    );
  }
}
```

Moving screens over one at a time works: Material screens and `shadcn_ui` screens share the same colors and radius.

## Extra colors

`shadcn_ui` has no field for the status colors, soft tints, tenant accents or brand colors. Read them from the theme with `context.sosialoka`:

```dart
ShadBadge(
  backgroundColor: context.sosialoka.successSoft,
  foregroundColor: context.sosialoka.success,
  child: const Text('Selesai'),
);
```

The raw values, radius, spacing and text sizes are also available as constants: `SosialokaColors`, `SosialokaRadius`, `SosialokaSpace` and `SosialokaText`. The same constants are in one file, [/tokens/sosialoka_tokens.dart](https://design.sosialoka.tech/tokens/sosialoka_tokens.dart), for an app without the package.

## Font

The themes set Plus Jakarta Sans through the `google_fonts` package, which downloads the font on first use. An app that must work offline should bundle the font files and declare them in its `pubspec.yaml`.

## Examples

Every component page shows its Flutter code in the Flutter tab. The same code runs in the gallery app in `flutter/example` of the repository, where `flutter analyze` and a render test under every brand and mode check it.
