mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
md #1
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_md/flutter_md.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:swift_control/widgets/ui/colored_title.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class MarkdownPage extends StatefulWidget {
|
||||
@@ -67,27 +68,61 @@ class _ChangelogPageState extends State<MarkdownPage> {
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MarkdownWidget(
|
||||
markdown: _markdown!,
|
||||
theme: MarkdownThemeData(
|
||||
textStyle: TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Theme.of(context).colorScheme.brightness == Brightness.dark
|
||||
? Colors.white.withAlpha(255 * 70)
|
||||
: Colors.black.withAlpha(87 * 255),
|
||||
child: Accordion(
|
||||
items: _markdown!.blocks.fold(<Widget>[], (acc, block) {
|
||||
if (block is MD$Heading) {
|
||||
acc.add(
|
||||
AccordionItem(
|
||||
trigger: AccordionTrigger(child: ColoredTitle(text: block.text)),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [],
|
||||
),
|
||||
onLinkTap: (title, url) {
|
||||
launchUrlString(url);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
((acc.last as AccordionItem).content as Column).children.add(
|
||||
switch (block.type) {
|
||||
_ when block is MD$Paragraph => Text(block.text).small,
|
||||
_ when block is MD$List => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (var item in block.items) ...[
|
||||
if (item.children.isEmpty)
|
||||
fromString(item.text).li
|
||||
else
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
fromString(item.text),
|
||||
for (var line in item.children) fromString(line.text).li,
|
||||
],
|
||||
).li,
|
||||
],
|
||||
],
|
||||
),
|
||||
_ when block is MD$Spacer => SizedBox(height: 16),
|
||||
_ => SizedBox.shrink(),
|
||||
},
|
||||
);
|
||||
}
|
||||
return acc;
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
MarkdownWidget fromString(String md) {
|
||||
final markdown = Markdown.fromString(md);
|
||||
return MarkdownWidget(
|
||||
markdown: markdown,
|
||||
theme: MarkdownThemeData(
|
||||
onLinkTap: (title, url) {
|
||||
launchUrlString(url);
|
||||
},
|
||||
textStyle: TextStyle(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user