Flutter SDK
Instructions for adding the Azbox Flutter SDK to your app for iOS, Android and Web.
Requirements
- iOS 12+ or iPadOS 12+ device (iPhone, iPad) to test on. Xcode 14+ simulator works running iOS 16+
- iOS: mac with Xcode 12+
- Android: Android 5.0+ device or emulator with "Google Play Store (Services)" installed
- Paid Azbox plan (Starter or higher)
- Configured Azbox Project
Installation
Add to your pubspec.yaml:
dependencies:
azbox-localization: <last_version>
Configuration
First, you need to initialize Azbox in your main file before running your app:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Azbox.ensureInitialized(
apiKey: 'Your API Key',
projectId: 'Your project ID');
runApp(
Azbox(
child: MyApp()
),
);
}
Then, configure your MaterialApp to support localization:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
home: MyHomePage()
);
}
}
Usage
Once configured, you can translate your texts using several methods:
// Using Text widget extension
Text('title').translate()
// Using String extension
'title'.translate()
// Using static function
var title = translate('title')
// Using BuildContext extension
Text(context.translate('title'))
You can also use parameters in your translations:
// Using positional arguments
Text('msg').translate(args: ['Azbox', 'Flutter'])
// Using named arguments
Text('msg_named').translate(namedArgs: {'lang': 'Flutter'})