refactor: migrate to flutter_markdown_plus for enhanced markdown support
- Replaced the gpt_markdown package with flutter_markdown_plus to improve markdown rendering capabilities. - Updated the markdown configuration to utilize the new package, enhancing the overall maintainability and adaptability of markdown features. - Adjusted the streaming markdown widget to integrate with the new markdown body implementation, ensuring a cohesive user experience. - Removed deprecated builders and streamlined the code for better clarity and performance.
This commit is contained in:
@@ -768,6 +768,7 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
|
||||
Widget buildDefault(BuildContext context) => StreamingMarkdownWidget(
|
||||
content: processedContent,
|
||||
isStreaming: widget.isStreaming,
|
||||
onTapLink: (url, _) => _launchUri(url),
|
||||
);
|
||||
|
||||
final responseBuilder = ref.watch(assistantResponseBuilderProvider);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gpt_markdown/gpt_markdown.dart';
|
||||
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
||||
|
||||
import '../../theme/theme_extensions.dart';
|
||||
import 'markdown_config.dart';
|
||||
@@ -26,74 +26,30 @@ class StreamingMarkdownWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
final normalized = ConduitMarkdownPreprocessor.normalize(content);
|
||||
|
||||
const featureFlags = MarkdownFeatureFlags(
|
||||
enableSyntaxHighlighting: true,
|
||||
enableMermaid: true,
|
||||
final markdownTheme = ConduitMarkdownConfig.resolve(context);
|
||||
final markdownBody = MarkdownBody(
|
||||
data: normalized,
|
||||
styleSheet: markdownTheme.styleSheet,
|
||||
selectable: false,
|
||||
imageBuilder: markdownTheme.imageBuilder,
|
||||
onTapLink: (text, href, title) {
|
||||
final target = href ?? '';
|
||||
if (target.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final resolvedTitle = title.isNotEmpty ? title : text;
|
||||
onTapLink?.call(target, resolvedTitle);
|
||||
},
|
||||
);
|
||||
|
||||
final markdownTheme = ConduitMarkdownConfig.resolve(
|
||||
context,
|
||||
flags: featureFlags,
|
||||
);
|
||||
final textScaler = MediaQuery.maybeOf(context)?.textScaler;
|
||||
|
||||
final themedControls = Theme.of(context).copyWith(
|
||||
checkboxTheme: markdownTheme.checkboxTheme,
|
||||
radioTheme: markdownTheme.radioTheme,
|
||||
);
|
||||
|
||||
return GptMarkdownTheme(
|
||||
gptThemeData: markdownTheme.themeData,
|
||||
return SelectionArea(
|
||||
child: Theme(
|
||||
data: themedControls,
|
||||
child: SelectionArea(
|
||||
child: GptMarkdown(
|
||||
normalized,
|
||||
style: markdownTheme.textStyle,
|
||||
followLinkColor: markdownTheme.followLinkColor,
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: textScaler,
|
||||
onLinkTap: onTapLink,
|
||||
codeBuilder: markdownTheme.codeBuilder,
|
||||
imageBuilder: markdownTheme.imageBuilder,
|
||||
orderedListBuilder: markdownTheme.orderedListBuilder,
|
||||
unOrderedListBuilder: markdownTheme.unOrderedListBuilder,
|
||||
tableBuilder: markdownTheme.tableBuilder,
|
||||
useDollarSignsForLatex: true,
|
||||
highlightBuilder: (highlightContext, inline, baseStyle) {
|
||||
final softened = ConduitMarkdownPreprocessor.softenInlineCode(
|
||||
inline,
|
||||
);
|
||||
final theme = highlightContext.conduitTheme;
|
||||
final base = baseStyle;
|
||||
final fontSize = (base.fontSize ?? 13).clamp(11, 15).toDouble();
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: Spacing.xs,
|
||||
vertical: Spacing.xxs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.surfaceBackground.withValues(alpha: 0.55),
|
||||
borderRadius: BorderRadius.circular(AppBorderRadius.xs),
|
||||
border: Border.all(
|
||||
color: theme.cardBorder.withValues(alpha: 0.2),
|
||||
width: BorderWidth.micro,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
softened,
|
||||
style: base.copyWith(
|
||||
fontFamily: AppTypography.monospaceFontFamily,
|
||||
fontSize: fontSize,
|
||||
height: 1.35,
|
||||
color: theme.code?.color ?? theme.textSecondary,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
data: Theme.of(context).copyWith(
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: context.conduitTheme.buttonPrimary,
|
||||
),
|
||||
),
|
||||
child: markdownBody,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
90
pubspec.lock
90
pubspec.lock
@@ -451,14 +451,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_math_fork:
|
||||
dependency: transitive
|
||||
flutter_markdown_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_math_fork
|
||||
sha256: "6d5f2f1aa57ae539ffb0a04bb39d2da67af74601d685a161aff7ce5bda5fa407"
|
||||
name: flutter_markdown_plus
|
||||
sha256: "7f349c075157816da399216a4127096108fd08e1ac931e34e72899281db4113c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
version: "1.0.5"
|
||||
flutter_native_splash:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -539,14 +539,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
flutter_svg:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_svg
|
||||
sha256: b9c2ad5872518a27507ab432d1fb97e8813b05f0fc693f9d40fad06d073e0678
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -605,14 +597,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.8.1"
|
||||
gpt_markdown:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: gpt_markdown
|
||||
sha256: "8174983f2ed7d8576d25810913e3afe3f8ffdaa3172c0c823b7cfc289b67f380"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.4"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -845,6 +829,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
markdown:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: markdown
|
||||
sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.3.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -885,14 +877,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.5.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -941,14 +925,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
path_provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -1037,14 +1013,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.0.3"
|
||||
provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: provider
|
||||
sha256: "4e82183fa20e5ca25703ead7e05de9e4cceed1fbd1eadc1ac3cb6f565a09f272"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.5+1"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1530,14 +1498,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1626,30 +1586,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.1"
|
||||
vector_graphics:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics
|
||||
sha256: a4f059dc26fc8295b5921376600a194c4ec7d55e72f2fe4c7d2831e103d461e6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.19"
|
||||
vector_graphics_codec:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_codec
|
||||
sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.13"
|
||||
vector_graphics_compiler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_compiler
|
||||
sha256: d354a7ec6931e6047785f4db12a1f61ec3d43b207fc0790f863818543f8ff0dc
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.19"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -30,7 +30,7 @@ dependencies:
|
||||
shared_preferences: ^2.3.2
|
||||
|
||||
# UI Components - GPT Markdown
|
||||
gpt_markdown: ^1.1.4
|
||||
flutter_markdown_plus: ^1.0.3
|
||||
cached_network_image: ^3.3.1
|
||||
flutter_highlight: ^0.7.0
|
||||
webview_flutter: ^4.7.0
|
||||
|
||||
Reference in New Issue
Block a user