2021-10-26 16:50:34 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-06-18 08:29:48 +00:00
|
|
|
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';
|
2023-08-13 14:10:31 +00:00
|
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.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
|
|
|
|
2023-10-28 11:03:16 +00:00
|
|
|
const ArchiveView(this.controller, {super.key});
|
2020-01-05 11:27:03 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-01 06:12:14 +00:00
|
|
|
return FutureBuilder<List<Room>>(
|
|
|
|
future: controller.getArchive(context),
|
|
|
|
builder: (BuildContext context, snapshot) => Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-08-13 16:23:36 +00:00
|
|
|
leading: const Center(child: 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),
|
|
|
|
),
|
2023-08-18 05:24:31 +00:00
|
|
|
),
|
2021-05-01 06:12:14 +00:00
|
|
|
],
|
|
|
|
),
|
2023-08-13 14:10:31 +00:00
|
|
|
body: MaxWidthBody(
|
|
|
|
withScrolling: false,
|
|
|
|
child: Builder(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context)!.oopsSomethingWentWrong,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
2021-10-17 12:15:29 +00:00
|
|
|
return const Center(
|
2023-08-13 14:10:31 +00:00
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
|
|
);
|
|
|
|
} else {
|
2023-10-29 09:59:07 +00:00
|
|
|
if (controller.archive.isEmpty) {
|
2023-08-13 14:10:31 +00:00
|
|
|
return const Center(
|
|
|
|
child: Icon(Icons.archive_outlined, size: 80),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ListView.builder(
|
2023-10-29 09:59:07 +00:00
|
|
|
itemCount: controller.archive.length,
|
2023-08-13 14:10:31 +00:00
|
|
|
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
2023-10-29 09:59:07 +00:00
|
|
|
controller.archive[i],
|
|
|
|
onForget: () => controller.forgetRoomAction(i),
|
2023-08-13 14:10:31 +00:00
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
);
|
2021-05-01 06:12:14 +00:00
|
|
|
}
|
2023-08-13 14:10:31 +00:00
|
|
|
},
|
|
|
|
),
|
2021-05-01 06:12:14 +00:00
|
|
|
),
|
2020-01-05 11:27:03 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|