fix error where app tried to set state off a nonexistant widget

This commit is contained in:
zoe 2022-08-15 16:20:57 +02:00
parent 7c3bbe700f
commit f627f248fb
3 changed files with 40 additions and 38 deletions

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:loris/business_logic/settings.dart';
import './pages/timeline/timeline.dart' as tl;
const String name = "loris";
const String version = "v0.1 'is this thing on'";
@ -8,8 +7,6 @@ const String useragent = "$name/$version";
const String website = "https://git.kittycat.homes/zoe/loris";
const String legalese = "todo";
final GlobalKey<tl.TimelineState> tlKey = GlobalKey<tl.TimelineState>();
const Map<String, String> defaultHeaders = {
"User-Agent": useragent,
"accept": "application/json",

View File

@ -41,40 +41,42 @@ class TimelineState extends State<Timeline> with AutomaticKeepAliveClientMixin {
final models = await tl.getTimelineFromServer(
oldestId, selectedId, selectedTimelineType);
setState(() {
children.removeWhere((element) {
return element.runtimeType != Thread;
if (mounted) {
setState(() {
children.removeWhere((element) {
return element.runtimeType != Thread;
});
List<Thread> threads = [];
for (int i = 0; i < models.length; i++) {
threads.add(Thread(model: models[i]));
}
if (models.isNotEmpty) {
oldestId = models.last.posts.last.id;
}
children.addAll(threads);
children.add(
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton.icon(
onPressed: () {
fetchMore();
},
icon: const Icon(Icons.more_horiz),
label: Text(
"load-more".i18n(),
),
)
],
),
);
children.add(const LoadingBox());
loading = false;
});
List<Thread> threads = [];
for (int i = 0; i < models.length; i++) {
threads.add(Thread(model: models[i]));
}
if (models.isNotEmpty) {
oldestId = models.last.posts.last.id;
}
children.addAll(threads);
children.add(
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton.icon(
onPressed: () {
fetchMore();
},
icon: const Icon(Icons.more_horiz),
label: Text(
"load-more".i18n(),
),
)
],
),
);
children.add(const LoadingBox());
loading = false;
});
}
}
@override
@ -94,6 +96,7 @@ class TimelineState extends State<Timeline> with AutomaticKeepAliveClientMixin {
child: Text(global.settings!.identities.keys.toList()[i]),
));
}
selectedId = global.settings!.activeIdentity;
return Column(
children: [
Container(
@ -110,7 +113,7 @@ class TimelineState extends State<Timeline> with AutomaticKeepAliveClientMixin {
DropdownButton(
value: selectedId,
items: identities,
onChanged: (dynamic value) {
onChanged: (dynamic value) async {
setState(() {
selectedId = value ?? global.settings!.activeIdentity;
global.settings!.saveActiveIdentity(selectedId);

View File

@ -7,6 +7,7 @@ import 'package:loris/pages/timeline/timeline.dart';
import 'package:loris/pages/settings/settings.dart';
import '../global.dart' as global;
import '../business_logic/websocket.dart' as websocket;
import '../pages/timeline/timeline.dart' as tl;
class MainScaffold extends StatefulWidget {
const MainScaffold({Key? key}) : super(key: key);
@ -20,10 +21,11 @@ class _MainScaffoldState extends State<MainScaffold> {
@override
Widget build(BuildContext context) {
final GlobalKey<tl.TimelineState> tlKey = GlobalKey<tl.TimelineState>();
websocket.reloadWebsockets();
final screens = [
Timeline(
key: global.tlKey,
key: tlKey,
),
chat(context),
notifications(context),