chore: remove iconContent from IconsData (#7199)

This commit is contained in:
Morn 2025-01-14 09:31:43 +08:00 committed by GitHub
parent 9a237b5f18
commit 2b1d1ba2f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 30 additions and 26 deletions

View File

@ -45,7 +45,7 @@ void main() {
);
final icons = find.byWidgetPredicate(
(w) => w is FlowySvg && w.svgString == firstIcon.iconContent,
(w) => w is FlowySvg && w.svgString == firstIcon.svgString,
);
expect(icons, findsOneWidget);
await tester.tapIcon(EmojiIconData.icon(firstIcon));
@ -54,7 +54,7 @@ void main() {
final spaceIcon = find.descendant(
of: spaceHeader,
matching: find.byWidgetPredicate(
(w) => w is FlowySvg && w.svgString == firstIcon.iconContent,
(w) => w is FlowySvg && w.svgString == firstIcon.svgString,
),
);
expect(spaceIcon, findsOneWidget);

View File

@ -103,8 +103,8 @@ void main() {
final iconData = IconsData.fromJson(jsonDecode(emojiIconData.emoji));
/// icon displayed correctly
expect(firstSvg.svgString, iconData.iconContent);
expect(lastSvg.svgString, iconData.iconContent);
expect(firstSvg.svgString, iconData.svgString);
expect(lastSvg.svgString, iconData.svgString);
testWidgets('select the content in document and search', (tester) async {
const firstDocument = ''; // empty document

View File

@ -59,8 +59,8 @@ void main() {
.evaluate()
.first
.widget as IconWidget;
final iconWidgetData = iconWidget.data;
expect(iconWidgetData.iconContent, iconData.iconContent);
final iconWidgetData = iconWidget.iconsData;
expect(iconWidgetData.svgString, iconData.svgString);
expect(iconWidgetData.iconName, iconData.iconName);
expect(iconWidgetData.groupName, iconData.groupName);
});

View File

@ -928,7 +928,6 @@ extension CommonOperations on WidgetTester {
return EmojiIconData.icon(
IconsData(
firstGroup.name,
firstIcon.content,
firstIcon.name,
builtInSpaceColors.first,
),

View File

@ -35,7 +35,7 @@ extension EmojiTestExtension on WidgetTester {
final selectedSvg = find.descendant(
of: find.byType(FlowyIconPicker),
matching: find.byWidgetPredicate(
(w) => w is FlowySvg && w.svgString == iconsData.iconContent,
(w) => w is FlowySvg && w.svgString == iconsData.svgString,
),
);

View File

@ -245,7 +245,7 @@ extension Expectation on WidgetTester {
final icon = find.descendant(
of: pageName,
matching: find.byWidgetPredicate(
(w) => w is FlowySvg && w.svgString == iconsData.iconContent,
(w) => w is FlowySvg && w.svgString == iconsData.svgString,
),
);
expect(icon, findsOneWidget);
@ -269,7 +269,7 @@ extension Expectation on WidgetTester {
final icon = find.descendant(
of: find.byType(ViewTitleBar),
matching: find.byWidgetPredicate(
(w) => w is FlowySvg && w.svgString == iconsData.iconContent,
(w) => w is FlowySvg && w.svgString == iconsData.svgString,
),
);
expect(icon, findsOneWidget);

View File

@ -1,27 +1,32 @@
import 'package:appflowy/plugins/base/emoji/emoji_text.dart';
import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';
import 'package:flutter/material.dart';
import '../../../generated/flowy_svgs.g.dart';
class IconWidget extends StatelessWidget {
const IconWidget({
super.key,
required this.size,
required this.data,
});
const IconWidget({super.key, required this.size, required this.iconsData});
final IconsData data;
final IconsData iconsData;
final double size;
@override
Widget build(BuildContext context) {
final colorValue = int.tryParse(data.color ?? '');
final colorValue = int.tryParse(iconsData.color ?? '');
Color? color;
if (colorValue != null) {
color = Color(colorValue);
}
final svgString = iconsData.svgString;
if (svgString == null) {
return EmojiText(
emoji: '',
fontSize: size,
textAlign: TextAlign.center,
);
}
return FlowySvg.string(
data.iconContent,
svgString,
size: Size.square(size),
color: color,
);

View File

@ -92,7 +92,7 @@ class RawEmojiIconWidget extends StatelessWidget {
/// size of the icons
final iconSize = Platform.isMacOS ? emojiSize * 0.9 : emojiSize;
return IconWidget(
data: iconData,
iconsData: iconData,
size: iconSize,
);
default:

View File

@ -173,7 +173,6 @@ class _FlowyIconPickerState extends State<FlowyIconPicker> {
widget.onSelectedIcon(
IconsData(
value.$1.name,
value.$2.content,
value.$2.name,
color,
).toResult(isRandom: true),
@ -232,16 +231,14 @@ class _FlowyIconPickerState extends State<FlowyIconPicker> {
}
class IconsData {
IconsData(this.groupName, this.iconContent, this.iconName, this.color);
IconsData(this.groupName, this.iconName, this.color);
final String groupName;
final String iconContent;
final String iconName;
final String? color;
String get iconString => jsonEncode({
'groupName': groupName,
'iconContent': iconContent,
'iconName': iconName,
if (color != null) 'color': color,
});
@ -251,11 +248,16 @@ class IconsData {
static IconsData fromJson(dynamic json) {
return IconsData(
json['groupName'],
json['iconContent'],
json['iconName'],
json['color'],
);
}
String? get svgString => kIconGroups
?.firstWhereOrNull((group) => group.name == groupName)
?.icons
.firstWhereOrNull((icon) => icon.name == iconName)
?.content;
}
class IconPicker extends StatefulWidget {
@ -317,7 +319,6 @@ class _IconPickerState extends State<IconPicker> {
widget.onSelectedIcon(
IconsData(
groupName,
icon.content,
icon.name,
color,
),
@ -336,7 +337,6 @@ class _IconPickerState extends State<IconPicker> {
widget.onSelectedIcon(
IconsData(
groupName,
icon.content,
icon.name,
null,
),