Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
7.7 KiB

  1. import 'package:Envelope/components/custom_circle_avatar.dart';
  2. import 'package:Envelope/views/main/conversation/edit_details.dart';
  3. import 'package:flutter/material.dart';
  4. import '/models/conversation_users.dart';
  5. import '/models/conversations.dart';
  6. import '/models/my_profile.dart';
  7. import '/views/main/conversation/settings_user_list_item.dart';
  8. class ConversationSettings extends StatefulWidget {
  9. final Conversation conversation;
  10. const ConversationSettings({
  11. Key? key,
  12. required this.conversation,
  13. }) : super(key: key);
  14. @override
  15. State<ConversationSettings> createState() => _ConversationSettingsState();
  16. }
  17. class _ConversationSettingsState extends State<ConversationSettings> {
  18. List<ConversationUser> users = [];
  19. MyProfile? profile;
  20. TextEditingController nameController = TextEditingController();
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. appBar: AppBar(
  25. elevation: 0,
  26. automaticallyImplyLeading: false,
  27. flexibleSpace: SafeArea(
  28. child: Container(
  29. padding: const EdgeInsets.only(right: 16),
  30. child: Row(
  31. children: <Widget>[
  32. IconButton(
  33. onPressed: (){
  34. Navigator.pop(context);
  35. },
  36. icon: const Icon(Icons.arrow_back),
  37. ),
  38. const SizedBox(width: 2,),
  39. Expanded(
  40. child: Column(
  41. crossAxisAlignment: CrossAxisAlignment.start,
  42. mainAxisAlignment: MainAxisAlignment.center,
  43. children: <Widget>[
  44. Text(
  45. widget.conversation.name + " Settings",
  46. style: const TextStyle(
  47. fontSize: 16,
  48. fontWeight: FontWeight.w600
  49. ),
  50. ),
  51. ],
  52. ),
  53. ),
  54. ],
  55. ),
  56. ),
  57. ),
  58. ),
  59. body: Padding(
  60. padding: const EdgeInsets.all(15),
  61. child: Column(
  62. children: <Widget> [
  63. const SizedBox(height: 30),
  64. conversationName(),
  65. const SizedBox(height: 25),
  66. widget.conversation.admin ?
  67. sectionTitle('Settings') :
  68. const SizedBox.shrink(),
  69. widget.conversation.admin ?
  70. settings() :
  71. const SizedBox.shrink(),
  72. widget.conversation.admin ?
  73. const SizedBox(height: 25) :
  74. const SizedBox.shrink(),
  75. sectionTitle('Members'),
  76. usersList(),
  77. const SizedBox(height: 25),
  78. myAccess(),
  79. ],
  80. ),
  81. ),
  82. );
  83. }
  84. Widget conversationName() {
  85. return Row(
  86. children: <Widget> [
  87. const CustomCircleAvatar(
  88. icon: Icon(Icons.people, size: 40),
  89. imagePath: null, // TODO: Add image here
  90. radius: 30,
  91. ),
  92. const SizedBox(width: 10),
  93. Text(
  94. widget.conversation.name,
  95. style: const TextStyle(
  96. fontSize: 25,
  97. fontWeight: FontWeight.w500,
  98. ),
  99. ),
  100. widget.conversation.admin ? IconButton(
  101. iconSize: 20,
  102. icon: const Icon(Icons.edit),
  103. padding: const EdgeInsets.all(5.0),
  104. splashRadius: 25,
  105. onPressed: () {
  106. Navigator.of(context).push(
  107. MaterialPageRoute(builder: (context) => ConversationEditDetails(
  108. users: users,
  109. conversation: widget.conversation,
  110. friends: null,
  111. )),
  112. ).then(onGoBack);
  113. },
  114. ) : const SizedBox.shrink(),
  115. ],
  116. );
  117. }
  118. Future<void> getUsers() async {
  119. users = await getConversationUsers(widget.conversation);
  120. profile = await MyProfile.getProfile();
  121. setState(() {});
  122. }
  123. @override
  124. void initState() {
  125. nameController.text = widget.conversation.name;
  126. super.initState();
  127. getUsers();
  128. }
  129. Widget myAccess() {
  130. return Align(
  131. alignment: Alignment.centerLeft,
  132. child: Column(
  133. crossAxisAlignment: CrossAxisAlignment.stretch,
  134. children: [
  135. TextButton.icon(
  136. label: const Text(
  137. 'Leave Conversation',
  138. style: TextStyle(fontSize: 16)
  139. ),
  140. icon: const Icon(Icons.exit_to_app),
  141. style: const ButtonStyle(
  142. alignment: Alignment.centerLeft,
  143. ),
  144. onPressed: () {
  145. print('Leave Group');
  146. }
  147. ),
  148. ],
  149. ),
  150. );
  151. }
  152. Widget sectionTitle(String title) {
  153. return Align(
  154. alignment: Alignment.centerLeft,
  155. child: Container(
  156. padding: const EdgeInsets.only(left: 12),
  157. child: Text(
  158. title,
  159. style: const TextStyle(fontSize: 20),
  160. ),
  161. ),
  162. );
  163. }
  164. Widget settings() {
  165. return Align(
  166. alignment: Alignment.centerLeft,
  167. child: Column(
  168. crossAxisAlignment: CrossAxisAlignment.stretch,
  169. children: [
  170. const SizedBox(height: 5),
  171. TextButton.icon(
  172. label: const Text(
  173. 'Disappearing Messages',
  174. style: TextStyle(fontSize: 16)
  175. ),
  176. icon: const Icon(Icons.timer),
  177. style: ButtonStyle(
  178. alignment: Alignment.centerLeft,
  179. foregroundColor: MaterialStateProperty.resolveWith<Color>(
  180. (Set<MaterialState> states) {
  181. return Theme.of(context).colorScheme.onBackground;
  182. },
  183. )
  184. ),
  185. onPressed: () {
  186. print('Disappearing Messages');
  187. }
  188. ),
  189. TextButton.icon(
  190. label: const Text(
  191. 'Permissions',
  192. style: TextStyle(fontSize: 16)
  193. ),
  194. icon: const Icon(Icons.lock),
  195. style: ButtonStyle(
  196. alignment: Alignment.centerLeft,
  197. foregroundColor: MaterialStateProperty.resolveWith<Color>(
  198. (Set<MaterialState> states) {
  199. return Theme.of(context).colorScheme.onBackground;
  200. },
  201. )
  202. ),
  203. onPressed: () {
  204. print('Permissions');
  205. }
  206. ),
  207. ],
  208. ),
  209. );
  210. }
  211. Widget usersList() {
  212. return ListView.builder(
  213. itemCount: users.length,
  214. shrinkWrap: true,
  215. padding: const EdgeInsets.only(top: 5, bottom: 0),
  216. itemBuilder: (context, i) {
  217. return ConversationSettingsUserListItem(
  218. user: users[i],
  219. isAdmin: widget.conversation.admin,
  220. profile: profile!, // TODO: Fix this
  221. );
  222. }
  223. );
  224. }
  225. onGoBack(dynamic value) async {
  226. nameController.text = widget.conversation.name;
  227. super.initState();
  228. getUsers();
  229. setState(() {});
  230. }
  231. }