Skip to content

Commit aae2068

Browse files
authored
[device_info_plus] Add support for screenWidth and screenHeight (#897)
1 parent 21f3010 commit aae2068

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

packages/device_info_plus/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 1.3.0
22

33
* Update code format.
4+
* Add support for `screenWidth` and `screenHeight`.
45

56
## 1.2.1
67

packages/device_info_plus/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Add `device_info_plus_tizen` as a dependency in your `pubspec.yaml` file.
1010

1111
```yaml
1212
dependencies:
13-
device_info_plus_tizen: ^1.2.1
13+
device_info_plus_tizen: ^1.3.0
1414
```
1515
1616
Then you can import `device_info_plus_tizen` in your Dart code.
@@ -46,5 +46,7 @@ String modelName = tizenInfo.modelName;
4646
| `platformName` | `http://tizen.org/system/platform.name` |
4747
| `platformProcessor` | `http://tizen.org/system/platform.processor` |
4848
| `tizenId` | `http://tizen.org/system/tizenid` |
49+
| `screenWidth` | `http://tizen.org/feature/screen.width` |
50+
| `screenHeight` | `http://tizen.org/feature/screen.height` |
4951

5052
For a description of each feature or system key in the list, see https://docs.tizen.org/application/native/guides/device/system.

packages/device_info_plus/example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class _MyAppState extends State<MyApp> {
7777
'platformName': data.platformName,
7878
'platformProcessor': data.platformProcessor,
7979
'tizenId': data.tizenId,
80+
'screenWidth': data.screenWidth,
81+
'screenHeight': data.screenHeight,
8082
};
8183
}
8284

packages/device_info_plus/lib/device_info_plus_tizen.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class TizenDeviceInfo {
3030
required this.platformName,
3131
required this.platformProcessor,
3232
required this.tizenId,
33+
required this.screenWidth,
34+
required this.screenHeight,
3335
});
3436

3537
/// Device information data.
@@ -89,6 +91,12 @@ class TizenDeviceInfo {
8991
/// http://tizen.org/system/tizenid
9092
final String? tizenId;
9193

94+
/// http://tizen.org/feature/screen.width
95+
final int screenWidth;
96+
97+
/// http://tizen.org/feature/screen.height
98+
final int screenHeight;
99+
92100
/// Creates a [TizenDeviceInfo] from the [map].
93101
static TizenDeviceInfo fromMap(Map<String, dynamic> map) {
94102
return TizenDeviceInfo._(
@@ -111,6 +119,8 @@ class TizenDeviceInfo {
111119
platformName: map['platformName'],
112120
platformProcessor: map['platformProcessor'],
113121
tizenId: map['tizenId'],
122+
screenWidth: map['screenWidth'],
123+
screenHeight: map['screenHeight'],
114124
);
115125
}
116126

packages/device_info_plus/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin providing detailed information about Tizen device
33
(make, model, etc.) the app is running on.
44
homepage: https://github.com/flutter-tizen/plugins
55
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/device_info_plus
6-
version: 1.2.1
6+
version: 1.3.0
77

88
environment:
99
sdk: ">=3.1.0 <4.0.0"

packages/device_info_plus/tizen/src/device_info_plus_tizen_plugin.cc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,23 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
5050

5151
for (const auto &[key, tizen_key] : tizen_keys_) {
5252
auto response = flutter::EncodableValue();
53-
char *value = nullptr;
54-
int ret = system_info_get_platform_string(tizen_key.c_str(), &value);
55-
if (ret == SYSTEM_INFO_ERROR_NONE) {
56-
response = std::string(value);
57-
free(value);
53+
int ret = SYSTEM_INFO_ERROR_NONE;
54+
if (key.compare(0, 6, "screen") == 0) {
55+
int value = 0;
56+
ret = system_info_get_platform_int(tizen_key.c_str(), &value);
57+
if (ret == SYSTEM_INFO_ERROR_NONE) {
58+
response = value;
59+
}
5860
} else {
61+
char *value = nullptr;
62+
ret = system_info_get_platform_string(tizen_key.c_str(), &value);
63+
if (ret == SYSTEM_INFO_ERROR_NONE) {
64+
response = std::string(value);
65+
free(value);
66+
}
67+
}
68+
69+
if (ret != SYSTEM_INFO_ERROR_NONE) {
5970
LOG_ERROR("Failed to get %s from the system: %s", tizen_key.c_str(),
6071
get_error_message(ret));
6172
}
@@ -88,6 +99,8 @@ class DeviceInfoPlusTizenPlugin : public flutter::Plugin {
8899
{"platformName", "http://tizen.org/system/platform.name"},
89100
{"platformProcessor", "http://tizen.org/system/platform.processor"},
90101
{"tizenId", "http://tizen.org/system/tizenid"},
102+
{"screenWidth", "http://tizen.org/feature/screen.width"},
103+
{"screenHeight", "http://tizen.org/feature/screen.height"},
91104
};
92105
};
93106

0 commit comments

Comments
 (0)