flutter usb串口_Flutter 1.22最新的多国语支持配置和使用

本文介绍了Flutter 1.22版本中新增的多国语支持配置方法,包括yaml文件配置、l10n.yaml文件设置、arb文件创建以及在项目中的使用。通过配置,可以实现自动多国语代码生成,方便进行多语言切换。详细步骤包括添加依赖、创建arb文件、设置多国语属性,并提供了具体的代码示例。
摘要由CSDN通过智能技术生成

Flutter 1.22现已发布

​ 最新版本中,随之发布了很多新的特性以及修复了一些BUG,现在我们说说其中的新的多国语插件。个人感觉新多国语操作,多了一些模板性的东西,但是也方便了很多东西。

​ 话不多说,现在我们进入正题,如何使用新插件呢?

配置项目的yaml文件

pubspec.yaml

dependencies:

flutter:

sdk: flutter

flutter_localizations: #配置多国语支持

sdk: flutter

intl: ^0.16.1 #多国语插件,要求高于0.16.1版本

flutter:

# The following line ensures that the Material Icons font is

# included with your application, so that you can use the icons in

# the material Icons class.

uses-material-design: true

generate: true #新增配置,自动多国语代码生成

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

dependencies:

flutter:

sdk:flutter

flutter_localizations:#配置多国语支持

sdk:flutter

intl:^0.16.1#多国语插件,要求高于0.16.1版本

flutter:

# The following line ensures that the Material Icons font is

# included with your application, so that you can use the icons in

# the material Icons class.

uses-material-design:true

generate:true#新增配置,自动多国语代码生成

项目根目录下新增配置l10n.yaml

添加位置如下图:

里面的内容如下:

l10n.yaml

arb-dir: lib/l10n #指定arb多国语文件目录

template-arb-file: app_en.arb #指定arb多国语言的模版文件,一般用英文作为默认模版,其他语言进行扩展

output-localization-file: app_localizations.dart #指定多国语配置生成的代码文件,代码中自动生成类文件AppLocalizations.dart

1

2

3

arb-dir:lib/l10n#指定arb多国语文件目录

template-arb-file:app_en.arb#指定arb多国语言的模版文件,一般用英文作为默认模版,其他语言进行扩展

output-localization-file:app_localizations.dart#指定多国语配置生成的代码文件,代码中自动生成类文件AppLocalizations.dart

l10n.yaml 文件可配置的属性有:

属性

描述

arb-dir

The directory where the template and translated arb files are located. (defaults to "lib/l10n")

output-dir

The directory where the generated localization classes will be written. This option is only relevant if you want to generate the localizations code somewhere else in the Flutter project. You will also need to set the synthetic-package flag to false.
The app must import the file specified in the 'output-localization-file' option from this directory. If unspecified, this defaults to the same directory as the input directory specified in 'arb-dir'.

template-arb-file

The template arb file that will be used as the basis for generating the Dart localization and messages files. (defaults to "app_en.arb")

output-localization-file

The filename for the output localization and localizations delegate classes. (defaults to "app_localizations.dart")

untranslated-messages-file

The location of a file that describes the localization messages have not been translated yet. Using this option will create a JSON file at the target location, in the following format:

"locale": ["message_1", "message_2" ... "message_n"]

If this option is not specified, a summary of the messages that have not been translated will be printed on the command line.

output-class

The Dart class name to use for the output localization and localizations delegate classes. (defaults to "AppLocalizations")

preferred-supported-locales

The list of preferred supported locales for the application. By default, the tool will generate the supported locales list in alphabetical order. Use this flag if you would like to default to a different locale.

For example, pass in [ en_US ] if you would like your app to default to American English if a device supports it.

synthetic-package

Determines whether or not the generated output files will be generated as a synthetic package or at a specified directory in the Flutter project.

This flag is set to true by default.
When synthetic-package is set to false, it will generate the localizations files in the directory specified by arb-dir by default.
If output-dir is specified, files will be generated there.

header

The header to prepend to the generated Dart localizations files. This option takes in a string.

For example, pass in "/// All localized files." if you would like this string prepended to the generated Dart file.

Alternatively, see the header-file option to pass in a text file for longer headers.

header-file

The header to prepend to the generated Dart localizations files. The value of this option is the name of the file that contains the header text which will be inserted at the top of each generated Dart file.

Alternatively, see the header option to pass in a string for a simpler header.

This file should be placed in the directory specified in 'arb-dir'.

[no-]use-deferred-loading

Whether to generate the Dart localization file with locales imported as deferred, allowing for lazy loading of each locale in Flutter web.

This can reduce a web app’s initial startup time by decreasing the size of the JavaScript bundle. When this flag is set to true, the messages for a particular locale are only downloaded and loaded by the Flutter app as they are needed. For projects with a lot of different locales and many localization strings, it can be a performance improvement to have deferred loading. For projects with

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
flutter_downloader是一个用于在Flutter应用程序中进行文件下载的插件。它提供了一种简单而强大的方式来管理和监控文件下载任务。 使用flutter_downloader,你可以轻松地添加文件下载功能到你的Flutter应用程序中。它支持多个平台,包括Android和iOS,并且提供了一组易于使用的API来管理下载任务。 要使用flutter_downloader,首先需要在你的Flutter项目中添加依赖。在pubspec.yaml文件中,添加以下内容: ``` dependencies: flutter_downloader: ^1.6.0 ``` 然后运行`flutter pub get`命令来获取依赖。 接下来,在你的代码中导入flutter_downloader包,并使用它来创建和管理下载任务。你可以使用`FlutterDownloader.enqueue`方法来创建一个下载任务,并传递下载链接、保存路径等参数。你还可以使用`FlutterDownloader.open`方法来打开已下载的文件。 以下是一个简单的示例代码,演示了如何使用flutter_downloader进行文件下载: ```dart import 'package:flutter/material.dart'; import 'package:flutter_downloader/flutter_downloader.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('File Downloader'), ), body: Center( child: RaisedButton( child: Text('Download File'), onPressed: () { _startDownload(); }, ), ), ), ); } void _startDownload() async { String url = 'https://example.com/file.pdf'; String savedDir = '/storage/emulated/0/Download'; await FlutterDownloader.enqueue( url: url, savedDir: savedDir, showNotification: true, openFileFromNotification: true, ); } } ``` 这是一个简单的示例,当用户点击按钮时,会触发文件下载任务。下载的文件将保存在指定的目录中,并且会显示下载通知。用户可以通过通知来打开已下载的文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值