add_partipant_page.dart 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/core/configuration.dart';
  3. import 'package:photos/models/collection.dart';
  4. import 'package:photos/services/collections_service.dart';
  5. import 'package:photos/services/update_service.dart';
  6. import 'package:photos/theme/ente_theme.dart';
  7. import 'package:photos/ui/common/gradient_button.dart';
  8. import 'package:photos/ui/components/captioned_text_widget.dart';
  9. import 'package:photos/ui/components/divider_widget.dart';
  10. import 'package:photos/ui/components/menu_item_widget.dart';
  11. import 'package:photos/ui/components/menu_section_description_widget.dart';
  12. import 'package:photos/ui/components/menu_section_title.dart';
  13. import 'package:photos/ui/sharing/user_avator_widget.dart';
  14. import 'package:photos/utils/toast_util.dart';
  15. class AddParticipantPage extends StatefulWidget {
  16. const AddParticipantPage({super.key});
  17. @override
  18. State<StatefulWidget> createState() => _AddParticipantPage();
  19. }
  20. class _AddParticipantPage extends State<AddParticipantPage> {
  21. late bool selectAsViewer;
  22. String selectedEmail = '';
  23. bool hideListOfEmails = false;
  24. @override
  25. void initState() {
  26. selectAsViewer = true;
  27. super.initState();
  28. }
  29. Widget build(BuildContext context) {
  30. final enteColorScheme = getEnteColorScheme(context);
  31. final enteTextTheme = getEnteTextTheme(context);
  32. final int ownerID = Configuration.instance.getUserID()!;
  33. final List<String> emails = [];
  34. for (final c in CollectionsService.instance.getActiveCollections()) {
  35. if (c.owner?.id == ownerID) {
  36. c.sharees?.forEach((e) => emails.add(e!.email));
  37. } else {
  38. emails.add(c.owner!.email);
  39. }
  40. }
  41. final List<String> finalList = emails.toSet().toList();
  42. hideListOfEmails = finalList.isEmpty;
  43. finalList.sort();
  44. return Scaffold(
  45. appBar: AppBar(
  46. title: const Text("Add people"),
  47. ),
  48. body: Container(
  49. color: enteColorScheme.backgroundElevated,
  50. child: Padding(
  51. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  52. child: Column(
  53. mainAxisAlignment: MainAxisAlignment.start,
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: [
  56. const SizedBox(height: 12),
  57. Text(
  58. "Add a new email",
  59. style: enteTextTheme.body,
  60. ),
  61. hideListOfEmails
  62. ? const Expanded(child: SizedBox())
  63. : Expanded(
  64. child: Column(
  65. children: [
  66. const SizedBox(height: 24),
  67. const MenuSectionTitle(
  68. title: "or pick an existing one",
  69. ),
  70. Expanded(
  71. child: ListView.builder(
  72. itemBuilder: (context, index) {
  73. final currentEmail = finalList[index];
  74. return Column(
  75. children: [
  76. MenuItemWidget(
  77. captionedTextWidget: CaptionedTextWidget(
  78. title: finalList[index],
  79. ),
  80. leadingIconSize: 24.0,
  81. leadingIconWidget: UserAvatarWidget(
  82. User(
  83. id: currentEmail.hashCode,
  84. email: currentEmail,
  85. ),
  86. type: AvatarType.mini,
  87. ),
  88. menuItemColor:
  89. getEnteColorScheme(context).fillFaint,
  90. pressedColor:
  91. getEnteColorScheme(context).fillFaint,
  92. trailingIcon:
  93. (selectedEmail == finalList[index])
  94. ? Icons.check
  95. : null,
  96. onTap: () async {
  97. if (selectedEmail == finalList[index]) {
  98. selectedEmail = '';
  99. } else {
  100. selectedEmail = finalList[index];
  101. }
  102. setState(() => {});
  103. // showShortToast(context, "yet to implement");
  104. },
  105. isTopBorderRadiusRemoved: index > 0,
  106. isBottomBorderRadiusRemoved:
  107. index < (finalList.length - 1),
  108. ),
  109. (index == (finalList.length - 1))
  110. ? const SizedBox.shrink()
  111. : DividerWidget(
  112. dividerType: DividerType.menu,
  113. bgColor: getEnteColorScheme(context)
  114. .blurStrokeFaint,
  115. ),
  116. ],
  117. );
  118. },
  119. itemCount: finalList.length,
  120. // physics: const ClampingScrollPhysics(),
  121. ),
  122. ),
  123. ],
  124. ),
  125. ),
  126. const DividerWidget(
  127. dividerType: DividerType.solid,
  128. ),
  129. SafeArea(
  130. child: Padding(
  131. padding: const EdgeInsets.only(top: 8, bottom: 8),
  132. child: Column(
  133. crossAxisAlignment: CrossAxisAlignment.start,
  134. children: [
  135. const MenuSectionTitle(title: "Add as"),
  136. MenuItemWidget(
  137. captionedTextWidget: const CaptionedTextWidget(
  138. title: "Collaborator",
  139. ),
  140. leadingIcon: Icons.edit,
  141. menuItemColor: getEnteColorScheme(context).fillFaint,
  142. pressedColor: getEnteColorScheme(context).fillFaint,
  143. trailingIcon: !selectAsViewer ? Icons.check : null,
  144. onTap: () async {
  145. showShortToast(context, "coming soon!");
  146. setState(() => {selectAsViewer = false});
  147. },
  148. isBottomBorderRadiusRemoved: true,
  149. ),
  150. DividerWidget(
  151. dividerType: DividerType.menu,
  152. bgColor: getEnteColorScheme(context).blurStrokeFaint,
  153. ),
  154. MenuItemWidget(
  155. captionedTextWidget: const CaptionedTextWidget(
  156. title: " Viewer",
  157. ),
  158. leadingIcon: Icons.photo,
  159. menuItemColor: getEnteColorScheme(context).fillFaint,
  160. pressedColor: getEnteColorScheme(context).fillFaint,
  161. trailingIcon: selectAsViewer ? Icons.check : null,
  162. onTap: () async {
  163. setState(() => {selectAsViewer = true});
  164. // showShortToast(context, "yet to implement");
  165. },
  166. isTopBorderRadiusRemoved: true,
  167. ),
  168. const MenuSectionDescriptionWidget(
  169. content:
  170. "Collaborators can add photos and videos to the shared album.",
  171. ),
  172. const SizedBox(height: 12),
  173. SizedBox(
  174. width: double.infinity,
  175. child: GradientButton(
  176. onTap: selectedEmail == ''
  177. ? null
  178. : () async {
  179. await UpdateService.instance.hideChangeLog();
  180. Navigator.of(context).pop();
  181. },
  182. text: selectAsViewer
  183. ? "Add viewer"
  184. : "Add collaborator",
  185. ),
  186. ),
  187. const SizedBox(height: 8),
  188. ],
  189. ),
  190. ),
  191. ),
  192. ],
  193. ),
  194. ),
  195. ),
  196. );
  197. }
  198. }