fluffychat/lib/views/archive.dart

63 lines
1.9 KiB
Dart
Raw Normal View History

2020-01-05 12:27:03 +01:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/list_items/chat_list_item.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-01-05 12:27:03 +01:00
class Archive extends StatefulWidget {
@override
_ArchiveState createState() => _ArchiveState();
}
class _ArchiveState extends State<Archive> {
List<Room> archive;
Future<List<Room>> getArchive(BuildContext context) async {
if (archive != null) return archive;
return await Matrix.of(context).client.archive;
}
2020-12-06 12:51:40 +01:00
final ScrollController _scrollController = ScrollController();
bool _scrolledToTop = true;
@override
void initState() {
_scrollController.addListener(() async {
if (_scrollController.position.pixels > 0 && _scrolledToTop) {
setState(() => _scrolledToTop = false);
} else if (_scrollController.position.pixels == 0 && !_scrolledToTop) {
setState(() => _scrolledToTop = true);
}
});
super.initState();
}
2020-01-05 12:27:03 +01:00
@override
Widget build(BuildContext context) {
2021-01-16 12:46:38 +01:00
return Scaffold(
appBar: AppBar(
2021-01-16 14:24:52 +01:00
leading: BackButton(),
2021-01-16 12:46:38 +01:00
title: Text(L10n.of(context).archive),
elevation: _scrolledToTop ? 0 : null,
2020-01-05 12:27:03 +01:00
),
2021-01-16 12:46:38 +01:00
body: FutureBuilder<List<Room>>(
future: getArchive(context),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else {
archive = snapshot.data;
return ListView.builder(
controller: _scrollController,
itemCount: archive.length,
itemBuilder: (BuildContext context, int i) => ChatListItem(
archive[i],
onForget: () => setState(() => archive.removeAt(i))),
);
}
},
2020-01-05 12:27:03 +01:00
),
);
}
}