Skip to content

Commit 7879ff1

Browse files
committed
refactor: simplify widget structure and formatting in plugin views
1 parent c5494e1 commit 7879ff1

7 files changed

+235
-438
lines changed

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_head_view.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ class WoxSettingPluginHead extends WoxSettingPluginItem {
2222
children: [
2323
Row(
2424
children: [
25-
Text(
26-
item.content,
27-
style: TextStyle(
28-
fontSize: 16,
29-
color: getThemeTextColor(),
30-
),
31-
),
25+
Text(item.content, style: TextStyle(fontSize: 16, color: getThemeTextColor())),
3226
if (item.tooltip != "") WoxTooltipIconView(tooltip: item.tooltip, color: getThemeTextColor()),
3327
],
3428
),

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_item_view.dart

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,13 @@ abstract class WoxSettingPluginItem extends StatelessWidget {
2323
}
2424

2525
Widget withFlexible(List<Widget> children) {
26-
return Wrap(
27-
crossAxisAlignment: WrapCrossAlignment.center,
28-
children: children,
29-
);
26+
return Wrap(crossAxisAlignment: WrapCrossAlignment.center, children: children);
3027
}
3128

3229
Widget layout({required List<Widget> children, required PluginSettingValueStyle style}) {
3330
if (style.hasAnyPadding()) {
3431
return Padding(
35-
padding: EdgeInsets.only(
36-
top: style.paddingTop,
37-
bottom: style.paddingBottom,
38-
left: style.paddingLeft,
39-
right: style.paddingRight,
40-
),
32+
padding: EdgeInsets.only(top: style.paddingTop, bottom: style.paddingBottom, left: style.paddingLeft, right: style.paddingRight),
4133
child: withFlexible(children),
4234
);
4335
}
@@ -56,10 +48,7 @@ abstract class WoxSettingPluginItem extends StatelessWidget {
5648
),
5749
);
5850
} else {
59-
return Padding(
60-
padding: const EdgeInsets.only(right: 4),
61-
child: Text(text, style: TextStyle(color: getThemeTextColor(), fontSize: 13)),
62-
);
51+
return Padding(padding: const EdgeInsets.only(right: 4), child: Text(text, style: TextStyle(color: getThemeTextColor(), fontSize: 13)));
6352
}
6453
}
6554

