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.

156 lines
5.7 KiB

  1. import 'package:Envelope/models/conversation_users.dart';
  2. import 'package:flutter/material.dart';
  3. import '/components/custom_circle_avatar.dart';
  4. import '/models/conversations.dart';
  5. import '/models/friends.dart';
  6. import '/views/main/conversation/create_add_users.dart';
  7. class ConversationEditDetails extends StatefulWidget {
  8. final Conversation? conversation;
  9. final List<Friend>? friends;
  10. final List<ConversationUser>? users;
  11. const ConversationEditDetails({
  12. Key? key,
  13. this.conversation,
  14. this.friends,
  15. this.users,
  16. }) : super(key: key);
  17. @override
  18. State<ConversationEditDetails> createState() => _ConversationEditDetails();
  19. }
  20. class _ConversationEditDetails extends State<ConversationEditDetails> {
  21. final _formKey = GlobalKey<FormState>();
  22. List<Conversation> conversations = [];
  23. TextEditingController conversationNameController = TextEditingController();
  24. @override
  25. void initState() {
  26. if (widget.conversation != null) {
  27. conversationNameController.text = widget.conversation!.name;
  28. }
  29. super.initState();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. const TextStyle inputTextStyle = TextStyle(
  34. fontSize: 25,
  35. );
  36. final OutlineInputBorder inputBorderStyle = OutlineInputBorder(
  37. borderRadius: BorderRadius.circular(5),
  38. borderSide: const BorderSide(
  39. color: Colors.transparent,
  40. )
  41. );
  42. final ButtonStyle buttonStyle = ElevatedButton.styleFrom(
  43. padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 10),
  44. textStyle: TextStyle(
  45. fontSize: 15,
  46. fontWeight: FontWeight.bold,
  47. color: Theme.of(context).colorScheme.error,
  48. ),
  49. );
  50. return Scaffold(
  51. appBar: AppBar(
  52. elevation: 0,
  53. automaticallyImplyLeading: false,
  54. flexibleSpace: SafeArea(
  55. child: Container(
  56. padding: const EdgeInsets.only(right: 16),
  57. child: Row(
  58. children: <Widget>[
  59. IconButton(
  60. onPressed: (){
  61. Navigator.pop(context);
  62. },
  63. icon: const Icon(Icons.arrow_back),
  64. ),
  65. const SizedBox(width: 2,),
  66. Expanded(
  67. child: Column(
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. mainAxisAlignment: MainAxisAlignment.center,
  70. children: <Widget>[
  71. Text(
  72. widget.conversation != null ?
  73. widget.conversation!.name + " Settings" :
  74. 'Add Conversation',
  75. style: const TextStyle(
  76. fontSize: 16,
  77. fontWeight: FontWeight.w600
  78. ),
  79. ),
  80. ],
  81. ),
  82. ),
  83. ],
  84. ),
  85. ),
  86. ),
  87. ),
  88. body: Center(
  89. child: Padding(
  90. padding: const EdgeInsets.only(
  91. top: 50,
  92. left: 25,
  93. right: 25,
  94. ),
  95. child: Form(
  96. key: _formKey,
  97. child: Column(
  98. children: [
  99. const CustomCircleAvatar(
  100. icon: const Icon(Icons.people, size: 60),
  101. imagePath: null,
  102. radius: 50,
  103. ),
  104. const SizedBox(height: 30),
  105. TextFormField(
  106. controller: conversationNameController,
  107. textAlign: TextAlign.center,
  108. decoration: InputDecoration(
  109. hintText: 'Title',
  110. enabledBorder: inputBorderStyle,
  111. focusedBorder: inputBorderStyle,
  112. ),
  113. style: inputTextStyle,
  114. // The validator receives the text that the user has entered.
  115. validator: (value) {
  116. if (value == null || value.isEmpty) {
  117. return 'Add a title';
  118. }
  119. return null;
  120. },
  121. ),
  122. const SizedBox(height: 30),
  123. ElevatedButton(
  124. style: buttonStyle,
  125. onPressed: () {
  126. if (_formKey.currentState!.validate()) {
  127. Navigator.of(context).push(
  128. MaterialPageRoute(builder: (context) => ConversationAddFriendsList(
  129. friends: widget.friends!,
  130. title: conversationNameController.text,
  131. )
  132. )
  133. );
  134. }
  135. },
  136. child: const Text('Save'),
  137. ),
  138. ],
  139. ),
  140. ),
  141. ),
  142. ),
  143. );
  144. }
  145. }