refactor: ImmichHtmlText to ImmichFormattedText (#26466)

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
shenlong
2026-02-24 02:35:00 +05:30
committed by GitHub
parent e5722c525b
commit db7158b967
17 changed files with 266 additions and 402 deletions

View File

@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';
import 'package:immich_ui/immich_ui.dart';
class FormattedTextBoldText extends StatelessWidget {
const FormattedTextBoldText({super.key});
@override
Widget build(BuildContext context) {
return ImmichFormattedText('This is <b>bold text</b>.');
}
}

View File

@@ -1,25 +1,24 @@
import 'package:flutter/material.dart';
import 'package:immich_ui/immich_ui.dart';
class HtmlTextLinks extends StatelessWidget {
const HtmlTextLinks({super.key});
class FormattedTextLinks extends StatelessWidget {
const FormattedTextLinks({super.key});
@override
Widget build(BuildContext context) {
return ImmichHtmlText(
return ImmichFormattedText(
'Read the <docs-link>documentation</docs-link> or visit <github-link>GitHub</github-link>.',
linkHandlers: {
'docs-link': () {
ScaffoldMessenger.of(
spanBuilder: (tag) => FormattedSpan(
onTap: switch (tag) {
'docs-link' => () => ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Docs link clicked!')));
},
'github-link': () {
ScaffoldMessenger.of(
).showSnackBar(const SnackBar(content: Text('Docs link clicked!'))),
'github-link' => () => ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('GitHub link clicked!')));
).showSnackBar(const SnackBar(content: Text('GitHub link clicked!'))),
_ => null,
},
},
),
);
}
}

View File

@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:immich_ui/immich_ui.dart';
class FormattedTextMixedContent extends StatelessWidget {
const FormattedTextMixedContent({super.key});
@override
Widget build(BuildContext context) {
return ImmichFormattedText(
'You can use <b>bold text</b> and <link>links</link> together.',
spanBuilder: (tag) => switch (tag) {
'b' => const FormattedSpan(
style: TextStyle(fontWeight: FontWeight.bold),
),
_ => FormattedSpan(
onTap: () => ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Link clicked!'))),
),
},
);
}
}

View File

@@ -1,13 +0,0 @@
import 'package:flutter/material.dart';
import 'package:immich_ui/immich_ui.dart';
class HtmlTextBoldText extends StatelessWidget {
const HtmlTextBoldText({super.key});
@override
Widget build(BuildContext context) {
return ImmichHtmlText(
'This is <b>bold text</b> and <strong>strong text</strong>.',
);
}
}

View File

@@ -1,20 +0,0 @@
import 'package:flutter/material.dart';
import 'package:immich_ui/immich_ui.dart';
class HtmlTextNestedTags extends StatelessWidget {
const HtmlTextNestedTags({super.key});
@override
Widget build(BuildContext context) {
return ImmichHtmlText(
'You can <b>combine <link>bold and links</link></b> together.',
linkHandlers: {
'link': () {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Nested link clicked!')));
},
},
);
}
}

View File

@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:showcase/pages/components/examples/formatted_text_bold_text.dart';
import 'package:showcase/pages/components/examples/formatted_text_links.dart';
import 'package:showcase/pages/components/examples/formatted_text_mixed_tags.dart';
import 'package:showcase/routes.dart';
import 'package:showcase/widgets/component_examples.dart';
import 'package:showcase/widgets/example_card.dart';
import 'package:showcase/widgets/page_title.dart';
class FormattedTextPage extends StatelessWidget {
const FormattedTextPage({super.key});
@override
Widget build(BuildContext context) {
return PageTitle(
title: AppRoute.formattedText.name,
child: ComponentExamples(
title: 'ImmichFormattedText',
subtitle: 'Render text with HTML formatting (bold, links).',
examples: [
ExampleCard(
title: 'Bold Text',
preview: const FormattedTextBoldText(),
code: 'formatted_text_bold_text.dart',
),
ExampleCard(
title: 'Links',
preview: const FormattedTextLinks(),
code: 'formatted_text_links.dart',
),
ExampleCard(
title: 'Mixed Content',
preview: const FormattedTextMixedContent(),
code: 'formatted_text_mixed_tags.dart',
),
],
),
);
}
}

View File

@@ -1,40 +0,0 @@
import 'package:flutter/material.dart';
import 'package:showcase/pages/components/examples/html_text_bold_text.dart';
import 'package:showcase/pages/components/examples/html_text_links.dart';
import 'package:showcase/pages/components/examples/html_text_nested_tags.dart';
import 'package:showcase/routes.dart';
import 'package:showcase/widgets/component_examples.dart';
import 'package:showcase/widgets/example_card.dart';
import 'package:showcase/widgets/page_title.dart';
class HtmlTextPage extends StatelessWidget {
const HtmlTextPage({super.key});
@override
Widget build(BuildContext context) {
return PageTitle(
title: AppRoute.htmlText.name,
child: ComponentExamples(
title: 'ImmichHtmlText',
subtitle: 'Render text with HTML formatting (bold, links).',
examples: [
ExampleCard(
title: 'Bold Text',
preview: const HtmlTextBoldText(),
code: 'html_text_bold_text.dart',
),
ExampleCard(
title: 'Links',
preview: const HtmlTextLinks(),
code: 'html_text_links.dart',
),
ExampleCard(
title: 'Nested Tags',
preview: const HtmlTextNestedTags(),
code: 'html_text_nested_tags.dart',
),
],
),
);
}
}