rename to loris
This commit is contained in:
parent
05eef7f783
commit
30de8189bc
8 changed files with 104 additions and 19 deletions
|
@ -1,13 +1,80 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:slothmu/partials/post.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import '../../business_logic/settings.dart' as settings;
|
||||
import 'package:slothmu/partials/thread.dart';
|
||||
|
||||
Widget timeline(context) {
|
||||
return Container(
|
||||
child: ListView(
|
||||
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,
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 64),
|
||||
addAutomaticKeepAlives: false,
|
||||
children: [Thread(), Thread(), Thread()],
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue