2022-06-16 20:30:02 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-07-04 17:37:53 +00:00
|
|
|
import 'package:localization/localization.dart';
|
|
|
|
import '../../business_logic/settings.dart' as settings;
|
2022-07-03 13:47:24 +00:00
|
|
|
import 'package:slothmu/partials/thread.dart';
|
2022-06-16 20:30:02 +00:00
|
|
|
|
2022-07-04 17:37:53 +00:00
|
|
|
class Timeline extends StatefulWidget {
|
|
|
|
const Timeline({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Timeline> createState() => _TimelineState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TimelineState extends State<Timeline> {
|
|
|
|
final controller = ScrollController();
|
|
|
|
List<Widget> children = [];
|
|
|
|
bool loading = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
fetchMore();
|
|
|
|
controller.addListener(() {
|
|
|
|
if (controller.position.maxScrollExtent <= controller.offset &&
|
|
|
|
!loading) {
|
|
|
|
fetchMore();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future fetchMore() async {
|
|
|
|
loading = true;
|
|
|
|
final token = await settings.loadAuthCode();
|
|
|
|
setState(() {
|
|
|
|
if (children.isNotEmpty) {
|
|
|
|
children.removeAt(children.length - 1);
|
|
|
|
}
|
|
|
|
children.addAll([Thread()]);
|
|
|
|
children.add(
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
TextButton.icon(
|
|
|
|
onPressed: () {
|
|
|
|
fetchMore();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.more_horiz),
|
|
|
|
label: Text("load-more".i18n()),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListView.separated(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
controller: controller,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return children[index];
|
|
|
|
},
|
|
|
|
separatorBuilder: (context, index) {
|
|
|
|
return const Divider(
|
|
|
|
color: Colors.transparent,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: children.length,
|
2022-07-03 13:47:24 +00:00
|
|
|
padding: const EdgeInsets.fromLTRB(24, 0, 24, 64),
|
|
|
|
addAutomaticKeepAlives: false,
|
2022-07-04 17:37:53 +00:00
|
|
|
);
|
|
|
|
}
|
2022-06-16 20:30:02 +00:00
|
|
|
}
|