mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-03-03 12:16:47 +00:00
76 lines
1.9 KiB
Dart
76 lines
1.9 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:twonly/globals.dart';
|
|
import 'package:twonly/src/constants/routes.keys.dart';
|
|
import 'package:twonly/src/database/twonly.db.dart';
|
|
|
|
class VerifiedShield extends StatefulWidget {
|
|
const VerifiedShield({
|
|
this.contact,
|
|
this.group,
|
|
super.key,
|
|
this.size = 18,
|
|
});
|
|
final Group? group;
|
|
final Contact? contact;
|
|
final double size;
|
|
|
|
@override
|
|
State<VerifiedShield> createState() => _VerifiedShieldState();
|
|
}
|
|
|
|
class _VerifiedShieldState extends State<VerifiedShield> {
|
|
bool isVerified = false;
|
|
Contact? contact;
|
|
|
|
StreamSubscription<List<Contact>>? stream;
|
|
|
|
@override
|
|
void initState() {
|
|
if (widget.group != null) {
|
|
stream = twonlyDB.groupsDao
|
|
.watchGroupContact(widget.group!.groupId)
|
|
.listen((contacts) {
|
|
if (contacts.length == 1) {
|
|
contact = contacts.first;
|
|
}
|
|
setState(() {
|
|
isVerified = contacts.any((t) => t.verified);
|
|
});
|
|
});
|
|
} else if (widget.contact != null) {
|
|
isVerified = widget.contact!.verified;
|
|
contact = widget.contact;
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
stream?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: (contact == null)
|
|
? null
|
|
: () => context.push(Routes.settingsPublicProfile),
|
|
child: Tooltip(
|
|
message: isVerified
|
|
? 'You verified this contact'
|
|
: 'You have not verifies this contact.',
|
|
child: FaIcon(
|
|
isVerified ? FontAwesomeIcons.shieldHeart : Icons.gpp_maybe_rounded,
|
|
color:
|
|
isVerified ? Theme.of(context).colorScheme.primary : Colors.red,
|
|
size: widget.size,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|