Skip to content

Commit

Permalink
switch profile circle picking to custom form
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 13, 2024
1 parent 6e563ca commit 5e5be95
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 152 deletions.
10 changes: 10 additions & 0 deletions lib/data/repositories/contacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ class ContactsRepository {
// }
}

List<(String, String, bool)> circlesWithMembership(String coagContactId) =>
circles
.map((id, label) => MapEntry(id, (
id,
label,
(circleMemberships[coagContactId] ?? []).contains(id)
)))
.values
.toList();

Future<void> saveContact(CoagContact coagContact) async {
_contacts[coagContact.coagContactId] = coagContact;
_contactsStreamController.add(coagContact);
Expand Down
55 changes: 26 additions & 29 deletions lib/ui/locations/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

import 'dart:math';

import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:collection/collection.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:formz/formz.dart';
import 'package:multi_select_flutter/multi_select_flutter.dart';

import '../../data/models/contact_location.dart';
import '../../data/repositories/contacts.dart';
Expand Down Expand Up @@ -200,32 +197,32 @@ class _LocationFormState extends State<LocationForm> {
maxLines: 6,
textInputAction: TextInputAction.next,
),
MultiSelectBottomSheetField<int>(
key: _multiSelectKey,
initialChildSize: 0.7,
maxChildSize: 0.95,
title: const Text("Circles"),
buttonText: const Text("Circles to share with"),
items: [
MultiSelectItem<int>(1, 'Circle 1'),
MultiSelectItem<int>(1, 'Circle 2')
],
searchable: true,
onConfirm: (List<int?> values) {
// setState(() {
// _selectedAnimals3 = values;
// });
// _multiSelectKey.currentState?.validate();
},
chipDisplay: MultiSelectChipDisplay(
// onTap: (item) {
// setState(() {
// _selectedAnimals3.remove(item);
// });
// _multiSelectKey.currentState.validate();
// },
),
),
// MultiSelectBottomSheetField<int>(
// key: _multiSelectKey,
// initialChildSize: 0.7,
// maxChildSize: 0.95,
// title: const Text("Circles"),
// buttonText: const Text("Circles to share with"),
// items: [
// MultiSelectItem<int>(1, 'Circle 1'),
// MultiSelectItem<int>(1, 'Circle 2')
// ],
// searchable: true,
// onConfirm: (List<int?> values) {
// // setState(() {
// // _selectedAnimals3 = values;
// // });
// // _multiSelectKey.currentState?.validate();
// },
// chipDisplay: MultiSelectChipDisplay(
// // onTap: (item) {
// // setState(() {
// // _selectedAnimals3.remove(item);
// // });
// // _multiSelectKey.currentState.validate();
// // },
// ),
// ),
const SizedBox(height: 24),
if (_state.status.isInProgress)
const CircularProgressIndicator()
Expand Down
110 changes: 52 additions & 58 deletions lib/ui/profile/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,55 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:multi_select_flutter/multi_select_flutter.dart';

import '../../data/models/contact_location.dart';
import '../../data/repositories/contacts.dart';
import '../widgets/address_coordinates_form.dart';
import '../widgets/avatar.dart';
import '../widgets/circles/cubit.dart';
import '../widgets/circles/widget.dart';
import 'cubit.dart';

Future<void> showPickCirclesBottomSheet(
{required BuildContext context,
required String label,
required Map<String, String> circles,
required List<String> selectedCircles,
required String coagContactId,
required List<(String, String, bool)> circles,
required void Function(List<String> selectedCircles) callback}) async =>
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
builder: (modalContext) => MultiSelectBottomSheet(
title: Padding(
padding: const EdgeInsets.only(left: 16, top: 12),
child: Text('Share "$label" with',
textScaler: const TextScaler.linear(1.4))),
searchable: circles.length > 10,
items: circles
.map((id, label) => MapEntry(id, MultiSelectItem(id, label)))
.values
.asList(),
initialValue: selectedCircles,
onConfirm: (values) => callback(values),
maxChildSize: 0.8,
));
builder: (modalContext) => Padding(
padding: EdgeInsets.only(
left: 16,
top: 16,
right: 16,
bottom: MediaQuery.of(modalContext).viewInsets.bottom),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
BlocProvider(
create: (context) => CirclesCubit(
context.read<ContactsRepository>(), coagContactId),
child: BlocConsumer<CirclesCubit, CirclesState>(
listener: (context, state) async {},
builder: (context, state) => CirclesForm(
customHeader: Row(children: [
Padding(
padding: const EdgeInsets.only(
left: 4, bottom: 12),
child: Text('Share "$label" with',
textScaler:
const TextScaler.linear(1.4)))
]),
allowCreateNew: false,
circles: circles,
callback: (circles) => callback(circles
.where((c) => c.$3)
.map((c) => c.$1)
.asList()))))
])));

