mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 07:48:40 +00:00
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
84 lines
2.1 KiB
Dart
84 lines
2.1 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:twonly/globals.dart';
|
|
import 'package:twonly/src/database/twonly.db.dart';
|
|
import 'package:twonly/src/views/public_profile.view.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
|
|
: () async {
|
|
await Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return const PublicProfileView();
|
|
},
|
|
),
|
|
);
|
|
},
|
|
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|