41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
|
|
import 'dart:ffi';
|
|
import 'dart:io';
|
|
|
|
import 'hardware_bindings_generated.dart';
|
|
|
|
const String _libName = 'hardware';
|
|
|
|
/// The dynamic library in which the symbols for [HardwareBindings] can be found.
|
|
final DynamicLibrary _dylib = () {
|
|
if (Platform.isMacOS || Platform.isIOS) {
|
|
return DynamicLibrary.open('$_libName.framework/$_libName');
|
|
}
|
|
if (Platform.isAndroid || Platform.isLinux) {
|
|
return DynamicLibrary.open('lib$_libName.so');
|
|
}
|
|
if (Platform.isWindows) {
|
|
return DynamicLibrary.open('$_libName.dll');
|
|
}
|
|
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
|
|
}();
|
|
|
|
/// The bindings to the native functions in [_dylib].
|
|
final HardwareBindings _bindings = HardwareBindings(_dylib);
|
|
|
|
/// Hardware screen information.
|
|
class HardwareScreen {
|
|
/// Returns the device screen corner radius in logical pixels.
|
|
/// Returns null on platforms where the value is not available.
|
|
double? get borderRadius {
|
|
final result = _bindings.get_screen_border_radius();
|
|
if (result.hasValue == 0) return null;
|
|
return result.value;
|
|
}
|
|
}
|
|
|
|
/// Main Hardware API for accessing device hardware information.
|
|
abstract class Hardware {
|
|
static final HardwareScreen screen = HardwareScreen();
|
|
}
|