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.

232 lines
7.2 KiB

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