> ## Documentation Index
> Fetch the complete documentation index at: https://docs.localesync.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Flutter

> Flutter SDK

## Requirements

Locale Sync's SDK integrates with Flutter through flutter\_localizations package, so, naturally, you'll need to get this added to your **pubspec.yaml**:

```yaml pubspec.yaml theme={null}
    ...
    flutter_localizations:
        sdk: flutter
    intl: any
    ...
```

Once added, you need to add your supported locales on your app widget along with the localization delegates:

```dart lib/app.dart theme={null}
    return MaterialApp(
        supportedLocales: const [
            Locale("pt"),
            Locale("en"),
        ],
        localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
        ],
    );
```

## Installing

Add locale\_sync package as a dependency:

```bash theme={null}
    flutter pub add locale_sync
```

Once you have already added your <a href="/config/config-file">config file</a> and your <a href="/config/translation-fallback">translation fallback file</a> you can generate your .dart files by running:

```bash theme={null}
    dart run locale_sync gen
```

If you want to upload it to servers already you can just run after:

```bash theme={null}
    dart run locale_sync upload
```

This will send your translations to the repository specified in your config file, upserting languages and strings from your file.

On your app widget you need to add LocaleSync.delegate to that list:

```dart lib/app.dart theme={null}
    return MaterialApp(
        supportedLocales: const [
            Locale("pt"),
            Locale("en"),
        ],
        localizationsDelegates: [
            // Add this line
            LocaleSync.delegate
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
        ],
    );
```

## Over the air

If you want to use our over-the-air strings feature you just need to call setup method from LocaleSync on your main.dart, or whatever entry point you're using:

```dart main.dart theme={null}
    void main() async {
        // setups
        await LocaleSync.setup(
            apiToken: "your-api-token",
            repositoryId: "your-repository-id",
        );
        
        // run your app
        runApp(
            const App(),
        );
    }
```

## Getting translations

```dart lib/screens/my_screen.dart theme={null}
    ...,
    Text(
        LocaleSync.of(context).yourString
    ),
    ...
```

When you get strings which takes arguments you add it as a function arg, and the same is applied to plural strings:

```dart lib/screens/my_screen.dart theme={null}
    ...,
    Text(
        LocaleSync.of(context).minValidation(
            count: 8,
            name: translations.password,
        ),
    ),
    ...
```

```json lib/translations/fallback_translation.json theme={null}
    {
        "en": {
            "minValidation" : {
                "plural" : "{name} deve ter no mínimo {count} caracteres",
                "value" : "{name} deve ter no mínimo 1 caracter"
            }
        }
    }
```
