veilidchat/lib/components/contact_invitation_list_widget.dart

82 lines
2.9 KiB
Dart
Raw Normal View History

2023-08-05 01:00:46 -04:00
import 'package:awesome_extensions/awesome_extensions.dart';
2023-08-04 01:00:38 -04:00
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
2023-09-30 21:11:06 -04:00
import 'package:flutter/foundation.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
2023-09-26 18:46:02 -04:00
import '../proto/proto.dart' as proto;
2023-08-04 01:00:38 -04:00
import '../tools/tools.dart';
import 'contact_invitation_item_widget.dart';
2023-08-05 01:00:46 -04:00
class ContactInvitationListWidget extends ConsumerStatefulWidget {
2023-09-26 18:46:02 -04:00
const ContactInvitationListWidget({
2023-08-05 01:00:46 -04:00
required this.contactInvitationRecordList,
super.key,
});
2023-08-04 01:00:38 -04:00
final IList<proto.ContactInvitationRecord> contactInvitationRecordList;
2023-08-05 01:00:46 -04:00
@override
ContactInvitationListWidgetState createState() =>
ContactInvitationListWidgetState();
2023-09-29 22:45:50 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
2023-09-30 21:11:06 -04:00
properties.add(IterableProperty<proto.ContactInvitationRecord>(
'contactInvitationRecordList', contactInvitationRecordList));
2023-09-29 22:45:50 -04:00
}
2023-08-05 01:00:46 -04:00
}
class ContactInvitationListWidgetState
extends ConsumerState<ContactInvitationListWidget> {
final ScrollController _scrollController = ScrollController();
2023-08-04 01:00:38 -04:00
@override
// ignore: prefer_expression_function_bodies
2023-08-05 01:00:46 -04:00
Widget build(BuildContext context) {
2023-08-04 01:00:38 -04:00
final theme = Theme.of(context);
2023-08-05 01:00:46 -04:00
//final textTheme = theme.textTheme;
final scale = theme.extension<ScaleScheme>()!;
2023-08-04 01:00:38 -04:00
return Container(
2023-08-05 01:00:46 -04:00
width: double.infinity,
2023-09-24 15:30:54 -04:00
margin: const EdgeInsets.fromLTRB(4, 0, 4, 4),
2023-09-23 12:56:54 -04:00
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
2023-09-24 15:30:54 -04:00
borderRadius: BorderRadius.circular(16),
)),
2023-09-23 12:56:54 -04:00
constraints: const BoxConstraints(maxHeight: 200),
2023-10-14 15:47:02 -04:00
child: Container(
width: double.infinity,
decoration: ShapeDecoration(
color: scale.primaryScale.subtleBackground,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
)),
child: ListView.builder(
controller: _scrollController,
itemCount: widget.contactInvitationRecordList.length,
itemBuilder: (context, index) {
if (index < 0 ||
index >= widget.contactInvitationRecordList.length) {
return null;
}
return ContactInvitationItemWidget(
contactInvitationRecord:
widget.contactInvitationRecordList[index],
key: ObjectKey(widget.contactInvitationRecordList[index]))
.paddingLTRB(4, 2, 4, 2);
},
findChildIndexCallback: (key) {
final index = widget.contactInvitationRecordList.indexOf(
(key as ObjectKey).value! as proto.ContactInvitationRecord);
if (index == -1) {
return null;
}
return index;
},
).paddingLTRB(4, 6, 4, 6)),
2023-08-04 01:00:38 -04:00
);
}
}