From d3b64716b9c62dcba0eb0f84e275446938484b47 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Tue, 30 Sep 2025 19:53:19 +0530 Subject: [PATCH] chore: update markdown dependency and configuration - Replaced `gpt_markdown` with `flutter_markdown_plus` in `pubspec.yaml`. - Updated `pubspec.lock` to reflect the new dependency version. - Modified `markdown_config.dart` to generalize styling configuration. - Updated `streaming_markdown_widget.dart` to utilize `MarkdownBody` for rendering markdown content. --- .../widgets/markdown/markdown_config.dart | 2 +- .../markdown/streaming_markdown_widget.dart | 38 +++++++- pubspec.lock | 90 +++---------------- pubspec.yaml | 2 +- 4 files changed, 50 insertions(+), 82 deletions(-) diff --git a/lib/shared/widgets/markdown/markdown_config.dart b/lib/shared/widgets/markdown/markdown_config.dart index aa9125a..32385b1 100644 --- a/lib/shared/widgets/markdown/markdown_config.dart +++ b/lib/shared/widgets/markdown/markdown_config.dart @@ -4,7 +4,7 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:conduit/shared/theme/theme_extensions.dart'; import 'package:conduit/l10n/app_localizations.dart'; -/// Configuration for GptMarkdown styling +/// Configuration for markdown styling class ConduitMarkdownStyleConfig { final TextStyle textStyle; diff --git a/lib/shared/widgets/markdown/streaming_markdown_widget.dart b/lib/shared/widgets/markdown/streaming_markdown_widget.dart index 3f8d37d..98155dc 100644 --- a/lib/shared/widgets/markdown/streaming_markdown_widget.dart +++ b/lib/shared/widgets/markdown/streaming_markdown_widget.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:gpt_markdown/gpt_markdown.dart'; +import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; +import 'package:conduit/shared/theme/theme_extensions.dart'; import 'package:conduit/shared/widgets/markdown/markdown_config.dart'; class StreamingMarkdownWidget extends StatefulWidget { @@ -107,13 +108,44 @@ class _StreamingMarkdownWidgetState extends State { @override Widget build(BuildContext context) { final config = ConduitMarkdownConfig.getStyleConfig(context: context); + final theme = Theme.of(context); + final styleSheet = MarkdownStyleSheet.fromTheme( + theme, + ).copyWith(p: config.textStyle); + final conduitTheme = context.conduitTheme; if (_renderedContent.isEmpty) { return const SizedBox.shrink(); } - // GptMarkdown handles both streaming and static content elegantly - return GptMarkdown(_renderedContent, style: config.textStyle); + // MarkdownBody handles both streaming and static content elegantly + return MarkdownBody( + data: _renderedContent, + styleSheet: styleSheet, + softLineBreak: true, + selectable: true, + imageBuilder: (uri, title, alt) { + final scheme = uri.scheme; + + if (scheme == 'data') { + return ConduitMarkdownConfig.buildBase64Image( + uri.toString(), + context, + conduitTheme, + ); + } + + if (scheme.isEmpty || scheme == 'http' || scheme == 'https') { + return ConduitMarkdownConfig.buildNetworkImage( + uri.toString(), + context, + conduitTheme, + ); + } + + return const SizedBox.shrink(); + }, + ); } @override diff --git a/pubspec.lock b/pubspec.lock index a134d2b..8ae2ed5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -443,14 +443,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: @@ -531,14 +531,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 @@ -597,14 +589,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: @@ -805,6 +789,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: @@ -845,14 +837,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: @@ -901,14 +885,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: @@ -997,14 +973,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: @@ -1490,14 +1458,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: @@ -1586,30 +1546,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: diff --git a/pubspec.yaml b/pubspec.yaml index 530edb3..25b755f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,7 +28,7 @@ dependencies: shared_preferences: ^2.3.2 # UI Components - Enhanced Markdown - gpt_markdown: ^1.1.4 + flutter_markdown_plus: ^1.0.5 cached_network_image: ^3.3.1 socket_io_client: ^3.1.2 yaml: ^3.1.2