showMarkdownFile2 function
- String markdownFilePath,
- String newMarkdownFilePath,
- BuildContext context
A scrolling widget that parses and displays Markdown file,
which is located under the path markdownFilePath
.
It allows handling asynchronous loading of markdown file.
Implementation
FutureBuilder showMarkdownFile2(
String markdownFilePath,
String newMarkdownFilePath,
BuildContext context,
) {
return FutureBuilder(
key: const Key('markdown_file_new'),
future: loadAsset(markdownFilePath),
builder: (context, snapshot) {
if (snapshot.hasData) {
// Wrap the markdown data into rows with a maximum of 100 characters.
final wrappedMarkdown = _wrapText(snapshot.data!, 100);
return FutureBuilder(
future: loadAsset(newMarkdownFilePath),
builder: (context, newSnapshot) {
if (newSnapshot.hasData) {
// Wrap the new markdown data as well.
final wrappedNewMarkdown = _wrapText(newSnapshot.data!, 100);
return Container(
decoration: sunkenBoxDecoration,
child: Row(
children: [
// Left side: Original Markdown content taking 50% of the screen width.
Expanded(
flex: 5,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Markdown(
data: wrappedMarkdown,
selectable: true,
onTapLink: (text, href, title) {
final Uri url = Uri.parse(href ?? '');
launchUrl(url);
},
imageBuilder: (uri, title, alt) {
return Image.asset('$assetsPath/${uri.toString()}');
},
),
),
),
// Right side: New Markdown content taking 50% of the screen width.
Expanded(
flex: 5,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Markdown(
data: wrappedNewMarkdown,
selectable: true,
onTapLink: (text, href, title) {
final Uri url = Uri.parse(href ?? '');
launchUrl(url);
},
imageBuilder: (uri, title, alt) {
return Image.asset('$assetsPath/${uri.toString()}');
},
),
),
),
],
),
);
}
return const Center(child: CircularProgressIndicator());
},
);
}
return const Center(child: CircularProgressIndicator());
},
);
}