finally, paragraphs
This commit is contained in:
parent
ea2089fff9
commit
f71bcf1d42
|
@ -16,6 +16,8 @@
|
|||
"show-about-page": "show about page",
|
||||
"about": "about",
|
||||
"account-settings": "account settings",
|
||||
"logout": "log out"
|
||||
"logout": "log out",
|
||||
"show-in-browser": "show in browser",
|
||||
"post-options": "post options"
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ class AboutSettings extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
return Row(children: [
|
||||
Text("about".i18n()),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
|
|
|
@ -28,7 +28,7 @@ class _PostState extends State<Post> {
|
|||
spoilerText: widget.model.spoilerText,
|
||||
media: widget.model.attachments,
|
||||
),
|
||||
postActionBar(context),
|
||||
postActionBar(context, widget.model),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ class _PostBodyState extends State<PostBody> {
|
|||
}
|
||||
}
|
||||
|
||||
Widget postActionBar(context) {
|
||||
Widget postActionBar(context, tl.PostModel model) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
@ -182,7 +182,7 @@ Widget postActionBar(context) {
|
|||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
popupPostOptions(context);
|
||||
popupPostOptions(context, model);
|
||||
},
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
)
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/business_logic/timeline/timeline.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void popupPostOptions(context) {
|
||||
//TODO
|
||||
void popupPostOptions(context, PostModel model) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SimpleDialog(
|
||||
title: SelectableText("eee"),
|
||||
);
|
||||
});
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SimpleDialog(
|
||||
titleTextStyle: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: SelectableText("post-options".i18n()),
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
launchUrl(
|
||||
Uri.parse(model.uri),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser),
|
||||
label: Text("show-in-browser".i18n()),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:html/dom.dart' as dom;
|
||||
import 'package:html/parser.dart' as parser;
|
||||
|
||||
class PostTextRenderer extends StatelessWidget {
|
||||
const PostTextRenderer({
|
||||
|
@ -10,8 +11,43 @@ class PostTextRenderer extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var document = parse(htmlInput);
|
||||
return SelectableText.rich(
|
||||
TextSpan(text: document.body?.text, children: []));
|
||||
dom.Document document = parser.parse(htmlInput);
|
||||
final List<InlineSpan> children = createSpansFromDoc(document);
|
||||
return SelectableText.rich(TextSpan(
|
||||
text: "",
|
||||
children: children,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
List<InlineSpan> createSpansFromDoc(dom.Document document) {
|
||||
List<InlineSpan> result = [];
|
||||
for (int i = 0; i < document.body!.children.length; i += 1) {
|
||||
final e = document.body!.children[i];
|
||||
result.add(
|
||||
getSpanForElement(
|
||||
e,
|
||||
document.body!.children.length,
|
||||
i,
|
||||
),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
InlineSpan getSpanForElement(dom.Element e, int bodyLength, int pos) {
|
||||
if (e.toString() == "<html p>") {
|
||||
return handleParagraph(e, bodyLength, pos);
|
||||
}
|
||||
return TextSpan(text: e.text);
|
||||
}
|
||||
|
||||
InlineSpan handleParagraph(dom.Element e, int bodyLength, int pos) {
|
||||
String text = e.text;
|
||||
return WidgetSpan(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 4, 0, 4),
|
||||
child: SelectableText(text),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue