fluffychat/lib/pages/chat/encryption_button.dart

48 lines
1.6 KiB
Dart
Raw Normal View History

2020-02-22 08:03:44 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2021-11-09 20:32:16 +00:00
import '../../widgets/matrix.dart';
2020-02-22 08:03:44 +00:00
2022-12-26 16:47:08 +00:00
class EncryptionButton extends StatelessWidget {
2020-02-22 08:03:44 +00:00
final Room room;
const EncryptionButton(this.room, {super.key});
2020-02-22 08:03:44 +00:00
@override
Widget build(BuildContext context) {
2022-12-26 16:47:08 +00:00
return StreamBuilder<SyncUpdate>(
stream: Matrix.of(context)
.client
.onSync
.stream
.where((s) => s.deviceLists != null),
builder: (context, snapshot) {
return FutureBuilder<EncryptionHealthState>(
future: room.encrypted
? room.calcEncryptionHealthState()
: Future.value(EncryptionHealthState.allVerified),
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: () => context.go('/rooms/${room.id}/encryption'),
),
);
},
);
2020-02-22 08:03:44 +00:00
}
}