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.

231 lines
7.2 KiB

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