我们在本章回中介绍的包是open_seetings,该包主要用来打开手机中革个功能的设置页面,比如声音设备,应用设置等。如果使用原生开发方式,打开手机中的设置页
面有专门的API;如果使用Flutter进行混合开发则没有相关的API。该包就是为了解决这个问题而创建的,全章回中将详细该包的使用方法。
该包的使用方法也比较简单,只需要直接调用包中的方法就可以跳转相应的功能设置页面,因为这些方法都是静态方法,我们将在后面的小节中通过具体的示例代码来演示。
此外,包中把这些方法封装成了Future,因此可以通过Future来获取打开功能设置的结果。
我们查看了该包的源代码,从源代码中找出了打开手机中相关设置的方法,详细如下:
/// Open Wifi settings
static Future<void> openWIFISetting() async {
await _channel.invokeMethod('openSettings', 'wifi');
}
/// Open location source settings
static Future<void> openLocationSourceSetting() async {
await _channel.invokeMethod('openSettings', 'location_source');
}
/// Open app settings
static Future<void> openAppSetting() async {
await _channel.invokeMethod('openSettings', 'app_settings');
}
/// Open Bluetooth settings
static Future<void> openBluetoothSetting() async {
await _channel.invokeMethod('openSettings', 'bluetooth');
}
/// Open Notification settings
static Future<void> openNotificationSetting() async {
_channel.invokeMethod('openSettings', 'notification');
}
/// Open sound Screen settings
static Future<void> openSoundSetting() async {
_channel.invokeMethod('openSettings', 'sound');
}
/// Open main settings
static Future<void> openMainSetting() async {
_channel.invokeMethod('openSettings', 'settings');
}
/// Open Date settings
static Future<void> openDateSetting() async {
_channel.invokeMethod('openSettings', 'date');
}
/// Open Display settings
static Future<void> openDisplaySetting() async {
_channel.invokeMethod('openSettings', 'display');
}
/// Open airplane mode settings
static Future<void> openAirplaneModeSetting() async {
_channel.invokeMethod('openSettings', 'airplane_mode');
}
/// Open apn settings
static Future<void> openApnSetting() async {
_channel.invokeMethod('openSettings', 'apn');
}
/// Open application details settings
static Future<void> openApplicationDetailsSetting() async {
_channel.invokeMethod('openSettings', 'application_details');
}
/// Open application development settings
static Future<void> openApplicationDevelopmentSetting() async {
_channel.invokeMethod('openSettings', 'application_development');
}
/// Open app_notification_bubble settings
static Future<void> openAppNotificationBubbleSetting() async {
_channel.invokeMethod('openSettings', 'app_notification_bubble');
}
/// Open app_notification settings
static Future<void> openAppNotificationSetting() async {
_channel.invokeMethod('openSettings', 'app_notification');
}
/// Open search settings
static Future<void> openSearchSetting() async {
_channel.invokeMethod('openSettings', 'search');
}
/// Open battery_saver settings
static Future<void> openBatterySaverSetting() async {
_channel.invokeMethod('openSettings', 'battery_saver');
}
/// Open channel_notification settings
static Future<void> openChannelNotificationSetting() async {
_channel.invokeMethod('openSettings', 'channel_notification');
}
/// Open device_info settings
static Future<void> openDeviceInfoSetting() async {
_channel.invokeMethod('openSettings', 'device_info');
}
/// Open hard_keyboard settings
static Future<void> openHardKeyboardSetting() async {
_channel.invokeMethod('openSettings', 'hard_keyboard');
}
/// Open home settings
static Future<void> openHomeSetting() async {
_channel.invokeMethod('openSettings', 'home');
}
上面的接口全面来自源代码,我只列出了其中的一部分,大家可以从源代码中获取到更多的内容。此外,代码中添加了注释,以方便大家理解接口的功能。
///打开手机中的蓝牙设置功能
ElevatedButton(
onPressed: (){
OpenSettings.openBluetoothSetting();
},
child: const Text("Open BT"),
),
上面的示例代码中演示了如何打开手机中蓝牙功能的设置页面,运行该程序就会看到一个名叫"Open BT"按钮,点击该按钮后就可以跳转到手机中蓝牙功能设置页面。建
议大家自己动手去实践,比如打开声音设置页面。
我们在本章回中介绍这个包主要是为了打开手机中蓝牙功能的设置页面,因为在前面章回中介绍蓝牙操作时提起过。当然了,该包的功能比较多,可以通过该包打开其它
的功能设置页面。最后,我们对本章回的内容做一个全面总结: