@@ -50,6 +50,33 @@ class _TableElement {
5050 final List <TableRow > rows = < TableRow > [];
5151}
5252
53+ /// Holds configuration data for an image in a Markdown document.
54+ class MarkdownImageConfig {
55+ /// Creates a new [MarkdownImageConfig] instance.
56+ MarkdownImageConfig ({
57+ required this .uri,
58+ this .title,
59+ this .alt,
60+ this .width,
61+ this .height,
62+ });
63+
64+ /// The URI of the image.
65+ final Uri uri;
66+
67+ /// The title of the image, displayed on hover.
68+ final String ? title;
69+
70+ /// The alternative text for the image, displayed if the image cannot be loaded.
71+ final String ? alt;
72+
73+ /// The desired width of the image.
74+ final double ? width;
75+
76+ /// The desired height of the image.
77+ final double ? height;
78+ }
79+
5380/// A collection of widgets that should be placed adjacent to (inline with)
5481/// other inline elements in the same parent block.
5582///
@@ -105,7 +132,8 @@ class MarkdownBuilder implements md.NodeVisitor {
105132 required this .selectable,
106133 required this .styleSheet,
107134 required this .imageDirectory,
108- required this .imageBuilder,
135+ @Deprecated ('Use sizedImageBuilder instead' ) this .imageBuilder,
136+ required this .sizedImageBuilder,
109137 required this .checkboxBuilder,
110138 required this .bulletBuilder,
111139 required this .builders,
@@ -115,7 +143,8 @@ class MarkdownBuilder implements md.NodeVisitor {
115143 this .onSelectionChanged,
116144 this .onTapText,
117145 this .softLineBreak = false ,
118- });
146+ }) : assert (imageBuilder == null || sizedImageBuilder == null ,
147+ 'Only one of imageBuilder or sizedImageBuilder may be specified.' );
119148
120149 /// A delegate that controls how link and `pre` elements behave.
121150 final MarkdownBuilderDelegate delegate;
@@ -131,9 +160,41 @@ class MarkdownBuilder implements md.NodeVisitor {
131160 /// The base directory holding images referenced by Img tags with local or network file paths.
132161 final String ? imageDirectory;
133162
134- /// Call when build an image widget.
163+ /// {@template flutter_markdown.builder.MarkdownBuilder.imageBuilder}
164+ /// Called to build an image widget.
165+ ///
166+ /// This builder allows for custom rendering of images within the Markdown content.
167+ /// It provides the image `Uri` , `title` , and `alt` text.
168+ ///
169+ /// **Deprecated:** Use [sizedImageBuilder] instead, which offers more comprehensive
170+ /// image information.
171+ ///
172+ /// Only one of [imageBuilder] or [sizedImageBuilder] may be specified.
173+ ///
174+ /// {@endtemplate}
175+ @Deprecated ('Use sizedImageBuilder instead' )
135176 final MarkdownImageBuilder ? imageBuilder;
136177
178+ /// {@template flutter_markdown.builder.MarkdownBuilder.sizedImageBuilder}
179+ /// Called to build an image widget with size information.
180+ ///
181+ /// This builder allows for custom rendering of images within the Markdown content
182+ /// when size information is available. It provides a [MarkdownImageConfig]
183+ /// containing the `Uri` , `title` , `alt` , `width` , and `height` of the image.
184+ ///
185+ /// If both [imageBuilder] and [sizedImageBuilder] are `null` , a default image builder
186+ /// will be used.
187+ /// when size information is available. It provides a [MarkdownImageConfig]
188+ /// containing the `Uri` , `title` , `alt` , `width` , and `height` of the image.
189+ ///
190+ /// If both [imageBuilder] and [sizedImageBuilder] are `null` , a default
191+ /// image builder will be used.
192+ ///
193+ /// Only one of [imageBuilder] or [sizedImageBuilder] may be specified.
194+ ///
195+ /// {@endtemplate}
196+ final MarkdownSizedImageBuilder ? sizedImageBuilder;
197+
137198 /// Call when build a checkbox widget.
138199 final MarkdownCheckboxBuilder ? checkboxBuilder;
139200
@@ -619,8 +680,12 @@ class MarkdownBuilder implements md.NodeVisitor {
619680 }
620681
621682 Widget child;
622- if (imageBuilder != null ) {
623- child = imageBuilder !(uri, title, alt);
683+ if (sizedImageBuilder != null ) {
684+ final MarkdownImageConfig config = MarkdownImageConfig (
685+ uri: uri, alt: alt, title: title, height: height, width: width);
686+ child = sizedImageBuilder !(config);
687+ } else if (imageBuilder != null ) {
688+ child = imageBuilder !(uri, alt, title);
624689 } else {
625690 child = kDefaultImageBuilder (uri, imageDirectory, width, height);
626691 }
0 commit comments