fluffychat/lib/pages/chat/encryption_button.dart

47 lines
1.5 KiB
Dart
Raw Normal View History

2020-02-22 09:03:44 +01:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.dart';
2021-10-26 18:50:34 +02:00
2021-11-09 21:32:16 +01:00
import '../../widgets/matrix.dart';
2020-02-22 09:03:44 +01:00
2022-12-26 17:47:08 +01:00
class EncryptionButton extends StatelessWidget {
2020-02-22 09:03:44 +01:00
final Room room;
2022-01-29 12:35:03 +01:00
const EncryptionButton(this.room, {Key? key}) : super(key: key);
2020-02-22 09:03:44 +01:00
@override
Widget build(BuildContext context) {
2022-12-26 17:47:08 +01:00
return StreamBuilder<SyncUpdate>(
stream: Matrix.of(context)
.client
.onSync
.stream
.where((s) => s.deviceLists != null),
builder: (context, snapshot) {
return FutureBuilder<EncryptionHealthState>(
future: room.calcEncryptionHealthState(),
builder: (BuildContext context, snapshot) => IconButton(
tooltip: room.encrypted
? L10n.of(context)!.encrypted
: L10n.of(context)!.encryptionNotEnabled,
icon: Icon(
room.encrypted ? Icons.lock_outlined : Icons.lock_open_outlined,
size: 20,
color: room.joinRules != JoinRules.public && !room.encrypted
? Colors.red
: room.joinRules != JoinRules.public &&
snapshot.data ==
EncryptionHealthState.unverifiedDevices
? Colors.orange
: null,
),
onPressed: () => VRouter.of(context)
.toSegments(['rooms', room.id, 'encryption']),
),
);
},
);
2020-02-22 09:03:44 +01:00
}
}