当前位置: 首页 > news >正文

Flutter应用设置插件 - 轻松打开iOS和Android系统设置

app_settings

一个用于从Flutter应用中打开iOS和Android手机设置的插件。

功能特性

  • 🚀 跨平台支持 - 完美支持iOS和Android两大移动平台
  • ⚙️ 多种设置类型 - 支持打开位置、Wi-Fi、蓝牙、通知、声音等多种系统设置
  • 🔧 Android Q面板支持 - 支持Android Q及以上版本的设置面板功能
  • :mobile_phone: Swift包管理器 - 支持SPM方式集成到iOS项目
  • :bullseye: 灵活配置 - 可指定特定设置类型,平台不支持时自动回退到通用设置
  • :counterclockwise_arrows_button: 新任务模式 - Android平台支持在新Activity中打开设置页面

安装指南

添加依赖

pubspec.yaml文件中添加依赖:

dependencies:app_settings: ^6.1.1

或使用命令行:

flutter pub add app_settings

导入包

在Dart代码中导入:

import 'package:app_settings/app_settings.dart';

iOS配置

如果项目使用Objective-C,需要在Podfile中添加:

target 'Runner' douse_frameworks!

如需使用Swift Package Manager,启用Swift支持:

flutter config --enable-swift-package-manager

使用说明

基础用法

打开应用的设置页面:

Widget build(BuildContext context) {return ElevatedButton(onPressed: () => AppSettings.openAppSettings(),child: const Text('打开应用设置'),);
}

指定设置类型

打开特定类型的设置页面:

Widget build(BuildContext context) {return ElevatedButton(onPressed: () => AppSettings.openAppSettings(type: AppSettingsType.location),child: const Text('打开位置设置'),);
}

Android Q设置面板

在Android Q及以上版本打开设置面板:

Widget build(BuildContext context) {return ElevatedButton(onPressed: () => AppSettings.openAppSettingsPanel(AppSettingsPanelType.volume),child: const Text('打开音量设置面板'),);
}

支持的所有设置类型

插件支持打开以下设置类型:

  • 应用设置 (AppSettingsType.settings)
  • 位置设置 (AppSettingsType.location)
  • Wi-Fi设置 (AppSettingsType.wifi)
  • 蓝牙设置 (AppSettingsType.bluetooth)
  • 通知设置 (AppSettingsType.notification)
  • 声音设置 (AppSettingsType.sound)
  • 显示设置 (AppSettingsType.display)
  • 日期设置 (AppSettingsType.date)
  • 应用语言设置 (AppSettingsType.appLocale) - Android 13+
  • 开发者设置 (AppSettingsType.developer)
  • 以及其他系统设置

核心代码

主要API调用

/// 打开应用设置的主方法
/// [type]: 设置类型,默认为通用设置
/// [asAnotherTask]: Android平台是否在新Activity中打开
Future<void> openAppSettings({AppSettingsType type = AppSettingsType.settings,bool asAnotherTask = false,
}) async {// 实现平台特定的设置打开逻辑// iOS使用UIApplication.openSettingsURLString// Android使用Intent跳转到对应设置页面
}

Android平台实现

/// Android平台的设置打开实现
Future<void> _openAppSettingsAndroid(AppSettingsType type, bool asAnotherTask) async {// 根据设置类型构建对应的Intentfinal Intent intent = _getSettingsIntent(type);// 设置Intent标志位if (asAnotherTask) {intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);}// 启动设置Activityawait _channel.invokeMethod('openAppSettings', {'intent': intent.toUri(0),'asAnotherTask': asAnotherTask,});
}

iOS平台实现

/// iOS平台的设置打开实现
Future<void> _openAppSettingsIOS(AppSettingsType type) async {final String urlString;// 根据设置类型构建对应的URL Schemeswitch (type) {case AppSettingsType.location:urlString = 'App-Prefs:root=Privacy&path=LOCATION';break;case AppSettingsType.wifi:urlString = 'App-Prefs:root=WIFI';break;// 其他设置类型的URL Scheme处理default:urlString = UIApplication.openSettingsURLString;}// 通过URL打开系统设置if (await canLaunch(urlString)) {await launch(urlString);}
}

设置面板支持

/// Android Q设置面板打开方法
Future<void> openAppSettingsPanel(AppSettingsPanelType type) async {// 检查Android版本,仅Q及以上支持if (defaultTargetPlatform == TargetPlatform.android) {final String panelType = _getPanelTypeString(type);await _channel.invokeMethod('openAppSettingsPanel', {'panelType': panelType,});} else {// 其他平台回退到通用设置await openAppSettings();}
}

该插件提供了简洁易用的API,让开发者能够轻松地在Flutter应用中集成系统设置跳转功能,提升用户体验。
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
对网络安全、黑客技术感兴趣的朋友可以关注我的安全公众号(网络安全技术点滴分享)

公众号二维码

公众号二维码

http://www.gsyq.cn/news/25662.html

相关文章:

  • CSP-S 22
  • /usr/bin/sudo 二进制文件的权限有问题,导致所有用户都无法使用 sudo
  • CSP-S 19
  • 研1转码自学黑马程序员Python第7天 | Python函数知识 - 指南
  • 从C10K到Reactor:事件驱动,如何重塑高并发服务器的网络架构
  • 数据范围
  • CF2107E Ain and Apple Tree
  • 2025,为什么公众号编辑器排版决定阅读完成率?——一次从流程到结果的深评
  • P14262 [ROI 2015 Day1] 自动好友
  • win10 升级 win11 后时间更新失败
  • Hands on Deep Learning Chapter 3 线性神经网络
  • 超越技术范畴:低代码如何重塑企业数字文化
  • 详细介绍:1、手把手教你入门设计半桥LLC开关电源设计,LLC谐振腔器件计算
  • 十六天
  • 20251019
  • 【上青了】
  • [VIM] reverse multiple lines in VIM
  • Tuack 生成比赛题目 PDF 笔记
  • 4060显卡也能玩转AI改图!Flux.1 Kontext Dev GGUF版本超详细入门教程 - 实践
  • 提升生产力:8个.NET开源且功能强大的快速开发框架
  • 使用c++14标准实现函数注册包装
  • 【VSCode中Java创建环境安装的三个层级之Maven篇】(Windows版)
  • 2025年不锈钢酸洗钝化液厂家推荐排行榜,环保型不锈钢管酸洗钝化液,不锈钢清洗钝化液,酸洗钝化处理工艺及不锈钢清洗剂公司推荐
  • 2025年法兰保护罩厂家推荐排行榜,阀门保温罩,法兰罩,法兰防溅罩,法兰保护套,专业防护与定制服务优质供应商
  • 百度网盘非会员下载慢怎么解决 - fosgrignonhto
  • d435i 标定 imu和相机 用来复现vins_fusion - 教程
  • K230基础-摄像头的使用 - 详解
  • 2025年市面上高杆灯品牌Top10权威推荐榜单
  • Spring AOP 原理
  • 250921