sway 0.2.0 copy "sway: ^0.2.0" to clipboard
sway: ^0.2.0 copied to clipboard

Type-safe Flutter localization with an instant in-app locale switcher and zero-friction migration from ARB, easy_localization, and slang.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:sway/sway.dart';

import 'i18n/sway.g.dart';
import 'screens/home_screen.dart';

void main() => runApp(const ExampleApp());

/// Brand charcoal - matches Darkmintis mark energy without default M3 blue.
const _brandSeed = Color(0xFF1C1C1C);

class ExampleApp extends StatefulWidget {
  const ExampleApp({super.key});

  @override
  State<ExampleApp> createState() => ExampleAppState();
}

class ExampleAppState extends State<ExampleApp> {
  late final SwayFormatAdapter adapter;
  Locale _locale = const Locale('en');

  /// Kept above [ForceRebuildScope] so locale switches don't reset the tab.
  int tabIndex = 0;

  Locale get locale => _locale;

  @override
  void initState() {
    super.initState();
    adapter = SwayFormatAdapter(
      supportedLocales: SwayTranslations.supportedLocales,
      currentLocale: _locale,
      onLocaleChange: (locale) => setState(() => _locale = locale),
    );
  }

  @override
  Widget build(BuildContext context) {
    final translations = SwayTranslations.forLocale(_locale);
    return MaterialApp(
      title: translations.app.title,
      debugShowCheckedModeBanner: false,
      locale: _locale,
      supportedLocales: SwayTranslations.supportedLocales,
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      theme: ThemeData(
        colorSchemeSeed: _brandSeed,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      // Production-style shell: nested Overlay via Sway.debugOverlay.
      builder: (context, child) => SwayScope(
        translations: translations,
        child: Sway.debugOverlay(
          adapter: adapter,
          child: child ?? const SizedBox.shrink(),
        ),
      ),
      home: HomeScreen(
        tabIndex: tabIndex,
        onTabChanged: (i) => setState(() => tabIndex = i),
      ),
    );
  }
}
0
likes
160
points
119
downloads
screenshot

Documentation

Documentation
API reference

Publisher

verified publisherdarkmintis.dev

Weekly Downloads

Type-safe Flutter localization with an instant in-app locale switcher and zero-friction migration from ARB, easy_localization, and slang.

Repository (GitHub)
View/report issues

Topics

#localization #i18n #l10n #translation #flutter

License

MIT (license)

Dependencies

flutter, flutter_localizations, path

More

Packages that depend on sway