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.

148 lines
5.3 KiB

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