fluffychat/lib/pages/archive/archive_view.dart

66 lines
2.1 KiB
Dart
Raw Normal View History

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