Card _card(List<Widget> children) => Card(
color: Colors.white,
Expand Down Expand Up @@ -307,8 +325,8 @@ class ProfileView extends StatefulWidget {
ProfileViewState createState() => ProfileViewState();
}

Widget buildProfileScrollView(BuildContext context, Contact contact,
List<ContactAddressLocation> addressLocations) =>
Widget buildProfileScrollView(BuildContext context, String coagContactId,
Contact contact, List<ContactAddressLocation> addressLocations) =>
RefreshIndicator(
onRefresh: () async =>
context.read<ProfileCubit>().setContact(contact.id),
Expand All @@ -326,39 +344,29 @@ Widget buildProfileScrollView(BuildContext context, Contact contact,
(i, label) async => showPickCirclesBottomSheet(
context: context,
label: label,
coagContactId: coagContactId,
circles: context
.read<ProfileCubit>()
.contactsRepository
.circles,
selectedCircles: context
.read<ProfileCubit>()
.contactsRepository
.profileSharingSettings
.phones['$i|$label'] ??
[],
.circlesWithMembership(coagContactId),
callback: (selectedCircles) => context
.read<ProfileCubit>()
.updatePhoneSharingCircles(
.updateAddressSharingCircles(
i, label, selectedCircles))),
if (contact.emails.isNotEmpty)
emails(
contact.emails,
(i, label) async => showPickCirclesBottomSheet(
context: context,
label: label,
coagContactId: coagContactId,
circles: context
.read<ProfileCubit>()
.contactsRepository
.circles,
selectedCircles: context
.read<ProfileCubit>()
.contactsRepository
.profileSharingSettings
.emails['$i|$label'] ??
[],
.circlesWithMembership(coagContactId),
callback: (selectedCircles) => context
.read<ProfileCubit>()
.updateEmailSharingCircles(
.updateAddressSharingCircles(
i, label, selectedCircles))),
if (contact.addresses.isNotEmpty)
addressesWithForms(
Expand All @@ -368,16 +376,11 @@ Widget buildProfileScrollView(BuildContext context, Contact contact,
(i, label) async => showPickCirclesBottomSheet(
context: context,
label: label,
coagContactId: coagContactId,
circles: context
.read<ProfileCubit>()
.contactsRepository
.circles,
selectedCircles: context
.read<ProfileCubit>()
.contactsRepository
.profileSharingSettings
.addresses['$i|$label'] ??
[],
.circlesWithMembership(coagContactId),
callback: (selectedCircles) => context
.read<ProfileCubit>()
.updateAddressSharingCircles(
Expand All @@ -388,39 +391,29 @@ Widget buildProfileScrollView(BuildContext context, Contact contact,
(i, label) async => showPickCirclesBottomSheet(
context: context,
label: label,
coagContactId: coagContactId,
circles: context
.read<ProfileCubit>()
.contactsRepository
.circles,
selectedCircles: context
.read<ProfileCubit>()
.contactsRepository
.profileSharingSettings
.websites['$i|$label'] ??
[],
.circlesWithMembership(coagContactId),
callback: (selectedCircles) => context
.read<ProfileCubit>()
.updateWebsiteSharingCircles(
.updateAddressSharingCircles(
i, label, selectedCircles))),
if (contact.socialMedias.isNotEmpty)
socialMedias(
contact.socialMedias,
(i, label) async => showPickCirclesBottomSheet(
context: context,
label: label,
coagContactId: coagContactId,
circles: context
.read<ProfileCubit>()
.contactsRepository
.circles,
selectedCircles: context
.read<ProfileCubit>()
.contactsRepository
.profileSharingSettings
.socialMedias['$i|$label'] ??
[],
.circlesWithMembership(coagContactId),
callback: (selectedCircles) => context
.read<ProfileCubit>()
.updateSocialMediaSharingCircles(
.updateAddressSharingCircles(
i, label, selectedCircles))),
]))
]));
Expand Down Expand Up @@ -475,6 +468,7 @@ class ProfileViewState extends State<ProfileView> {
return Center(
child: buildProfileScrollView(
context,
state.profileContact!.coagContactId,
state.profileContact!.systemContact!,
state.profileContact!.addressLocations.values.asList()),
);
Expand Down
Loading

0 comments on commit 5e5be95

Please sign in to comment.