mta-mcp 2.17.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/flutter.agent.md +23 -64
- package/agents/mta.agent.md +226 -0
- package/agents/vue3.agent.md +24 -0
- package/agents/wechat-miniprogram.agent.md +23 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/standards/mcp-tools/sketch-mcp.md +497 -0
- package/standards/patterns/design-system-restoration.md +570 -0
- package/standards/syntax-mapping.md +256 -0
- package/standards/workflows/design-restoration.md +401 -0
- package/templates/README.md +14 -0
- package/templates/design-measurement/README.md +81 -0
- package/templates/design-measurement/component-measurement.js +52 -0
- package/templates/design-measurement/gap-measurement.js +79 -0
- package/templates/design-measurement/style-extraction.js +109 -0
- package/common/i18n.md +0 -385
- package/common/typescript-strict.md +0 -186
- package/troubleshooting/README.md +0 -368
- package/troubleshooting/USAGE_GUIDE.md +0 -289
- package/troubleshooting/flutter/clip-/351/230/264/345/275/261/350/243/201/345/211/252.md +0 -244
- package/troubleshooting/flutter/input-/345/255/227/346/256/265/347/274/272/345/244/261.md +0 -240
- package/troubleshooting/flutter/input-/350/276/271/346/241/206/351/227/256/351/242/230.md +0 -236
- package/troubleshooting/flutter/layout-/345/260/272/345/257/270/344/270/215/345/214/271/351/205/215.md +0 -214
- package/troubleshooting/flutter/shadow-/351/200/217/345/207/272/351/227/256/351/242/230.md +0 -172
- package/troubleshooting/flutter/sketch-/345/210/227/350/241/250item/345/214/272/345/237/237.md +0 -212
- package/troubleshooting/flutter/sketch-/345/233/276/346/240/207/345/260/272/345/257/270.md +0 -135
- package/troubleshooting/flutter/sketch-/345/256/214/346/225/264/346/217/220/345/217/226.md +0 -201
- package/troubleshooting/flutter/sketch-/345/261/236/346/200/247/346/234/252/344/275/277/347/224/250.md +0 -139
- package/troubleshooting/flutter/sketch-/350/203/214/346/231/257/345/261/202/351/253/230/345/272/246.md +0 -264
- package/troubleshooting/flutter/svg-/346/234/252/345/261/205/344/270/255.md +0 -120
- package/troubleshooting/flutter/svg-/351/242/234/350/211/262/345/274/202/345/270/270.md +0 -117
- package/troubleshooting/flutter/tabbar-/345/212/250/347/224/273/345/220/214/346/255/245.md +0 -107
- package/troubleshooting/flutter/withopacity-/345/274/203/347/224/250.md +0 -81
- package/troubleshooting/vue3/cascader-/350/257/257/346/233/277/346/215/242.md +0 -130
- package/troubleshooting/vue3/drawer-input-/346/240/267/345/274/217.md +0 -181
- package/troubleshooting/vue3/table-/347/274/226/350/276/221/345/217/226/346/266/210.md +0 -148
- package/troubleshooting/vue3/table-/350/276/271/346/241/206/351/227/256/351/242/230.md +0 -178
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
# Flutter 组件字段缺失问题
|
|
2
|
-
|
|
3
|
-
> **问题标签**: `component`, `props`, `missing-field`, `custom-widget`
|
|
4
|
-
> **问题类型**: 组件配置
|
|
5
|
-
> **框架**: Flutter
|
|
6
|
-
> **严重程度**: 低(编译错误,容易发现)
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 🔍 问题识别
|
|
11
|
-
|
|
12
|
-
### 自动检测特征
|
|
13
|
-
|
|
14
|
-
```dart
|
|
15
|
-
// 编译错误信息
|
|
16
|
-
The named parameter 'showBorder' isn't defined
|
|
17
|
-
The named parameter 'shadow' isn't defined
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
### 用户描述关键词
|
|
21
|
-
- "组件不支持这个属性"
|
|
22
|
-
- "字段未定义"
|
|
23
|
-
- "参数不存在"
|
|
24
|
-
- "自定义组件缺少配置"
|
|
25
|
-
|
|
26
|
-
### 问题特征
|
|
27
|
-
- [ ] 编译错误:`The named parameter 'xxx' isn't defined`
|
|
28
|
-
- [ ] 自定义组件无法接收某些属性
|
|
29
|
-
- [ ] IDE 提示参数不存在
|
|
30
|
-
- [ ] 想配置组件样式但没有对应的属性
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## ❌ 常见错误排查路线(避免重复)
|
|
35
|
-
|
|
36
|
-
| 尝试方向 | 为什么无效 | 浪费时间 |
|
|
37
|
-
|----------|-----------|---------|
|
|
38
|
-
| 直接在使用处添加样式 | 破坏组件封装性 | 1 轮对话 |
|
|
39
|
-
| 修改组件内部硬编码 | 失去可配置性 | 1-2 轮对话 |
|
|
40
|
-
| 复制组件代码到页面 | 违反 DRY 原则 | 1 轮对话 |
|
|
41
|
-
|
|
42
|
-
**总计浪费**: 2-4 轮对话
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## ✅ 正确解决方案
|
|
47
|
-
|
|
48
|
-
### 核心原理
|
|
49
|
-
|
|
50
|
-
**问题根源**:自定义组件(如 `FlexInput`)在设计时未预留足够的可配置字段。
|
|
51
|
-
|
|
52
|
-
### 解决步骤
|
|
53
|
-
|
|
54
|
-
#### 1. 检查组件定义
|
|
55
|
-
|
|
56
|
-
找到组件源文件(如 `lib/core/themes/flex_widgets.dart`)
|
|
57
|
-
|
|
58
|
-
#### 2. 补充缺失字段
|
|
59
|
-
|
|
60
|
-
```dart
|
|
61
|
-
class FlexInput extends StatelessWidget {
|
|
62
|
-
const FlexInput({
|
|
63
|
-
super.key,
|
|
64
|
-
// ... 已有字段
|
|
65
|
-
this.controller,
|
|
66
|
-
this.hintText,
|
|
67
|
-
this.inputType = TextInputType.text,
|
|
68
|
-
|
|
69
|
-
// ← 新增字段
|
|
70
|
-
this.showBorder = true,
|
|
71
|
-
this.shadow,
|
|
72
|
-
this.borderColor,
|
|
73
|
-
this.borderWidth = 1.0,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// 已有属性
|
|
77
|
-
final TextEditingController? controller;
|
|
78
|
-
final String? hintText;
|
|
79
|
-
final TextInputType inputType;
|
|
80
|
-
|
|
81
|
-
// ← 新增属性
|
|
82
|
-
final bool showBorder;
|
|
83
|
-
final List<BoxShadow>? shadow;
|
|
84
|
-
final Color? borderColor;
|
|
85
|
-
final double borderWidth;
|
|
86
|
-
|
|
87
|
-
@override
|
|
88
|
-
Widget build(BuildContext context) {
|
|
89
|
-
return Container(
|
|
90
|
-
decoration: BoxDecoration(
|
|
91
|
-
// ← 使用新增的属性
|
|
92
|
-
border: showBorder
|
|
93
|
-
? Border.all(
|
|
94
|
-
color: borderColor ?? $c.border,
|
|
95
|
-
width: borderWidth,
|
|
96
|
-
)
|
|
97
|
-
: null,
|
|
98
|
-
boxShadow: shadow,
|
|
99
|
-
// ... 其他样式
|
|
100
|
-
),
|
|
101
|
-
child: TextField(
|
|
102
|
-
controller: controller,
|
|
103
|
-
decoration: InputDecoration(
|
|
104
|
-
hintText: hintText,
|
|
105
|
-
// ...
|
|
106
|
-
),
|
|
107
|
-
),
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### 3. 使用新字段
|
|
114
|
-
|
|
115
|
-
```dart
|
|
116
|
-
// 现在可以配置了
|
|
117
|
-
FlexInput(
|
|
118
|
-
hintText: 'Enter phone',
|
|
119
|
-
showBorder: false, // ← 新增
|
|
120
|
-
shadow: [ // ← 新增
|
|
121
|
-
BoxShadow(
|
|
122
|
-
color: Color(0x0D000000),
|
|
123
|
-
blurRadius: 3,
|
|
124
|
-
offset: Offset(0, 1),
|
|
125
|
-
),
|
|
126
|
-
],
|
|
127
|
-
)
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## 📋 组件设计最佳实践
|
|
133
|
-
|
|
134
|
-
### 必须预留的常用字段
|
|
135
|
-
|
|
136
|
-
#### 样式相关
|
|
137
|
-
```dart
|
|
138
|
-
// 边框
|
|
139
|
-
final bool showBorder;
|
|
140
|
-
final Color? borderColor;
|
|
141
|
-
final double borderWidth;
|
|
142
|
-
final BorderRadius? borderRadius;
|
|
143
|
-
|
|
144
|
-
// 阴影
|
|
145
|
-
final List<BoxShadow>? shadow;
|
|
146
|
-
|
|
147
|
-
// 背景
|
|
148
|
-
final Color? backgroundColor;
|
|
149
|
-
final Gradient? gradient;
|
|
150
|
-
|
|
151
|
-
// 尺寸
|
|
152
|
-
final double? width;
|
|
153
|
-
final double? height;
|
|
154
|
-
final EdgeInsets? padding;
|
|
155
|
-
final EdgeInsets? margin;
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### 交互相关
|
|
159
|
-
```dart
|
|
160
|
-
// 状态
|
|
161
|
-
final bool enabled;
|
|
162
|
-
final bool readOnly;
|
|
163
|
-
|
|
164
|
-
// 回调
|
|
165
|
-
final VoidCallback? onTap;
|
|
166
|
-
final ValueChanged<String>? onChanged;
|
|
167
|
-
final VoidCallback? onSubmitted;
|
|
168
|
-
|
|
169
|
-
// 验证
|
|
170
|
-
final String? Function(String?)? validator;
|
|
171
|
-
final bool showError;
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### 组件设计检查清单
|
|
175
|
-
|
|
176
|
-
- [ ] 是否支持自定义颜色?
|
|
177
|
-
- [ ] 是否支持自定义尺寸?
|
|
178
|
-
- [ ] 是否支持显示/隐藏边框?
|
|
179
|
-
- [ ] 是否支持阴影配置?
|
|
180
|
-
- [ ] 是否支持禁用/只读状态?
|
|
181
|
-
- [ ] 回调函数是否足够?
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
## 💡 预防措施
|
|
186
|
-
|
|
187
|
-
### 1. 使用 Token 系统
|
|
188
|
-
|
|
189
|
-
```dart
|
|
190
|
-
// ✅ 推荐:使用 Token 作为默认值
|
|
191
|
-
final Color borderColor;
|
|
192
|
-
|
|
193
|
-
FlexInput({
|
|
194
|
-
this.borderColor = $c.border, // Token 默认值
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
// ❌ 避免:硬编码
|
|
198
|
-
final Color borderColor = Color(0xFFDDDDDD);
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### 2. 参考 Material/Cupertino 组件
|
|
202
|
-
|
|
203
|
-
Flutter 官方组件的属性设计很完善,可以参考:
|
|
204
|
-
|
|
205
|
-
```dart
|
|
206
|
-
// TextField 的部分属性
|
|
207
|
-
TextField(
|
|
208
|
-
decoration: InputDecoration(
|
|
209
|
-
border: ...,
|
|
210
|
-
enabledBorder: ...,
|
|
211
|
-
focusedBorder: ...,
|
|
212
|
-
filled: ...,
|
|
213
|
-
fillColor: ...,
|
|
214
|
-
),
|
|
215
|
-
style: ...,
|
|
216
|
-
enabled: ...,
|
|
217
|
-
readOnly: ...,
|
|
218
|
-
)
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### 3. 渐进式添加属性
|
|
222
|
-
|
|
223
|
-
**不要一开始就添加所有属性**,遵循 YAGNI 原则:
|
|
224
|
-
1. 先实现基础功能
|
|
225
|
-
2. 使用时发现缺少属性
|
|
226
|
-
3. 及时补充属性
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
## 🔗 相关案例
|
|
231
|
-
|
|
232
|
-
- [layout-尺寸不匹配](./layout-尺寸不匹配.md) - 组件的精确尺寸配置
|
|
233
|
-
- [shadow-透出问题](./shadow-透出问题.md) - CustomPainter 组件的属性设计
|
|
234
|
-
|
|
235
|
-
---
|
|
236
|
-
|
|
237
|
-
**来源**: my_flutter 项目实战经验
|
|
238
|
-
**创建日期**: 2025-12-31
|
|
239
|
-
**最后验证**: 2026-01-16
|
|
240
|
-
**节省时间**: 2-4 轮对话
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
# Flutter TextField 边框和背景问题
|
|
2
|
-
|
|
3
|
-
> **问题标签**: `textfield`, `input`, `border`, `focus`, `theme`
|
|
4
|
-
> **问题类型**: 主题冲突
|
|
5
|
-
> **框架**: Flutter
|
|
6
|
-
> **严重程度**: 中等
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 🔍 问题识别
|
|
11
|
-
|
|
12
|
-
### 自动检测特征
|
|
13
|
-
|
|
14
|
-
```dart
|
|
15
|
-
// 只设置了 border 但没设置其他状态
|
|
16
|
-
TextField(
|
|
17
|
-
decoration: InputDecoration(
|
|
18
|
-
border: InputBorder.none, // 不够!
|
|
19
|
-
),
|
|
20
|
-
)
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 用户描述关键词
|
|
24
|
-
- "TextField 聚焦时出现蓝色边框"
|
|
25
|
-
- "输入框背景颜色变了"
|
|
26
|
-
- "只设置了 border: InputBorder.none 但还有边框"
|
|
27
|
-
- "新拟态输入框样式被覆盖"
|
|
28
|
-
|
|
29
|
-
### 问题特征
|
|
30
|
-
- [ ] TextField 聚焦时出现蓝色边框
|
|
31
|
-
- [ ] TextField 聚焦时背景颜色变化
|
|
32
|
-
- [ ] 只设置了 `border: InputBorder.none` 但边框仍存在
|
|
33
|
-
- [ ] 新拟态输入框样式被全局主题覆盖
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## ❌ 常见错误排查路线(避免重复)
|
|
38
|
-
|
|
39
|
-
| 尝试方向 | 为什么无效 | 浪费时间 |
|
|
40
|
-
|----------|-----------|---------|
|
|
41
|
-
| 只设置 `border: InputBorder.none` | 不覆盖 focusedBorder 等状态 | 1-2 轮对话 |
|
|
42
|
-
| 组件级覆盖但不完整 | 全局主题的其他状态仍生效 | 2-3 轮对话 |
|
|
43
|
-
| 修改颜色为透明 | 边框仍存在,只是看不见 | 1 轮对话 |
|
|
44
|
-
| 不知道是全局主题的问题 | 反复修改组件级样式 | 2-3 轮对话 |
|
|
45
|
-
|
|
46
|
-
**总计浪费**: 6-9 轮对话
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
## ✅ 正确解决方案
|
|
51
|
-
|
|
52
|
-
### 核心原理
|
|
53
|
-
|
|
54
|
-
#### 原因1: Flutter InputDecoration 边框机制
|
|
55
|
-
|
|
56
|
-
Flutter 的 `InputDecoration.border` 只是**默认值**,各状态有独立的边框属性:
|
|
57
|
-
- `enabledBorder` - 启用状态
|
|
58
|
-
- `focusedBorder` - 聚焦状态 ⚠️ **最常见问题**
|
|
59
|
-
- `disabledBorder` - 禁用状态
|
|
60
|
-
- `errorBorder` - 错误状态
|
|
61
|
-
- `focusedErrorBorder` - 聚焦+错误状态
|
|
62
|
-
|
|
63
|
-
**只设置 `border` 不会覆盖其他状态的边框!**
|
|
64
|
-
|
|
65
|
-
#### 原因2: 全局主题干扰
|
|
66
|
-
|
|
67
|
-
`ThemeData.inputDecorationTheme` 会注入默认样式:
|
|
68
|
-
|
|
69
|
-
```dart
|
|
70
|
-
// 全局主题中的问题配置
|
|
71
|
-
inputDecorationTheme: InputDecorationTheme(
|
|
72
|
-
focusedBorder: OutlineInputBorder(
|
|
73
|
-
borderSide: BorderSide(color: Colors.blue, width: 2), // 蓝框来源!
|
|
74
|
-
),
|
|
75
|
-
filled: true, // 导致背景变色!
|
|
76
|
-
),
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 解决步骤
|
|
80
|
-
|
|
81
|
-
#### 方案1: 全局主题移除边框(推荐)
|
|
82
|
-
|
|
83
|
-
修改 `lib/core/themes/app_theme.dart` 和 `theme_manager.dart`:
|
|
84
|
-
|
|
85
|
-
```dart
|
|
86
|
-
ThemeData(
|
|
87
|
-
// ... 其他配置
|
|
88
|
-
inputDecorationTheme: InputDecorationTheme(
|
|
89
|
-
filled: true,
|
|
90
|
-
fillColor: Colors.transparent, // 透明填充
|
|
91
|
-
|
|
92
|
-
// ← 关键:所有状态都设为无边框
|
|
93
|
-
border: InputBorder.none,
|
|
94
|
-
enabledBorder: InputBorder.none,
|
|
95
|
-
focusedBorder: InputBorder.none,
|
|
96
|
-
disabledBorder: InputBorder.none,
|
|
97
|
-
errorBorder: InputBorder.none,
|
|
98
|
-
focusedErrorBorder: InputBorder.none,
|
|
99
|
-
|
|
100
|
-
// 其他样式...
|
|
101
|
-
isDense: true,
|
|
102
|
-
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
103
|
-
),
|
|
104
|
-
)
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### 方案2: 组件级完整覆盖
|
|
108
|
-
|
|
109
|
-
在 `TextField` 或自定义输入组件中:
|
|
110
|
-
|
|
111
|
-
```dart
|
|
112
|
-
TextField(
|
|
113
|
-
decoration: InputDecoration(
|
|
114
|
-
// 禁用填充背景
|
|
115
|
-
filled: false,
|
|
116
|
-
fillColor: Colors.transparent,
|
|
117
|
-
|
|
118
|
-
// ← 关键:移除所有状态下的边框
|
|
119
|
-
border: InputBorder.none,
|
|
120
|
-
enabledBorder: InputBorder.none,
|
|
121
|
-
focusedBorder: InputBorder.none, // 必须!
|
|
122
|
-
disabledBorder: InputBorder.none,
|
|
123
|
-
errorBorder: InputBorder.none,
|
|
124
|
-
focusedErrorBorder: InputBorder.none,
|
|
125
|
-
|
|
126
|
-
// 紧凑布局
|
|
127
|
-
isDense: true,
|
|
128
|
-
contentPadding: EdgeInsets.zero,
|
|
129
|
-
|
|
130
|
-
// 提示文本
|
|
131
|
-
hintText: '请输入',
|
|
132
|
-
hintStyle: TextStyle(color: Colors.grey),
|
|
133
|
-
),
|
|
134
|
-
)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## 📋 完整修复示例
|
|
140
|
-
|
|
141
|
-
### 全局主题配置
|
|
142
|
-
|
|
143
|
-
```dart
|
|
144
|
-
// lib/core/themes/app_theme.dart
|
|
145
|
-
class AppTheme {
|
|
146
|
-
static ThemeData lightTheme = ThemeData(
|
|
147
|
-
// ... 其他配置
|
|
148
|
-
|
|
149
|
-
inputDecorationTheme: const InputDecorationTheme(
|
|
150
|
-
// 禁用填充背景,避免 focus 时背景色变化
|
|
151
|
-
filled: false,
|
|
152
|
-
fillColor: Colors.transparent,
|
|
153
|
-
|
|
154
|
-
// 移除所有状态下的边框
|
|
155
|
-
border: InputBorder.none,
|
|
156
|
-
enabledBorder: InputBorder.none,
|
|
157
|
-
focusedBorder: InputBorder.none,
|
|
158
|
-
disabledBorder: InputBorder.none,
|
|
159
|
-
errorBorder: InputBorder.none,
|
|
160
|
-
focusedErrorBorder: InputBorder.none,
|
|
161
|
-
|
|
162
|
-
// 紧凑布局
|
|
163
|
-
isDense: true,
|
|
164
|
-
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
165
|
-
),
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### 自定义输入组件
|
|
171
|
-
|
|
172
|
-
```dart
|
|
173
|
-
class AppInputSection extends StatelessWidget {
|
|
174
|
-
Widget _buildTextField() {
|
|
175
|
-
return TextField(
|
|
176
|
-
controller: controller,
|
|
177
|
-
style: TextStyle(
|
|
178
|
-
fontSize: 32,
|
|
179
|
-
fontWeight: FontWeight.w800,
|
|
180
|
-
color: AppColors.textDark,
|
|
181
|
-
),
|
|
182
|
-
decoration: InputDecoration(
|
|
183
|
-
// 双重保险:组件级也禁用
|
|
184
|
-
filled: false,
|
|
185
|
-
fillColor: Colors.transparent,
|
|
186
|
-
|
|
187
|
-
// 完整覆盖所有边框状态
|
|
188
|
-
border: InputBorder.none,
|
|
189
|
-
enabledBorder: InputBorder.none,
|
|
190
|
-
focusedBorder: InputBorder.none,
|
|
191
|
-
disabledBorder: InputBorder.none,
|
|
192
|
-
errorBorder: InputBorder.none,
|
|
193
|
-
focusedErrorBorder: InputBorder.none,
|
|
194
|
-
|
|
195
|
-
// 紧凑布局
|
|
196
|
-
isDense: true,
|
|
197
|
-
contentPadding: EdgeInsets.zero,
|
|
198
|
-
|
|
199
|
-
// 提示文本
|
|
200
|
-
hintText: hint,
|
|
201
|
-
hintStyle: TextStyle(color: AppColors.textDarkTertiary),
|
|
202
|
-
),
|
|
203
|
-
onChanged: onChanged,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
## 💡 边框状态完整对照表
|
|
212
|
-
|
|
213
|
-
| 状态 | 属性 | 何时生效 | 优先级 |
|
|
214
|
-
|------|------|---------|--------|
|
|
215
|
-
| 默认 | `border` | 其他状态未设置时 | 最低 |
|
|
216
|
-
| 启用 | `enabledBorder` | 输入框可用但未聚焦 | 中 |
|
|
217
|
-
| 聚焦 | `focusedBorder` | 输入框获得焦点 | **高** ⭐ |
|
|
218
|
-
| 禁用 | `disabledBorder` | 输入框被禁用 | 中 |
|
|
219
|
-
| 错误 | `errorBorder` | 验证失败 | 中 |
|
|
220
|
-
| 聚焦错误 | `focusedErrorBorder` | 验证失败且聚焦 | 高 |
|
|
221
|
-
|
|
222
|
-
**最常见的错位**:只设置 `border`,忽略了 `focusedBorder`!
|
|
223
|
-
|
|
224
|
-
---
|
|
225
|
-
|
|
226
|
-
## 🔗 相关案例
|
|
227
|
-
|
|
228
|
-
- [shadow-透出问题](./shadow-透出问题.md) - 新拟态输入框的阴影实现
|
|
229
|
-
- [layout-尺寸不匹配](./layout-尺寸不匹配.md) - 输入框精确布局
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
**来源**: my_flutter 项目实战经验
|
|
234
|
-
**创建日期**: 2025-12-31
|
|
235
|
-
**最后验证**: 2026-01-16
|
|
236
|
-
**节省时间**: 6-9 轮对话
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
# Flutter 布局尺寸不匹配问题
|
|
2
|
-
|
|
3
|
-
> **问题标签**: `layout`, `sizing`, `design-spec`, `position`, `padding`
|
|
4
|
-
> **问题类型**: 布局偏差
|
|
5
|
-
> **框架**: Flutter
|
|
6
|
-
> **严重程度**: 中等
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 🔍 问题识别
|
|
11
|
-
|
|
12
|
-
### 自动检测特征
|
|
13
|
-
|
|
14
|
-
```dart
|
|
15
|
-
// 代码模式匹配 - 使用自动布局
|
|
16
|
-
Row(
|
|
17
|
-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
18
|
-
children: [...]
|
|
19
|
-
)
|
|
20
|
-
// 或
|
|
21
|
-
Expanded(child: ...)
|
|
22
|
-
// 或缺少明确的尺寸
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### 用户描述关键词
|
|
26
|
-
- "位置跟设计稿不一样"
|
|
27
|
-
- "间距不对"
|
|
28
|
-
- "元素偏移了"
|
|
29
|
-
- "尺寸不匹配"
|
|
30
|
-
- "布局差不多但不精确"
|
|
31
|
-
|
|
32
|
-
### 问题特征
|
|
33
|
-
- [ ] 输入框内元素间距与设计稿不符
|
|
34
|
-
- [ ] 国旗/图标/分隔线位置偏移
|
|
35
|
-
- [ ] 容器宽高与设计稿不一致
|
|
36
|
-
- [ ] 边框粗细或圆角不对
|
|
37
|
-
- [ ] 使用了 `MainAxisAlignment` 自动分布
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## ❌ 常见错误排查路线(避免重复)
|
|
42
|
-
|
|
43
|
-
| 尝试方向 | 为什么无效 | 浪费时间 |
|
|
44
|
-
|----------|-----------|---------|
|
|
45
|
-
| 调整 padding/margin 值 | 依赖猜测,无法精确 | 2-3 轮对话 |
|
|
46
|
-
| 使用 `MainAxisAlignment.spaceBetween` | 间距不可控 | 1-2 轮对话 |
|
|
47
|
-
| 依赖 `Expanded` 自动填充 | 宽度与设计稿不符 | 1-2 轮对话 |
|
|
48
|
-
| 忽略设计稿像素值 | 总是"差不多"但不精确 | 持续问题 |
|
|
49
|
-
|
|
50
|
-
**总计浪费**: 4-7 轮对话
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## ✅ 正确解决方案
|
|
55
|
-
|
|
56
|
-
### 核心原理
|
|
57
|
-
|
|
58
|
-
**问题根源**:未从设计稿提取精确坐标,依赖 Flutter 的自动布局系统。
|
|
59
|
-
|
|
60
|
-
Flutter 的 `Row`、`MainAxisAlignment`、`Expanded` 等会自动分配空间,但这种"自动"无法保证与设计稿完全一致。
|
|
61
|
-
|
|
62
|
-
### 解决步骤
|
|
63
|
-
|
|
64
|
-
#### 1. 从设计稿提取精确坐标
|
|
65
|
-
|
|
66
|
-
使用 Sketch MCP 工具或设计软件获取每个元素的精确位置:
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
设计稿规格示例 (国家代码选择器):
|
|
70
|
-
- 容器: 290x54, 圆角16
|
|
71
|
-
- 国旗 emoji: x=12, fontSize=20
|
|
72
|
-
- +61 文字: x=40, fontSize=15, fontWeight=600
|
|
73
|
-
- 下拉箭头: x=76, size=16x16
|
|
74
|
-
- 分隔线: x=98, 1x34
|
|
75
|
-
- 输入区起点: x=110
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
#### 2. 使用固定宽度而非弹性布局
|
|
79
|
-
|
|
80
|
-
```dart
|
|
81
|
-
// ❌ 错误:依赖自动布局
|
|
82
|
-
Row(
|
|
83
|
-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
84
|
-
children: [国旗, 区号, 箭头, 分隔线, 输入框],
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
// ✅ 正确:固定宽度容器
|
|
88
|
-
Row(
|
|
89
|
-
children: [
|
|
90
|
-
Container(
|
|
91
|
-
width: 98, // 精确到分隔线位置 (设计稿 x=98)
|
|
92
|
-
padding: const EdgeInsets.only(left: 12), // 国旗起点 x=12
|
|
93
|
-
child: Row(
|
|
94
|
-
children: [
|
|
95
|
-
const Text('🇦🇺', style: TextStyle(fontSize: 20)),
|
|
96
|
-
const SizedBox(width: 5), // 间距精确计算:40 - 12 - 20 = 8(约5)
|
|
97
|
-
const Text(
|
|
98
|
-
'+61',
|
|
99
|
-
style: TextStyle(
|
|
100
|
-
fontSize: 15,
|
|
101
|
-
fontWeight: FontWeight.w600,
|
|
102
|
-
color: Color(0xFF1C2B45),
|
|
103
|
-
),
|
|
104
|
-
),
|
|
105
|
-
const SizedBox(width: 4), // 间距:76 - 40 - 文字宽度
|
|
106
|
-
const Icon(Icons.keyboard_arrow_down, size: 16, color: Color(0x44CCCCCC)),
|
|
107
|
-
],
|
|
108
|
-
),
|
|
109
|
-
),
|
|
110
|
-
Container(
|
|
111
|
-
width: 1,
|
|
112
|
-
height: 34,
|
|
113
|
-
color: const Color(0x331C2B45)
|
|
114
|
-
), // 分隔线
|
|
115
|
-
Expanded(child: TextField(...)), // 输入区从 x=110 开始
|
|
116
|
-
],
|
|
117
|
-
)
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### 3. 精确设置边框和圆角
|
|
121
|
-
|
|
122
|
-
```dart
|
|
123
|
-
decoration: BoxDecoration(
|
|
124
|
-
borderRadius: BorderRadius.circular(16), // 设计稿圆角值
|
|
125
|
-
border: Border.all(
|
|
126
|
-
color: const Color(0x99FFFFFF), // 设计稿边框颜色
|
|
127
|
-
width: 1, // 设计稿边框粗细
|
|
128
|
-
),
|
|
129
|
-
),
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## 📋 精确还原检查清单
|
|
135
|
-
|
|
136
|
-
### 必须从设计稿读取的值
|
|
137
|
-
|
|
138
|
-
- [ ] **容器尺寸**: width, height
|
|
139
|
-
- [ ] **圆角**: borderRadius 值
|
|
140
|
-
- [ ] **边框**: color, width
|
|
141
|
-
- [ ] **内边距**: padding (top, right, bottom, left)
|
|
142
|
-
- [ ] **元素坐标**: 每个子元素的 x, y 位置
|
|
143
|
-
- [ ] **间距**: SizedBox 的精确数值
|
|
144
|
-
- [ ] **字体**: fontSize, fontWeight, color
|
|
145
|
-
- [ ] **图标**: size, color
|
|
146
|
-
|
|
147
|
-
### 计算间距的方法
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
元素B的左边距 = 元素B的x坐标 - 元素A的x坐标 - 元素A的宽度
|
|
151
|
-
|
|
152
|
-
示例:
|
|
153
|
-
国旗x=12, width=20
|
|
154
|
-
区号x=40
|
|
155
|
-
间距 = 40 - 12 - 20 = 8px
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
---
|
|
159
|
-
|
|
160
|
-
## 💡 预防措施
|
|
161
|
-
|
|
162
|
-
### 1. 不要依赖自动布局
|
|
163
|
-
|
|
164
|
-
```dart
|
|
165
|
-
// ❌ 避免
|
|
166
|
-
mainAxisAlignment: MainAxisAlignment.spaceBetween
|
|
167
|
-
mainAxisAlignment: MainAxisAlignment.spaceEvenly
|
|
168
|
-
Expanded(flex: 1)
|
|
169
|
-
|
|
170
|
-
// ✅ 推荐
|
|
171
|
-
Container(width: 精确值)
|
|
172
|
-
SizedBox(width: 精确值)
|
|
173
|
-
Positioned(left: 精确值, top: 精确值)
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### 2. 使用 Sketch MCP 工具
|
|
177
|
-
|
|
178
|
-
在 Copilot Chat 中直接查询设计稿:
|
|
179
|
-
|
|
180
|
-
```
|
|
181
|
-
@copilot 从 Sketch 获取"国家代码选择器"的布局坐标
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### 3. 创建布局配置类
|
|
185
|
-
|
|
186
|
-
```dart
|
|
187
|
-
class LoginInputConfig {
|
|
188
|
-
// 国家代码选择器
|
|
189
|
-
static const countryWidth = 98.0;
|
|
190
|
-
static const flagX = 12.0;
|
|
191
|
-
static const codeX = 40.0;
|
|
192
|
-
static const arrowX = 76.0;
|
|
193
|
-
static const dividerX = 98.0;
|
|
194
|
-
|
|
195
|
-
// 输入框
|
|
196
|
-
static const inputHeight = 54.0;
|
|
197
|
-
static const borderRadius = 16.0;
|
|
198
|
-
static const borderWidth = 1.0;
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## 🔗 相关案例
|
|
205
|
-
|
|
206
|
-
- [shadow-透出问题](./shadow-透出问题.md) - 新拟态容器的完整实现
|
|
207
|
-
- [input-字段缺失](./input-字段缺失.md) - 自定义输入组件配置
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
**来源**: my_flutter 项目实战经验
|
|
212
|
-
**创建日期**: 2025-12-31
|
|
213
|
-
**最后验证**: 2026-01-16
|
|
214
|
-
**节省时间**: 4-7 轮对话
|