2024-07-23 17:17:41 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/relations.dart';
|
|
|
|
import 'package:solian/providers/relation.dart';
|
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
|
|
|
import 'package:solian/widgets/account/account_profile_popup.dart';
|
|
|
|
|
|
|
|
class SilverRelativeList extends StatelessWidget {
|
|
|
|
final List<Relationship> items;
|
|
|
|
final Function onUpdate;
|
|
|
|
final bool isHandleable;
|
|
|
|
|
|
|
|
const SilverRelativeList({
|
|
|
|
super.key,
|
|
|
|
required this.items,
|
|
|
|
required this.onUpdate,
|
|
|
|
this.isHandleable = true,
|
|
|
|
});
|
|
|
|
|
|
|
|
Widget buildItem(context, index) {
|
|
|
|
final element = items[index];
|
|
|
|
return ListTile(
|
|
|
|
title: Text(element.related.nick),
|
|
|
|
subtitle: Text(element.related.name),
|
|
|
|
leading: GestureDetector(
|
2024-10-11 16:41:03 +00:00
|
|
|
child: AttachedCircleAvatar(content: element.related.avatar),
|
2024-07-23 17:17:41 +00:00
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isScrollControlled: true,
|
2024-09-26 15:47:19 +00:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
2024-07-23 17:17:41 +00:00
|
|
|
context: context,
|
2024-09-26 15:47:19 +00:00
|
|
|
builder: (context) => AccountProfilePopup(
|
|
|
|
name: element.related.name,
|
|
|
|
),
|
2024-07-23 17:17:41 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
trailing: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2024-09-26 15:47:19 +00:00
|
|
|
if (element.status != 1 && element.status != 3)
|
2024-07-23 17:17:41 +00:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.check),
|
|
|
|
onPressed: () {
|
|
|
|
final RelationshipProvider provider = Get.find();
|
|
|
|
if (element.status == 0) {
|
2024-09-26 15:47:19 +00:00
|
|
|
provider
|
|
|
|
.handleRelation(element, true)
|
|
|
|
.then((_) => onUpdate());
|
2024-07-23 17:17:41 +00:00
|
|
|
} else {
|
2024-09-26 15:47:19 +00:00
|
|
|
provider
|
|
|
|
.editRelation(element.relatedId, 1)
|
|
|
|
.then((_) => onUpdate());
|
2024-07-23 17:17:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2024-09-26 15:47:19 +00:00
|
|
|
if (element.status != 2 && element.status != 3)
|
2024-07-23 17:17:41 +00:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
onPressed: () {
|
|
|
|
final RelationshipProvider provider = Get.find();
|
|
|
|
if (element.status == 0) {
|
2024-09-26 15:47:19 +00:00
|
|
|
provider
|
|
|
|
.handleRelation(element, false)
|
|
|
|
.then((_) => onUpdate());
|
2024-07-23 17:17:41 +00:00
|
|
|
} else {
|
2024-09-26 15:47:19 +00:00
|
|
|
provider
|
|
|
|
.editRelation(element.relatedId, 2)
|
|
|
|
.then((_) => onUpdate());
|
2024-07-23 17:17:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SliverList.builder(
|
|
|
|
itemCount: items.length,
|
|
|
|
itemBuilder: (context, idx) => buildItem(context, idx),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|