一个专为创建跨平台原生外观的内嵌设置界面而设计的 Flutter 包。它提供了预先构建且可自定义的组件,模拟 Android、iOS、Web、macOS、Windows 和 Linux 系统设置的外观和感觉。该包简化了开发一致且精致的设置界面的过程,无需为每个平台手动定制样式。非常适合需要直观配置面板且设置简单的应用程序。
适合场景
构建跨平台设置 UI
创建应用首选项面板
实施主题和通知设置
设计可访问的配置屏幕
添加用户配置文件管理
启用应用自定义选项
主要特点
所有平台上的原生外观
预设计的、可重用的设置小部件
跨平台一致性
轻松集成到现有的 Flutter 应用中
对深色模式和辅助功能的支持
最少的样板代码
适合对象
开发功能丰富的移动和桌面应用程序的开发者
注重用户体验一致性的团队
需要大量用户配置的应用程序
Flutter 初学者寻找现成的 UI 组件
面向多个操作系统的项目
使用建议
需要 Flutter SDK 3.0 或更高版本
超出内置主题的自定义功能有限
可能需要额外的样式来实现高度独特的设计
依赖于平台特定的渲染行为
最适合标准设置布局,而非复杂表单
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
gizmos_settings_screen
A Flutter package for displaying settings screens (or similar screens). I built this after finding it near impossible to customize the look and feel of the other popular settings screen packages. This package takes a different approach and separates the functionality from the UI customization. This lets you create custom skins to better fit into your existing app. There are several skin prototypes included for Cupertino (light and dark modes), and Material (light and dark modes). In most cases, you can just subclass those, alter your colours and move on to the rest of your app.
This package doesn't depend on any specific package for settings storage. In fact, gizmos_settings_screen can be used for any type of general purpose cell based list, it's just that settings is the most obvious use case. The example application included uses shared_preferences, but I've also used flutter_secure_storage in production apps.
Check the included example app for full details. For basic usage, you need to instantiate a SkinDelegate using one of the supplied skins, or by create your own subclass of one of the supplied skins. Then customize a SettingsScreen by attaching one of more SettingsSections configured with one or more SettingsCell subclasses. Included subclasses include DetailsSettingCell, SwitchSettingsCell, 'SliderSettingsCellandButtonSettingsCell`. These will cover most of your basic needs, but it's trivial to create additional subclasses to handle specific options for your app.
Screenshots
Example
// Select the default skin to useSettingsSkinDelegate skinDelegate = !Platform.isIOS ? MaterialSettingsSkin() : CupertinoSettingsSkin();
// Return the configured SettingsScreen wrapped in a SettingsSkin with an assigned delegatereturnSettingsSkin(
delegate: skinDelegate,
child: SettingsScreen(
sections: [
SettingsSection(
header: 'App Settings',
footer: 'Your app preferences are set here',
cells: [
DetailsSettingsCell(
title: 'Informational',
subtitle: 'Can include simple cells',
leadingWidget: Icon(
Icons.star,
color: Colors.blue,
),
),
SwitchSettingsCell(
title: 'Toggleable option',
subtitle: 'Uses a switch to set something on or off',
value: sampleBooleanSetting,
onPressed: () {
setState(() {
sampleBooleanSetting = !sampleBooleanSetting;
});
},
onChanged: (bool value) {
setState(() {
sampleBooleanSetting = value;
});
},
),
SliderSettingsCell(
title: 'Fractional option (i.e. Volume)',
subtitle: 'Uses a slider to adjust a double',
value: sampleDoubleSetting,
onChanged: (value) {
setState(() {
sampleDoubleSetting = value;
});
},
),
DetailsSettingsCell(
title: 'Multiple choice option',
value: preferences.currentOption.description,
accessoryType: AccessoryType.Disclosure,
onPressed: () async {
// Your code goes here
},
),
ButtonSettingsCell(
type: ButtonType.Normal,
title: 'Check for updates',
onPressed: () async {
// Your code goes here
},
),
],
),
],
),
);
Please see the example app in this package for a full example.
Notes
This is my second Flutter package, and I'm still learning the Flutter way of doing things so a lot of this package may change. Specifically, I'll be looking to make use of ThemeData etc in the skins to reduce duplication of having to set specific colours for your app.