-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ib): scroll to index links in table of contents
Signed-off-by: Manjot Sidhu <manjot.techie@gmail.com>
- Loading branch information
1 parent
0bce311
commit d508ad2
Showing
7 changed files
with
207 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_markdown/flutter_markdown.dart'; | ||
import 'package:markdown/markdown.dart' as md; | ||
import 'package:mobile_app/services/ib_engine_service.dart'; | ||
import 'package:scroll_to_index/scroll_to_index.dart'; | ||
|
||
class IbHeadingsBuilder extends MarkdownElementBuilder { | ||
final Map<String, int> slugMap; | ||
final AutoScrollController controller; | ||
final bool selectable; | ||
var index = 0; | ||
|
||
IbHeadingsBuilder({this.slugMap, this.controller, this.selectable = true}); | ||
|
||
@override | ||
Widget visitElementAfter(md.Element element, TextStyle preferredStyle) { | ||
var text = element.textContent; | ||
|
||
var widget = selectable | ||
? SelectableText( | ||
text, | ||
style: preferredStyle, | ||
) | ||
: Text( | ||
text, | ||
style: preferredStyle, | ||
); | ||
|
||
slugMap[IbEngineService.getSlug(text)] = index; | ||
|
||
return AutoScrollTag( | ||
key: ValueKey(index), | ||
controller: controller, | ||
index: index++, | ||
child: widget, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.