Skip to content

Commit 234663f

Browse files
committed
优化代码
1 parent 1ab6ae0 commit 234663f

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'package:app_config/app_config.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:widget_repository/widget_repository.dart';
4+
5+
class LinkWidgetButtons extends StatelessWidget {
6+
final List<WidgetModel> links;
7+
final ValueChanged<WidgetModel> onSelect;
8+
9+
const LinkWidgetButtons(
10+
{Key? key, required this.links, required this.onSelect})
11+
: super(key: key);
12+
13+
@override
14+
Widget build(BuildContext context) {
15+
Color chipColor = Theme.of(context).primaryColor;
16+
17+
if (links.isEmpty) {
18+
return Padding(
19+
padding: const EdgeInsets.only(left: 10),
20+
child: Chip(
21+
backgroundColor: Colors.grey.withAlpha(120),
22+
labelStyle: const TextStyle(fontSize: 12, color: Colors.white),
23+
label: const Text('暂无链接组件'),
24+
));
25+
}
26+
27+
return Padding(
28+
padding: const EdgeInsets.only(left: 10.0, top: 10),
29+
child: Wrap(
30+
spacing: 5,
31+
runSpacing: 5,
32+
children: links
33+
.map((WidgetModel model) => ActionChip(
34+
labelPadding: EdgeInsets.zero,
35+
side: BorderSide.none,
36+
onPressed: () => onSelect(model),
37+
elevation: 1,
38+
// shadowColor: chipColor,
39+
backgroundColor: chipColor,
40+
labelStyle: model.deprecated
41+
? UnitTextStyle.deprecatedChip
42+
: UnitTextStyle.commonChip,
43+
label: Text(model.name),
44+
))
45+
.toList(),
46+
),
47+
);
48+
}
49+
}

lib/widget_system/views/widget_detail_page/desk_ui/widget_detail_page.dart

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:widget_repository/widget_repository.dart';
1111

1212
import '../../../widgets/widgets_map.dart';
1313
import '../category_end_drawer.dart';
14+
import 'link_widget_buttons.dart';
1415
import 'widget_detail_bar.dart';
1516
import 'widget_detail_panel.dart';
1617
import 'widget_node_panel.dart';
@@ -103,13 +104,15 @@ class _DeskWidgetDetailPageState extends State<DeskWidgetDetailPage> {
103104
children: [
104105
linkText,
105106
if (state is DetailWithData)
106-
_buildLinkTo(context, state.links),
107-
// const Divider(),
107+
LinkWidgetButtons(
108+
links: state.links,
109+
onSelect: _toLinkWidget,
110+
)
108111
],
109112
))
110113
],
111114
),
112-
Divider()
115+
const Divider()
113116
],
114117
),
115118
),
@@ -134,44 +137,6 @@ class _DeskWidgetDetailPageState extends State<DeskWidgetDetailPage> {
134137
}
135138
}
136139

137-
Color? get chipColor => isDark
138-
? Theme.of(context).floatingActionButtonTheme.backgroundColor
139-
: Theme.of(context).primaryColor;
140-
141-
Widget _buildLinkTo(BuildContext context, List<WidgetModel> links) {
142-
if (links.isEmpty) {
143-
return Padding(
144-
padding: const EdgeInsets.only(left: 10),
145-
child: Chip(
146-
backgroundColor: Colors.grey.withAlpha(120),
147-
labelStyle: const TextStyle(fontSize: 12, color: Colors.white),
148-
label: const Text('暂无链接组件'),
149-
));
150-
} else {
151-
return Padding(
152-
padding: const EdgeInsets.only(left: 10.0, top: 10),
153-
child: Wrap(
154-
spacing: 5,
155-
runSpacing: 5,
156-
children: links
157-
.map((WidgetModel model) => ActionChip(
158-
labelPadding: EdgeInsets.zero,
159-
side: BorderSide.none,
160-
onPressed: () => _toLinkWidget(model),
161-
elevation: 1,
162-
// shadowColor: chipColor,
163-
backgroundColor: chipColor,
164-
labelStyle: model.deprecated
165-
? UnitTextStyle.deprecatedChip
166-
: UnitTextStyle.commonChip,
167-
label: Text(model.name),
168-
))
169-
.toList(),
170-
),
171-
);
172-
}
173-
}
174-
175140
void _toLinkWidget(WidgetModel model) {
176141
BlocProvider.of<WidgetDetailBloc>(context).add(FetchWidgetDetail(model));
177142
_modelStack.add(model);

0 commit comments

Comments
 (0)