locale_sync 1.0.2 locale_sync: ^1.0.2 copied to clipboard
An easy-to-use internationalization package for Flutter
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'translations/locale_sync.dart';
void main() async {
await LocaleSync.setup(
apiToken: "e7b52dfd-57bd-4bc6-9738-cad3be7cfd9d",
repositoryId: "repository:s6udatrquzh2c5m0ye8c",
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
locale: const Locale("pt"),
supportedLocales: const [
Locale("en"),
Locale("en", "US"),
Locale("en", "CA"),
Locale("pt"),
Locale("pt", "BR"),
],
localizationsDelegates: [
LocaleSync.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
LocaleSync.of(context).string_edit,
),
],
),
),
);
}
}