fluffychat/lib/pages/archive/archive_view.dart

69 lines
2.2 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: [
2023-01-08 12:32:35 +01: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 08:12:14 +02:00
)
],
),
body: Builder(
builder: (BuildContext context) {
if (snapshot.hasError) {
return Center(
child: Text(
L10n.of(context)!.oopsSomethingWentWrong,
textAlign: TextAlign.center,
),
);
2021-05-01 08:12:14 +02:00
}
if (!snapshot.hasData) {
2021-10-14 18:09:30 +02:00
return const Center(
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
),
);
}
},
),
2020-01-05 12:27:03 +01:00
),
);
}
}