flutter_localization_updater 1.0.3
flutter_localization_updater: ^1.0.3 copied to clipboard
A Flutter package that automatically updates localizations from Google Sheets and integrates with easy_localization.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_localization_updater/flutter_localization_updater.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize localization service with your configuration
final localizationService = LocalizationService(
config: LocalizationConfig(
googleSheetApiKey: 'YOUR_GOOGLE_SHEETS_API_KEY',
sheetId: 'YOUR_GOOGLE_SHEET_ID',
supportedLocales: ['en', 'nl'],
updateIntervalMs: 24 * 60 * 60 * 1000, // 24 hours
),
);
// Check and update localizations
await localizationService.checkAndUpdateLocalizations();
// Initialize easy_localization
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: const [Locale('en'), Locale('nl')],
path: 'assets/localizations',
fallbackLocale: const Locale('en'),
assetLoader: CustomAssetLoader(), // Use the custom asset loader
child: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('general.header_title'.tr()), // Updated key
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('general.searching_location'.tr()), // Updated key
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// Change locale
context.setLocale(Locale('nl'));
},
child: Text('Switch to Dutch'),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
// Change locale back to English
context.setLocale(Locale('en'));
},
child: Text('Switch to English'),
),
],
),
),
);
}
}