@@ -68,10 +57,7 @@ abstract class WoxSettingPluginItem extends StatelessWidget {
6857

6958
Widget suffix(String text) {
7059
if (text != "") {
71-
return Padding(
72-
padding: const EdgeInsets.only(left: 4),
73-
child: Text(text, style: TextStyle(color: getThemeTextColor(), fontSize: 13)),
74-
);
60+
return Padding(padding: const EdgeInsets.only(left: 4), child: Text(text, style: TextStyle(color: getThemeTextColor(), fontSize: 13)));
7561
}
7662

7763
return const SizedBox.shrink();

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_label_view.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ class WoxSettingPluginLabel extends WoxSettingPluginItem {
1212

1313
@override
1414
Widget build(BuildContext context) {
15-
return layout(children: [
16-
Text(item.content, style: TextStyle(color: getThemeTextColor(), fontSize: 13)),
17-
if (item.tooltip != "")
18-
WoxTooltipIconView(
19-
tooltip: item.tooltip,
20-
color: getThemeTextColor(),
21-
),
22-
], style: item.style);
15+
return layout(
16+
children: [
17+
Text(item.content, style: TextStyle(color: getThemeTextColor(), fontSize: 13)),
18+
if (item.tooltip != "") WoxTooltipIconView(tooltip: item.tooltip, color: getThemeTextColor()),
19+
],
20+
style: item.style,
21+
);
2322
}
2423
}

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_newline_view.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ class WoxSettingPluginNewLine extends WoxSettingPluginItem {
1212
Widget build(BuildContext context) {
1313
return layout(
1414
children: [
15-
const Padding(
16-
padding: EdgeInsets.all(4),
17-
child: Row(
18-
children: [
19-
SizedBox(
20-
width: 1,
21-
),
22-
],
23-
),
24-
),
15+
const Padding(padding: EdgeInsets.all(4), child: Row(children: [SizedBox(width: 1)])),
2516
],
2617
style: item.style,
2718
);

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_select_view.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ class WoxSettingPluginSelect extends WoxSettingPluginItem {
2020
WoxDropdownButton<String>(
2121
value: getSetting(item.key),
2222
isExpanded: true,
23-
items: item.options.map((e) {
24-
return WoxDropdownItem(
25-
value: e.value,
26-
label: e.label,
27-
);
28-
}).toList(),
23+
width: item.style.width > 0 ? item.style.width.toDouble() : null,
24+
items:
25+
item.options.map((e) {
26+
return WoxDropdownItem(value: e.value, label: e.label);
27+
}).toList(),
2928
onChanged: (v) {
3029
updateConfig(item.key, v ?? "");
3130
},

wox.ui.flutter/wox/lib/components/plugin/wox_setting_plugin_table_update_view.dart

Lines changed: 39 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ class WoxSettingPluginTableUpdate extends StatefulWidget {
3030
final Function onUpdate;
3131
final Future<String?> Function(Map<String, dynamic> rowValues)? onUpdateValidate;
3232

33-
const WoxSettingPluginTableUpdate({
34-
super.key,
35-
required this.item,
36-
required this.row,
37-
required this.onUpdate,
38-
this.onUpdateValidate,
39-
});
33+
const WoxSettingPluginTableUpdate({super.key, required this.item, required this.row, required this.onUpdate, this.onUpdateValidate});
4034

4135
@override
4236
State<WoxSettingPluginTableUpdate> createState() => _WoxSettingPluginTableUpdateState();
@@ -178,19 +172,12 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
178172
Container(
179173
width: 80,
180174
height: 80,
181-
decoration: BoxDecoration(
182-
border: Border.all(color: getThemeSubTextColor().withAlpha(76)),
183-
borderRadius: BorderRadius.circular(8),
184-
),
175+
decoration: BoxDecoration(border: Border.all(color: getThemeSubTextColor().withAlpha(76)), borderRadius: BorderRadius.circular(8)),
185176
child: ClipRRect(
186177
borderRadius: BorderRadius.circular(8),
187178
child: Center(
188179
// Center the preview content (especially emoji) in the 80x80 box
189-
child: WoxImageView(
190-
woxImage: currentImage,
191-
width: 80,
192-
height: 80,
193-
),
180+
child: WoxImageView(woxImage: currentImage, width: 80, height: 80),
194181
),
195182
),
196183
),
@@ -206,10 +193,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
206193
onPressed: () async {
207194
final emojiResult = await _showEmojiPicker(context);
208195
if (emojiResult != null && emojiResult.isNotEmpty) {
209-
final newImage = WoxImage(
210-
imageType: WoxImageTypeEnum.WOX_IMAGE_TYPE_EMOJI.code,
211-
imageData: emojiResult,
212-
);
196+
final newImage = WoxImage(imageType: WoxImageTypeEnum.WOX_IMAGE_TYPE_EMOJI.code, imageData: emojiResult);
213197
updateValue(column.key, newImage);
214198
setState(() {});
215199
}
@@ -220,10 +204,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
220204
icon: Icon(Icons.file_upload_outlined, size: 14, color: getThemeTextColor()),
221205
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
222206
onPressed: () async {
223-
final result = await FilePicker.platform.pickFiles(
224-
type: FileType.image,
225-
allowMultiple: false,
226-
);
207+
final result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: false);
227208

228209
if (result != null && result.files.isNotEmpty && result.files.first.path != null) {
229210
final filePath = result.files.first.path!;
@@ -232,10 +213,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
232213
final bytes = await file.readAsBytes();
233214
final base64Image = base64Encode(bytes);
234215

235-
final newImage = WoxImage(
236-
imageType: WoxImageTypeEnum.WOX_IMAGE_TYPE_BASE64.code,
237-
imageData: "data:image/png;base64,$base64Image",
238-
);
216+
final newImage = WoxImage(imageType: WoxImageTypeEnum.WOX_IMAGE_TYPE_BASE64.code, imageData: "data:image/png;base64,$base64Image");
239217

240218
updateValue(column.key, newImage);
241219
setState(() {});
@@ -263,23 +241,15 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
263241
width: 300,
264242
height: 200,
265243
child: GridView.builder(
266-
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
267-
crossAxisCount: 5,
268-
childAspectRatio: 1,
269-
),
244+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5, childAspectRatio: 1),
270245
itemCount: commonEmojis.length,
271246
itemBuilder: (context, index) {
272247
return InkWell(
273248
onTap: () {
274249
selectedEmoji = commonEmojis[index];
275250
Navigator.pop(context);
276251
},
277-
child: Center(
278-
child: Text(
279-
commonEmojis[index],
280-
style: const TextStyle(fontSize: 24),
281-
),
282-
),
252+
child: Center(child: Text(commonEmojis[index], style: const TextStyle(fontSize: 24))),
283253
);
284254
},
285255
),
@@ -446,32 +416,29 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
446416
);
447417
case PluginSettingValueType.pluginSettingValueTableColumnTypeSelect:
448418
return Expanded(
449-
child: Builder(builder: (context) {
450-
final currentValue = getValue(column.key);
451-
// Ensure the current value exists in selectOptions, otherwise use first option or null
452-
final valueExists = column.selectOptions.any((e) => e.value == currentValue);
453-
final effectiveValue = valueExists ? currentValue : (column.selectOptions.isNotEmpty ? column.selectOptions.first.value : null);
454-
455-
return WoxDropdownButton<String>(
456-
value: effectiveValue,
457-
isExpanded: true,
458-
fontSize: 13,
459-
underline: Container(
460-
height: 1,
461-
color: getThemeDividerColor().withOpacity(0.6),
462-
),
463-
onChanged: (value) {
464-
updateValue(column.key, value);
465-
setState(() {});
466-
},
467-
items: column.selectOptions.map((e) {
468-
return WoxDropdownItem(
469-
value: e.value,
470-
label: e.label,
471-
);
472-
}).toList(),
473-
);
474-
}),
419+
child: Builder(
420+
builder: (context) {
421+
final currentValue = getValue(column.key);
422+
// Ensure the current value exists in selectOptions, otherwise use first option or null
423+
final valueExists = column.selectOptions.any((e) => e.value == currentValue);
424+
final effectiveValue = valueExists ? currentValue : (column.selectOptions.isNotEmpty ? column.selectOptions.first.value : null);
425+
426+
return WoxDropdownButton<String>(
427+
value: effectiveValue,
428+
isExpanded: true,
429+
fontSize: 13,
430+
underline: Container(height: 1, color: getThemeDividerColor().withOpacity(0.6)),
431+
onChanged: (value) {
432+
updateValue(column.key, value);
433+
setState(() {});
434+
},
435+
items:
436+
column.selectOptions.map((e) {
437+
return WoxDropdownItem(value: e.value, label: e.label);
438+
}).toList(),
439+
);
440+
},
441+
),
475442
);
476443
case PluginSettingValueType.pluginSettingValueTableColumnTypeSelectAIModel:
477444
return Expanded(
@@ -539,9 +506,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
539506
),
540507
);
541508
case PluginSettingValueType.pluginSettingValueTableColumnTypeWoxImage:
542-
return Expanded(
543-
child: _buildWoxImageEditor(column),
544-
);
509+
return Expanded(child: _buildWoxImageEditor(column));
545510
case PluginSettingValueType.pluginSettingValueTableColumnTypeTextList:
546511
var columnValues = getValue(column.key);
547512
return Expanded(
@@ -574,10 +539,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
574539
child: WoxTextField(
575540
controller: textboxEditingController[column.key + i.toString()],
576541
maxLines: 1,
577-
style: TextStyle(
578-
overflow: TextOverflow.ellipsis,
579-
color: getThemeTextColor(),
580-
),
542+
style: TextStyle(overflow: TextOverflow.ellipsis, color: getThemeTextColor()),
581543
onChanged: (value) {
582544
columnValues[i] = value;
583545

@@ -666,10 +628,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
666628
return MaterialApp(
667629
debugShowCheckedModeBanner: false,
668630
theme: ThemeData(
669-
colorScheme: ColorScheme.fromSeed(
670-
seedColor: accentColor,
671-
brightness: isDarkTheme ? Brightness.dark : Brightness.light,
672-
),
631+
colorScheme: ColorScheme.fromSeed(seedColor: accentColor, brightness: isDarkTheme ? Brightness.dark : Brightness.light),
673632
scaffoldBackgroundColor: Colors.transparent,
674633
cardColor: cardColor,
675634
shadowColor: textColor.withAlpha(50),
@@ -686,10 +645,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
686645
child: AlertDialog(
687646
backgroundColor: cardColor,
688647
surfaceTintColor: Colors.transparent,
689-
shape: RoundedRectangleBorder(
690-
borderRadius: BorderRadius.circular(20),
691-
side: BorderSide(color: outlineColor),
692-
),
648+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20), side: BorderSide(color: outlineColor)),
693649
elevation: 18,
694650
insetPadding: const EdgeInsets.symmetric(horizontal: 32, vertical: 28),
695651
contentPadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
@@ -715,14 +671,7 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
715671
children: [
716672
SizedBox(
717673
width: maxLabelWidth,
718-
child: Text(
719-
tr(column.label),
720-
style: TextStyle(
721-
color: textColor.withOpacity(0.92),
722-
fontSize: 14,
723-
fontWeight: FontWeight.w600,
724-
),
725-
),
674+
child: Text(tr(column.label), style: TextStyle(color: textColor.withOpacity(0.92), fontSize: 14, fontWeight: FontWeight.w600)),
726675
),
727676
const SizedBox(width: 10),
728677
buildColumn(column),
@@ -731,41 +680,22 @@ class _WoxSettingPluginTableUpdateState extends State<WoxSettingPluginTableUpdat
731680
if (column.tooltip != "")
732681
Padding(
733682
padding: EdgeInsets.only(top: 4, left: maxLabelWidth + 10),
734-
child: Text(
735-
tr(column.tooltip),
736-
style: TextStyle(
737-
color: textColor.withOpacity(0.6),
738-
fontSize: 12,
739-
),
740-
),
683+
child: Text(tr(column.tooltip), style: TextStyle(color: textColor.withOpacity(0.6), fontSize: 12)),
741684
),
742685
],
743686
),
744687
),
745688
if (customValidationError != null)
746689
Padding(
747690
padding: const EdgeInsets.only(top: 10),
748-
child: Row(
749-
children: [
750-
Expanded(
751-
child: Text(
752-
customValidationError!,
753-
style: const TextStyle(color: Colors.red),
754-
),
755-
),
756-
],
757-
),
691+
child: Row(children: [Expanded(child: Text(customValidationError!, style: const TextStyle(color: Colors.red)))]),
758692
),
759693
],
760694
),
761695
),
762696
),
763697
actions: [
764-
WoxButton.secondary(
765-
text: tr("ui_cancel"),
766-
padding: const EdgeInsets.symmetric(horizontal: 22, vertical: 12),
767-
onPressed: () => Navigator.pop(context),
768-
),
698+
WoxButton.secondary(text: tr("ui_cancel"), padding: const EdgeInsets.symmetric(horizontal: 22, vertical: 12), onPressed: () => Navigator.pop(context)),
769699
const SizedBox(width: 12),
770700
WoxButton.primary(
771701
text: tr("ui_save"),

0 commit comments

Comments
 (0)