gpt4 book ai didi

Flutter 国际化,国际代码生成不起作用

转载 作者:行者123 更新时间:2023-12-02 02:22:37 26 4
gpt4 key购买 nike

我使用 Android Studio 创建了一个新的 Flutter 项目。我正在使用null-safety,并且正在物理设备上运行应用程序,但代码生成无法正常工作,没有flutter_gen .dart_tool文件夹内的strong>文件夹只是flutter_build文件夹。

我按照 Flutter's official Internationalizing documentation 中的步骤操作

我没有使用Flutter Intl插件,因为它不支持 null-safety (我知道你可以制作一个脚本来在每个生成的文件的顶部添加旧的 dart 版本作为解决方法)

flutter doctor 命令输出:

[✓] 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!"
}

最佳答案

这是我的错误,将 /lib/l10n.yaml/ 移动到 /l10n.yaml/ 解决了问题。

回答者perqin .

关于Flutter 国际化,国际代码生成不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66185977/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com