make scrolling nicer

This commit is contained in:
zoe 2022-08-09 20:58:11 +02:00
parent e46876f10a
commit d5675521f8
4 changed files with 23 additions and 14 deletions

View File

@ -114,13 +114,13 @@ Future<ThreadModel> getTimelineFromServer(String? olderThan) async {
Map<String, String> headers = {"Authorization": "Bearer $token"};
headers.addAll(global.defaultHeaders);
final response = await http.get(url, headers: headers);
final List<dynamic> json = await jsonDecode(response.body);
if (json.isEmpty) {
print(" error json empty");
print(response.body);
http.Response response = await http.get(url, headers: headers);
while (response.statusCode != 200) {
await Future.delayed(const Duration(seconds: 5));
response = await http.get(url, headers: headers);
}
final List<dynamic> json = await jsonDecode(response.body);
final PostModel post = PostModel.fromJson(json[0]);
return await post.getThread();

View File

@ -18,9 +18,12 @@ class _TimelineState extends State<Timeline> {
@override
void initState() {
super.initState();
fetchMore();
for (int i = 0; i <= 20; i++) {
fetchMore();
}
controller.addListener(() {
if (controller.position.maxScrollExtent <= controller.offset &&
if (controller.position.maxScrollExtent <=
controller.offset + MediaQuery.of(context).size.height &&
!loading) {
fetchMore();
}
@ -28,6 +31,9 @@ class _TimelineState extends State<Timeline> {
}
Future fetchMore() async {
while (loading) {
await Future.delayed(const Duration(milliseconds: 500));
}
loading = true;
final model = await tl.getTimelineFromServer(id);

View File

@ -12,7 +12,7 @@ void popupPostOptions(context, PostModel model) {
backgroundColor: Theme.of(context).colorScheme.surface,
title: SelectableText("post-options".i18n()),
alignment: Alignment.center,
contentPadding: EdgeInsetsDirectional.all(8),
contentPadding: const EdgeInsetsDirectional.all(8),
children: [
SelectableText(model.createdAt),
TextButton.icon(

View File

@ -12,7 +12,8 @@ class PostTextRenderer extends StatelessWidget {
@override
Widget build(BuildContext context) {
dom.Document document = parser.parse(htmlInput);
final List<InlineSpan> children = createSpansFromDoc(document);
final List<InlineSpan> children =
createSpansFromDoc(document.body!.children);
return SelectableText.rich(TextSpan(
text: "",
children: children,
@ -20,14 +21,14 @@ class PostTextRenderer extends StatelessWidget {
}
}
List<InlineSpan> createSpansFromDoc(dom.Document document) {
List<InlineSpan> createSpansFromDoc(List<dom.Element> elements) {
List<InlineSpan> result = [];
for (int i = 0; i < document.body!.children.length; i += 1) {
final e = document.body!.children[i];
for (int i = 0; i < elements.length; i += 1) {
final e = elements[i];
result.add(
getSpanForElement(
e,
document.body!.children.length,
elements.length,
i,
),
);
@ -47,7 +48,9 @@ InlineSpan handleParagraph(dom.Element e, int bodyLength, int pos) {
return WidgetSpan(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 4),
child: SelectableText(text),
child: SelectableText(
text,
),
),
);
}