@@ -7,6 +7,7 @@ import 'dart:convert';
77import 'package:flutter/cupertino.dart' ;
88import 'package:flutter/gestures.dart' ;
99import 'package:flutter/material.dart' ;
10+ import 'package:flutter/rendering.dart' ;
1011import 'package:markdown/markdown.dart' as md;
1112import 'package:meta/meta.dart' ;
1213
@@ -72,6 +73,40 @@ abstract class MarkdownElementBuilder {
7273/// is running on. Material on Android and Cupertino on iOS
7374enum MarkdownStyleSheetBaseTheme { material, cupertino, platform }
7475
76+ /// Enumeration of alignment strategies for the cross axis of list items.
77+ enum MarkdownListItemCrossAxisAlignment {
78+ /// Uses [CrossAxisAlignment.baseline] for the row the bullet and the list
79+ /// item are placed in.
80+ ///
81+ /// This alignment will ensure that the bullet always lines up with
82+ /// the list text on the baseline.
83+ ///
84+ /// However, note that this alignment does not support intrinsic height
85+ /// measurements because [RenderFlex] does not support it for
86+ /// [CrossAxisAlignment.baseline] .
87+ /// See https://github.com/flutter/flutter_markdown/issues/311 for cases,
88+ /// where this might be a problem for you.
89+ ///
90+ /// See also:
91+ /// * [start] , which allows for intrinsic height measurements.
92+ baseline,
93+
94+ /// Uses [CrossAxisAlignment.start] for the row the bullet and the list item
95+ /// are placed in.
96+ ///
97+ /// This alignment will ensure that intrinsic height measurements work.
98+ ///
99+ /// However, note that this alignment might not line up the bullet with the
100+ /// list text in the way you would expect in certain scenarios.
101+ /// See https://github.com/flutter/flutter_markdown/issues/169 for example
102+ /// cases that do not produce expected results.
103+ ///
104+ /// See also:
105+ /// * [baseline] , which will position the bullet and list item on the
106+ /// baseline.
107+ start,
108+ }
109+
75110/// A base class for widgets that parse and display Markdown.
76111///
77112/// Supports all standard Markdown from the original
@@ -102,9 +137,12 @@ abstract class MarkdownWidget extends StatefulWidget {
102137 this .checkboxBuilder,
103138 this .builders = const {},
104139 this .fitContent = false ,
140+ this .listItemCrossAxisAlignment =
141+ MarkdownListItemCrossAxisAlignment .baseline,
105142 }) : assert (data != null ),
106143 assert (selectable != null ),
107144 assert (builders != null ),
145+ assert (listItemCrossAxisAlignment != null ),
108146 super (key: key);
109147
110148 /// The Markdown to display.
@@ -169,6 +207,13 @@ abstract class MarkdownWidget extends StatefulWidget {
169207 /// Whether to allow the widget to fit the child content.
170208 final bool fitContent;
171209
210+ /// Controls the cross axis alignment for the bullet and list item content
211+ /// in lists.
212+ ///
213+ /// Defaults to [MarkdownListItemCrossAxisAlignment.baseline] , which
214+ /// does not allow for intrinsic height measurements.
215+ final MarkdownListItemCrossAxisAlignment listItemCrossAxisAlignment;
216+
172217 /// Subclasses should override this function to display the given children,
173218 /// which are the parsed representation of [data] .
174219 @protected
@@ -234,6 +279,7 @@ class _MarkdownWidgetState extends State<MarkdownWidget>
234279 checkboxBuilder: widget.checkboxBuilder,
235280 builders: widget.builders,
236281 fitContent: widget.fitContent,
282+ listItemCrossAxisAlignment: widget.listItemCrossAxisAlignment,
237283 );
238284
239285 _children = builder.build (astNodes);
@@ -298,6 +344,8 @@ class MarkdownBody extends MarkdownWidget {
298344 MarkdownImageBuilder imageBuilder,
299345 MarkdownCheckboxBuilder checkboxBuilder,
300346 Map <String , MarkdownElementBuilder > builders = const {},
347+ MarkdownListItemCrossAxisAlignment listItemCrossAxisAlignment =
348+ MarkdownListItemCrossAxisAlignment .baseline,
301349 this .shrinkWrap = true ,
302350 this .fitContent = true ,
303351 }) : super (
@@ -315,6 +363,7 @@ class MarkdownBody extends MarkdownWidget {
315363 imageBuilder: imageBuilder,
316364 checkboxBuilder: checkboxBuilder,
317365 builders: builders,
366+ listItemCrossAxisAlignment: listItemCrossAxisAlignment,
318367 );
319368
320369 /// See [ScrollView.shrinkWrap]
@@ -361,6 +410,8 @@ class Markdown extends MarkdownWidget {
361410 MarkdownImageBuilder imageBuilder,
362411 MarkdownCheckboxBuilder checkboxBuilder,
363412 Map <String , MarkdownElementBuilder > builders = const {},
413+ MarkdownListItemCrossAxisAlignment listItemCrossAxisAlignment =
414+ MarkdownListItemCrossAxisAlignment .baseline,
364415 this .padding = const EdgeInsets .all (16.0 ),
365416 this .controller,
366417 this .physics,
@@ -380,6 +431,7 @@ class Markdown extends MarkdownWidget {
380431 imageBuilder: imageBuilder,
381432 checkboxBuilder: checkboxBuilder,
382433 builders: builders,
434+ listItemCrossAxisAlignment: listItemCrossAxisAlignment,
383435 );
384436
385437 /// The amount of space by which to inset the children.
0 commit comments