Skip to content

Commit

Permalink
made the bullet size and its padding, baseline be determined by the l…
Browse files Browse the repository at this point in the history
…ist item's font size
  • Loading branch information
ali-thowfeek committed Mar 20, 2021
1 parent 7ae7a60 commit 62930ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Home extends StatelessWidget {
defaultTextStyle: TextStyle(color: Colors.grey[700]),
overrideStyle: <String, TextStyle>{
'p': const TextStyle(fontSize: 17.3),
'li': const TextStyle(fontSize: 15),
'a': const TextStyle(wordSpacing: 2),
// specify any tag not just the supported ones,
// and apply TextStyles to them and/override them
Expand Down
26 changes: 14 additions & 12 deletions lib/src/internals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ class Parser {
}
}

// TODO: see if there is a better way to add space after these tags
// maybe use widget spans
if (event is XmlEndElementEvent) {
if (event.name == 'p' ||
event.name == 'h1' ||
Expand Down Expand Up @@ -328,10 +326,16 @@ class Parser {

if (start > 0) returnedSpans.addAll(spans.getRange(0, start));

final List<TextSpan> listItems =
final List<TextSpan> singleListItemSpans =
spans.getRange(start + 1, end).toList();

if (listItems.isNotEmpty) {
if (singleListItemSpans.isNotEmpty) {
// Bullet size and the baseline height is determined by
// the first spans font size. if Its null then falls back to 14
double bulletFontSize =
singleListItemSpans.first.style?.fontSize ?? 14;
bulletFontSize = bulletFontSize + bulletFontSize / 4;

returnedSpans.add(
TextSpan(
children: <WidgetSpan>[
Expand All @@ -341,18 +345,16 @@ class Parser {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
Padding(
padding: EdgeInsets.symmetric(
horizontal: bulletFontSize * 0.55),
child: Baseline(
//TODO: make this val calculated from the font size
baseline: 14,
baseline: bulletFontSize * 0.7,
baselineType: TextBaseline.alphabetic,
child: Text(
'•',
textScaleFactor: 1,
style: TextStyle(
//TODO: make this val calculated
fontSize: 18,
fontSize: bulletFontSize,
fontWeight: FontWeight.bold,
),
),
Expand All @@ -361,7 +363,7 @@ class Parser {
Expanded(
child: RichText(
text: TextSpan(
children: listItems,
children: singleListItemSpans,
),
),
),
Expand Down

0 comments on commit 62930ef

Please sign in to comment.