fluffychat/lib/pages/archive/archive_view.dart

63 lines
2.0 KiB
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-10-26 18:50:34 +02:00
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/archive/archive.dart';
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
2020-01-05 12:27:03 +01:00
2021-05-22 08:57:49 +02:00
class ArchiveView extends StatelessWidget {
2021-04-12 18:33:43 +02:00
final ArchiveController controller;
2020-01-05 12:27:03 +01:00
2021-12-13 09:40:53 +01:00
const ArchiveView(this.controller, {Key? key}) : super(key: key);
2020-01-05 12:27:03 +01:00
@override
Widget build(BuildContext context) {
2021-12-13 09:40:53 +01:00
var archive = controller.archive;
2021-05-01 08:12:14 +02:00
return FutureBuilder<List<Room>>(
future: controller.getArchive(context),
builder: (BuildContext context, snapshot) => Scaffold(
appBar: AppBar(
2021-10-14 18:09:30 +02:00
leading: const BackButton(),
2021-12-13 09:40:53 +01:00
title: Text(L10n.of(context)!.archive),
2021-05-01 08:12:14 +02:00
actions: [
2021-12-13 09:40:53 +01:00
if (snapshot.hasData && archive != null && archive!.isNotEmpty)
2021-05-01 08:12:14 +02:00
TextButton(
onPressed: controller.forgetAllAction,
2021-12-13 09:40:53 +01:00
child: Text(L10n.of(context)!.clearArchive),
2021-05-01 08:12:14 +02:00
)
],
),
body: Builder(
builder: (BuildContext context) {
if (snapshot.hasError) {
return Center(
child: Text(
2021-12-13 09:40:53 +01:00
L10n.of(context)!.oopsSomethingWentWrong,
2021-05-01 08:12:14 +02:00
textAlign: TextAlign.center,
));
}
if (!snapshot.hasData) {
2021-10-14 18:09:30 +02:00
return const Center(
2021-10-10 13:38:06 +02:00
child: CircularProgressIndicator.adaptive(strokeWidth: 2));
2021-05-01 08:12:14 +02:00
} else {
2021-12-13 09:40:53 +01:00
archive = snapshot.data;
if (archive == null || archive!.isEmpty) {
2021-10-17 14:15:29 +02:00
return const Center(
child: Icon(Icons.archive_outlined, size: 80));
2021-05-01 08:12:14 +02:00
}
return ListView.builder(
2021-12-13 09:40:53 +01:00
itemCount: archive!.length,
2021-05-01 08:12:14 +02:00
itemBuilder: (BuildContext context, int i) => ChatListItem(
2021-12-13 09:40:53 +01:00
archive![i],
2021-05-01 08:12:14 +02:00
onForget: controller.forgetAction,
),
);
}
},
),
2020-01-05 12:27:03 +01:00
),
);
}
}