Skip to content

Commit

Permalink
Update android-devs.md (#10102)
Browse files Browse the repository at this point in the history
_Description of what this PR is changing or adding, and why:_

Updated
https://github.com/flutter/website/tree/main/src/get-started/flutter-for/android-devs.md
page as it is containing some outdated information.

_Issues fixed by this PR (if any):_
#10101

## Presubmit checklist

- [x] This PR doesn’t contain automatically generated corrections
(Grammarly or similar).
- [x] This PR follows the [Google Developer Documentation Style
Guidelines](https://developers.google.com/style) — for example, it
doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person).
- [x] This PR uses [semantic line
breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)
of 80 characters or fewer.

---------

Co-authored-by: Murtaza Hussain <murtaza.hussain@koderlabs.com>
  • Loading branch information
syedmurtaza108 and murtazahussain108 authored Feb 14, 2024
1 parent 148ab2b commit 5195806
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
3 changes: 3 additions & 0 deletions examples/get-started/flutter-for/android_devs/l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib
template-arb-file: arb_examples.arb
output-localization-file: app_localizations.dart
13 changes: 13 additions & 0 deletions examples/get-started/flutter-for/android_devs/lib/arb_examples.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@@locale": "en",
"hello":"Hello {userName}",
"@hello":{
"description":"A message with a single parameter",
"placeholders":{
"userName":{
"type":"String",
"example":"Bob"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class MyWidget extends StatelessWidget {
const MyWidget({super.key});

@override
Widget build(BuildContext context) {
return
// #docregion AccessString
Text(AppLocalizations.of(context)!.hello('John'));
// #enddocregion AccessString
}
}
4 changes: 4 additions & 0 deletions examples/get-started/flutter-for/android_devs/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

cupertino_icons: ^1.0.6
http: ^1.1.0
shared_preferences: ^2.2.0
intl: any

dev_dependencies:
example_utils:
Expand All @@ -23,4 +26,5 @@ dev_dependencies:
sdk: flutter

flutter:
generate: true
uses-material-design: true
31 changes: 20 additions & 11 deletions src/get-started/flutter-for/android-devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1312,28 +1312,36 @@ Widget build(BuildContext context) {
### Where do I store strings? How do I handle localization?

Flutter currently doesn't have a dedicated resources-like system for strings.
At the moment, the best practice is to hold your copy text in a class as
static fields and accessing them from there. For example:

<?code-excerpt "lib/string_examples.dart (Strings)"?>
```dart
class Strings {
static String welcomeMessage = 'Welcome To Flutter';
The best and recommended practice is to hold your strings in a `.arb` file as key-value pairs For example:

<?code-excerpt "lib/arb_examples.arb"?>
```arb
{
"@@locale": "en",
"hello":"Hello {userName}",
"@hello":{
"description":"A message with a single parameter",
"placeholders":{
"userName":{
"type":"String",
"example":"Bob"
}
}
}
}
```

Then in your code, you can access your strings as such:

<?code-excerpt "lib/string_examples.dart (AccessString)"?>
<?code-excerpt "lib/localization_examples.dart (AccessString)"?>
```dart
Text(Strings.welcomeMessage);
Text(AppLocalizations.of(context)!.hello('John'));
```

Flutter has basic support for accessibility on Android,
though this feature is a work in progress.

Flutter developers are encouraged to use the
[intl package][] for internationalization and localization.
See [Internationalizing Flutter apps][] for more information on this.

### What is the equivalent of a Gradle file? How do I add dependencies?

Expand Down Expand Up @@ -2413,3 +2421,4 @@ see the [`firebase_messaging`][] plugin documentation.
[SQFlite]: {{site.pub}}/packages/sqflite
[StackOverflow]: {{site.so}}/questions/44396075/equivalent-of-relativelayout-in-flutter
[widget catalog]: {{site.url}}/ui/widgets/layout
[Internationalizing Flutter apps]: {{site.url}}/ui/accessibility-and-internationalization/internationalization

0 comments on commit 5195806

Please sign in to comment.