2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/archive.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/list_items/chat_list_item.dart';
|
2020-01-05 12:27:03 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.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-05-22 08:57:49 +02:00
|
|
|
const ArchiveView(this.controller, {Key key}) : super(key: key);
|
2020-01-05 12:27:03 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-01 08:12:14 +02:00
|
|
|
return FutureBuilder<List<Room>>(
|
|
|
|
future: controller.getArchive(context),
|
|
|
|
builder: (BuildContext context, snapshot) => Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: BackButton(),
|
|
|
|
title: Text(L10n.of(context).archive),
|
|
|
|
actions: [
|
|
|
|
if (snapshot.hasData &&
|
|
|
|
controller.archive != null &&
|
|
|
|
controller.archive.isNotEmpty)
|
|
|
|
TextButton(
|
|
|
|
onPressed: controller.forgetAllAction,
|
|
|
|
child: Text(L10n.of(context).clearArchive),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Builder(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).oopsSomethingWentWrong,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return Center(child: CircularProgressIndicator());
|
|
|
|
} else {
|
|
|
|
controller.archive = snapshot.data;
|
|
|
|
if (controller.archive.isEmpty) {
|
|
|
|
return Center(child: Icon(Icons.archive_outlined, size: 80));
|
|
|
|
}
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: controller.archive.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
|
|
|
controller.archive[i],
|
|
|
|
onForget: controller.forgetAction,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2020-01-05 12:27:03 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|