2024-05-25 16:11:00 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/account.dart';
|
2024-07-23 17:17:41 +00:00
|
|
|
import 'package:solian/models/relations.dart';
|
|
|
|
import 'package:solian/providers/relation.dart';
|
2024-05-25 16:11:00 +00:00
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
|
|
|
|
2024-07-23 17:17:41 +00:00
|
|
|
class RelativeSelector extends StatefulWidget {
|
2024-05-25 16:11:00 +00:00
|
|
|
final String title;
|
|
|
|
final Widget? Function(Account item)? trailingBuilder;
|
|
|
|
|
2024-07-30 12:49:01 +00:00
|
|
|
const RelativeSelector(
|
|
|
|
{super.key, required this.title, this.trailingBuilder});
|
2024-05-25 16:11:00 +00:00
|
|
|
|
|
|
|
@override
|
2024-07-23 17:17:41 +00:00
|
|
|
State<RelativeSelector> createState() => _RelativeSelectorState();
|
2024-05-25 16:11:00 +00:00
|
|
|
}
|
|
|
|
|
2024-07-23 17:17:41 +00:00
|
|
|
class _RelativeSelectorState extends State<RelativeSelector> {
|
|
|
|
final List<Relationship> _friends = List.empty(growable: true);
|
2024-05-25 16:11:00 +00:00
|
|
|
|
2024-07-30 12:49:01 +00:00
|
|
|
_getFriends() async {
|
2024-07-23 17:17:41 +00:00
|
|
|
final RelationshipProvider provider = Get.find();
|
|
|
|
final resp = await provider.listRelationWithStatus(1);
|
2024-05-25 16:11:00 +00:00
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_friends.addAll(resp.body
|
2024-07-23 17:17:41 +00:00
|
|
|
.map((e) => Relationship.fromJson(e))
|
2024-05-25 16:11:00 +00:00
|
|
|
.toList()
|
2024-07-23 17:17:41 +00:00
|
|
|
.cast<Relationship>());
|
2024-05-25 16:11:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-07-30 12:49:01 +00:00
|
|
|
_getFriends();
|
2024-05-25 16:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * 0.85,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.title,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: _friends.length,
|
|
|
|
itemBuilder: (context, index) {
|
2024-07-30 12:49:01 +00:00
|
|
|
var element = _friends[index].related;
|
2024-05-25 16:11:00 +00:00
|
|
|
return ListTile(
|
|
|
|
title: Text(element.nick),
|
|
|
|
subtitle: Text(element.name),
|
2024-10-11 16:41:03 +00:00
|
|
|
leading: AttachedCircleAvatar(content: element.avatar),
|
2024-05-25 16:11:00 +00:00
|
|
|
trailing: widget.trailingBuilder != null
|
|
|
|
? widget.trailingBuilder!(element)
|
|
|
|
: null,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context, element);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|