ResponsiveSpacing 是一个 Flutter/Dart 包,可让开发者通过根据屏幕尺寸动态调整间距、边距、内边距、列间距、正文大小和列布局,创建自适应和响应式用户界面。它简化了在 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台上的响应式设计。通过使用内置的响应式单位和断点,确保无论设备尺寸如何,UI 外观都保持一致。非常适合需要灵活布局而无需编写重复媒体查询逻辑的应用。
适合场景
构建跨平台响应式布局
为不同屏幕尺寸调整用户界面
创建流体网格系统
自动调整填充和边距
设计可扩展的移动和Web界面
主要特点
基于屏幕尺寸的动态间距
内置响应式断点
支持边距、内边距和间距
跨平台兼容性
与现有 Flutter 小部件的轻松集成
灵活的列和正文大小控制
适合对象
开发响应式 Flutter 应用的开发者
针对多个平台的团队
专注于适应性的UI设计师
需要可扩展布局系统的项目
具有复杂响应式需求的应用程序
使用建议
新用户可能需要一个初始的学习曲线
在非常大的小部件树中性能影响
依赖于准确的屏幕尺寸检测
最好与一致的设计系统一起使用
超出提供的响应式单位之外的自定义功能有限
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
This plugin helps to design and develop beautiful responsive and adaptive flutter apps.
Lightweight, Responsive Spacing
All design principles have roughly the same elements. For example, Material Design works with margin, gutter, body and has a responsive 12 column system.
Our default values are set by the Material Design Guidelines, but you can also easily set your own breakpoints, margins, and spacing.
You can find spacings everywhere in your Project, don't use Magic Numbers, use the context-oriented spacing class instead.
We have developed this plugin so that you can easily make your app adaptive and responsive.
Simple Spacing
Access your own Spacing-System:
// Example values for a Pixel 7 Pro
context.spacing.xs; // default 2
context.spacing.s; // default 8
context.spacing.m; // default 12
context.spacing.l; // default 16
context.spacing.xl; // default 32
context.spacing.xxl; // default 56// Example:// Instead of SizedBox(height: 8);
// useSizedBox(height: context.spacing.s); // Wow!
And whenever your design guru wants to modify the values, you only have to modify it in a single file.
Giga Spacing for all design chads that need more power
Design Gurus are around the world and you will maybe find one in your own company. If you have such a mysterious creature, use the Giga Spacing class for even more fine tuning.
In the previous Example, we used the any override, this will ignore the layout width. If you want to make the spacings responsive, override the values for xl, lg, md, sm2, sm1 & xs
And in your Widget, access the Spacing class with Spacing.of(context) or context.spacingConfig which returns an object of ResponsiveData. The object has all necessary spacings.
context.spacingConfig.margin;
context.spacingConfig.padding;
context.spacingConfig.gutter;
context.spacingConfig.body;
context.spacingConfig.layoutColumns;
// You are now good to use these properties in your layout.
For example with a Card:
Card(
// use margin
margin: context.spacingConfig.margin.horizontalEdgeInsets,
child: Padding(
// use padding
padding: context.spacingConfig.padding.allEdgeInsets,
child: Column(
children: [
Text("This is a Title"),
Text("This is the subtitle, usually you explain something")
],
),
),
)
Columns, Gutters & Margins
The responsive layout grid is made up of three elements: columns, gutters, and margins. Read everything about Columns, Gutters & Margins on the material guidelines responsive layout page.
Example: Access global padding setting in your widget:
Spacing.of(context).padding
// or
context.spacingConfig.padding
Just like the custom breakpoints, you can also set your own spacing, spaces, and margins. Create your own gutter class by extending ResponsiveCollection:
There are two types of widgets, the data widgets that create the spacing context and widgets that use the spacing context.
Data Widgets
Data widgets create the spacing context and provide responsive values to all widgets created in the tree below. if there are multiple data widgets in the tree, the closest one is taken.