I created a new Flutter project with Android Studio. I'm using null-safety and I'm running the application on a physical device yet the code-generation is not working, there is no flutter_gen folder inside .dart_tool folder just flutter_build folder.
I followed the steps in Flutter's official Internationalizing documentation
Im not using Flutter Intl plugin because it doesn't support null-safety (I'm aware you can make an script to add an old dart version at the top of each generated file as a workaround)
flutter doctor command output:
[✓] Flutter (Channel beta, 1.26.0-17.5.pre, on Microsoft Windows [Versión 10.0.19042.804], locale es-ES)
• Flutter version 1.26.0-17.5.pre at <PATH>
• Framework revision 1fe38dcb5f (3 days ago), 2021-02-10 16:25:47 -0800
• Engine revision d4453f6018
• Dart version 2.12.0 (build 2.12.0-259.9.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at <PATH>
• Platform android-30, build-tools 30.0.2
• Java binary at: <PATH>
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[✓] Android Studio (version 4.1.0)
• Android Studio at <PATH>
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[✓] VS Code (version 1.53.2)
• VS Code at <PATH>
• Flutter extension version 3.19.0
[✓] Connected device (1 available)
• <DEVICE> • android-arm • Android 8.1.0 (API 27)
• No issues found!
/pubscpec.yaml:
name: example_app
description: A new Flutter application.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.12.0-0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0-nullsafety.2
cupertino_icons: ^1.0.1
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
flutter:
uses-material-design: true
generate: true
/lib/main.dart:
import 'package:example_app/ui/screen/home_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
// TODO: uncomment the line below after codegen
// import 'package:flutter_gen/gen_l10n/app_localizations.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage('Flutter Demo Home Page'),
localizationsDelegates: [
// ... app-specific localization delegate[s] here
// TODO: uncomment the line below after codegen
// AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''), // English, no country code
const Locale('es', ''), // Spanish, no country code
],
);
}
}
/lib/l10n.yaml:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
lib/l10n/app_en.arb
{
"helloWorld": "Hello World!"
}
lib/l10n/app_es.arb
{
"helloWorld": "Hola mundo!"
}