Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | List of all members
io.flutter.embedding.engine.systemchannels.LocalizationChannel Class Reference

Classes

interface  LocalizationMessageHandler
 

Public Member Functions

 LocalizationChannel (@NonNull DartExecutor dartExecutor)
 
void setLocalizationMessageHandler ( @Nullable LocalizationMessageHandler localizationMessageHandler)
 
void sendLocales (@NonNull List< Locale > locales)
 

Public Attributes

final MethodChannel channel
 
final MethodChannel.MethodCallHandler handler
 

Detailed Description

Sends the platform's locales to Dart.

Definition at line 22 of file LocalizationChannel.java.

Constructor & Destructor Documentation

◆ LocalizationChannel()

io.flutter.embedding.engine.systemchannels.LocalizationChannel.LocalizationChannel ( @NonNull DartExecutor  dartExecutor)
inline

Definition at line 61 of file LocalizationChannel.java.

61 {
62 this.channel =
63 new MethodChannel(dartExecutor, "flutter/localization", JSONMethodCodec.INSTANCE);
64 channel.setMethodCallHandler(handler);
65 }

Member Function Documentation

◆ sendLocales()

void io.flutter.embedding.engine.systemchannels.LocalizationChannel.sendLocales ( @NonNull List< Locale >  locales)
inline

Send the given locales to Dart.

Definition at line 77 of file LocalizationChannel.java.

77 {
78 Log.v(TAG, "Sending Locales to Flutter.");
79 // Send the user's preferred locales.
80 List<String> data = new ArrayList<>();
81 for (Locale locale : locales) {
82 Log.v(
83 TAG,
84 "Locale (Language: "
85 + locale.getLanguage()
86 + ", Country: "
87 + locale.getCountry()
88 + ", Variant: "
89 + locale.getVariant()
90 + ")");
91 data.add(locale.getLanguage());
92 data.add(locale.getCountry());
93 data.add(locale.getScript());
94 data.add(locale.getVariant());
95 }
96 channel.invokeMethod("setLocale", data);
97 }
void Log(const char *format,...) SK_PRINTF_LIKE(1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ setLocalizationMessageHandler()

void io.flutter.embedding.engine.systemchannels.LocalizationChannel.setLocalizationMessageHandler ( @Nullable LocalizationMessageHandler  localizationMessageHandler)
inline

Sets the LocalizationMessageHandler which receives all events and requests that are parsed from the underlying platform channel.

Definition at line 71 of file LocalizationChannel.java.

72 {
73 this.localizationMessageHandler = localizationMessageHandler;
74 }

Member Data Documentation

◆ channel

final MethodChannel io.flutter.embedding.engine.systemchannels.LocalizationChannel.channel

Definition at line 25 of file LocalizationChannel.java.

◆ handler

final MethodChannel.MethodCallHandler io.flutter.embedding.engine.systemchannels.LocalizationChannel.handler

Definition at line 29 of file LocalizationChannel.java.

30 {
31 @Override
32 public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
33 if (localizationMessageHandler == null) {
34 // If no explicit LocalizationMessageHandler has been registered then we don't
35 // need to forward this call to an API. Return.
36 return;
37 }
38
39 String method = call.method;
40 switch (method) {
41 case "Localization.getStringResource":
42 JSONObject arguments = call.<JSONObject>arguments();
43 try {
44 String key = arguments.getString("key");
45 String localeString = null;
46 if (arguments.has("locale")) {
47 localeString = arguments.getString("locale");
48 }
49 result.success(localizationMessageHandler.getStringResource(key, localeString));
50 } catch (JSONException exception) {
51 result.error("error", exception.getMessage(), null);
52 }
53 break;
54 default:
55 result.notImplemented();
56 break;
57 }
58 }
59 };
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
GAsyncResult * result
call(args)
Definition dom.py:159

The documentation for this class was generated from the following file: