From bfa98720bf771ed8c177467a26f22b511864f9af Mon Sep 17 00:00:00 2001 From: zoe Date: Mon, 1 Aug 2022 10:29:43 +0200 Subject: [PATCH] shows posts now... (i know) --- lib/business_logic/timeline/timeline.dart | 1 - lib/pages/settings/account.dart | 4 ++-- lib/pages/timeline/timeline.dart | 13 ++++++++++++- lib/partials/post.dart | 17 ++++++++++------- lib/partials/thread.dart | 19 +++++++++++-------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/business_logic/timeline/timeline.dart b/lib/business_logic/timeline/timeline.dart index 5dd95f4..242669c 100644 --- a/lib/business_logic/timeline/timeline.dart +++ b/lib/business_logic/timeline/timeline.dart @@ -95,7 +95,6 @@ Future getTimelineFromServer() async { ids.add(json[i]["id"]); final post = PostModel.fromJson(json[i]); final thread = await post.getThread(); - print(thread.posts[0].content); i++; } diff --git a/lib/pages/settings/account.dart b/lib/pages/settings/account.dart index 86e0fd3..9e6c00f 100644 --- a/lib/pages/settings/account.dart +++ b/lib/pages/settings/account.dart @@ -25,8 +25,8 @@ class LogoutButton extends StatelessWidget { FutureBuilder( future: settings.loadInstanceUrl(), builder: (context, snapshot) { - if (snapshot.hasData && snapshot.data != null) { - return Text("instance name"); + if (snapshot.hasData) { + return Text(snapshot.data ?? "no-instance".i18n()); } else { return const CircularProgressIndicator(); } diff --git a/lib/pages/timeline/timeline.dart b/lib/pages/timeline/timeline.dart index 99d0b0d..0b9f178 100644 --- a/lib/pages/timeline/timeline.dart +++ b/lib/pages/timeline/timeline.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:localization/localization.dart'; import 'package:slothmu/partials/thread.dart'; @@ -29,12 +31,21 @@ class _TimelineState extends State { Future fetchMore() async { loading = true; + final response = await tl.getTimelineFromServer(); + final json = jsonDecode(response.body)[0]; + final post = tl.PostModel.fromJson(json); + final model = await post.getThread(); + setState(() { if (children.isNotEmpty) { children.removeAt(children.length - 1); } - children.addAll([Thread()]); + children.addAll([ + Thread( + model: model, + ) + ]); children.add( Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/partials/post.dart b/lib/partials/post.dart index deb24b6..cb760b3 100644 --- a/lib/partials/post.dart +++ b/lib/partials/post.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; import 'package:localization/localization.dart'; +import '../business_logic/timeline/timeline.dart' as tl; class Post extends StatefulWidget { - const Post({Key? key}) : super(key: key); + const Post({required this.model, Key? key}) : super(key: key); + final tl.PostModel model; @override State createState() => _PostState(); @@ -14,7 +16,9 @@ class _PostState extends State { return Column( children: [ const DisplayName(), - const PostBody(), + PostBody( + content: widget.model.content, + ), postActionBar(context), ], ); @@ -54,7 +58,8 @@ class DisplayName extends StatelessWidget { } class PostBody extends StatefulWidget { - const PostBody({Key? key}) : super(key: key); + const PostBody({required this.content, Key? key}) : super(key: key); + final String content; @override State createState() => _PostBodyState(); @@ -72,8 +77,7 @@ class _PostBodyState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - "sdkfjksdjfkd sldkjfksdjf dskfjsdkfjkds skdfjksdjfisdujfiosdhfjkldsfh sldkfjksdjfksdjfklsdjf"), + Text(widget.content), OutlinedButton.icon( onPressed: () { setState(() { @@ -95,8 +99,7 @@ class _PostBodyState extends State { textAlign: TextAlign.start, text: TextSpan( style: Theme.of(context).textTheme.bodyMedium, - text: - "Lorem ipsumLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Auctor neque vitae tempus quam pellentesque. Scelerisque varius morbi enim nunc faucibus a. Tellus id interdum velit laoreet id donec ultrices. Aliquet bibendum enim facilisis gravida neque convallis a. Massa enim nec dui nunc mattis enim ut tellus. Sed felis eget velit aliquet sagittis id consectetur purus ut. Dignissim convallis aenean et tortor at risus. Integer vitae justo eget magna fermentum iaculis eu non. Ut placerat orci nulla pellentesque dignissim. Nisl suscipit adipiscing bibendum est ultricies. Mi ipsum faucibus vitae aliquet nec ullamcorper sit amet risus."), + text: widget.content), ), ), ], diff --git a/lib/partials/thread.dart b/lib/partials/thread.dart index 50c76e1..001ad70 100644 --- a/lib/partials/thread.dart +++ b/lib/partials/thread.dart @@ -1,16 +1,19 @@ import 'package:flutter/material.dart'; import 'package:slothmu/partials/post.dart'; +import '../business_logic/timeline/timeline.dart' as logic; -class Thread extends StatefulWidget { - const Thread({Key? key}) : super(key: key); +class Thread extends StatelessWidget { + const Thread({required this.model, Key? key}) : super(key: key); + final logic.ThreadModel model; - @override - State createState() => _ThreadState(); -} - -class _ThreadState extends State { @override Widget build(BuildContext context) { + List posts = []; + for (int i = 0; i < model.posts.length; i++) { + posts.add(Post(model: model.posts[i])); + } + + print(model.posts[0].content); return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -27,7 +30,7 @@ class _ThreadState extends State { borderRadius: BorderRadius.circular(8), ), child: Column( - children: [Post(), Post(), Post()], + children: posts, ), ), ),