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.

133 lines
4.7 KiB

  1. import 'package:flutter/material.dart';
  2. import '/models/conversations.dart';
  3. import '/views/main/conversation_list_item.dart';
  4. class ConversationList extends StatefulWidget {
  5. final List<Conversation> conversations;
  6. const ConversationList({
  7. Key? key,
  8. required this.conversations,
  9. }) : super(key: key);
  10. @override
  11. State<ConversationList> createState() => _ConversationListState();
  12. }
  13. class _ConversationListState extends State<ConversationList> {
  14. List<Conversation> conversations = [];
  15. @override
  16. void initState() {
  17. super.initState();
  18. conversations.addAll(widget.conversations);
  19. setState(() {});
  20. }
  21. void filterSearchResults(String query) {
  22. List<Conversation> dummySearchList = [];
  23. dummySearchList.addAll(widget.conversations);
  24. if(query.isNotEmpty) {
  25. List<Conversation> dummyListData = [];
  26. dummySearchList.forEach((item) {
  27. if (item.name.toLowerCase().contains(query)) {
  28. dummyListData.add(item);
  29. }
  30. });
  31. setState(() {
  32. conversations.clear();
  33. conversations.addAll(dummyListData);
  34. });
  35. return;
  36. }
  37. setState(() {
  38. conversations.clear();
  39. conversations.addAll(widget.conversations);
  40. });
  41. }
  42. Widget list() {
  43. if (conversations.isEmpty) {
  44. return const Center(
  45. child: Text('No Conversations'),
  46. );
  47. }
  48. return ListView.builder(
  49. itemCount: conversations.length,
  50. shrinkWrap: true,
  51. padding: const EdgeInsets.only(top: 16),
  52. physics: const NeverScrollableScrollPhysics(),
  53. itemBuilder: (context, i) {
  54. return ConversationListItem(
  55. conversation: conversations[i],
  56. );
  57. },
  58. );
  59. }
  60. @override
  61. Widget build(BuildContext context) {
  62. return Scaffold(
  63. body: SingleChildScrollView(
  64. physics: const BouncingScrollPhysics(),
  65. child: Column(
  66. crossAxisAlignment: CrossAxisAlignment.start,
  67. children: <Widget>[
  68. SafeArea(
  69. child: Padding(
  70. padding: const EdgeInsets.only(left: 16,right: 16,top: 10),
  71. child: Row(
  72. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  73. children: <Widget>[
  74. const Text("Conversations",style: TextStyle(fontSize: 32,fontWeight: FontWeight.bold),),
  75. Container(
  76. padding: const EdgeInsets.only(left: 8,right: 8,top: 2,bottom: 2),
  77. height: 30,
  78. decoration: BoxDecoration(
  79. borderRadius: BorderRadius.circular(30),
  80. color: Colors.pink[50],
  81. ),
  82. child: Row(
  83. children: const <Widget>[
  84. Icon(Icons.add,color: Colors.pink,size: 20,),
  85. SizedBox(width: 2,),
  86. Text("Add",style: TextStyle(fontSize: 14,fontWeight: FontWeight.bold),),
  87. ],
  88. ),
  89. )
  90. ],
  91. ),
  92. ),
  93. ),
  94. Padding(
  95. padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
  96. child: TextField(
  97. decoration: InputDecoration(
  98. hintText: "Search...",
  99. hintStyle: TextStyle(color: Colors.grey.shade600),
  100. prefixIcon: Icon(Icons.search,color: Colors.grey.shade600, size: 20,),
  101. filled: true,
  102. fillColor: Colors.grey.shade100,
  103. contentPadding: const EdgeInsets.all(8),
  104. enabledBorder: OutlineInputBorder(
  105. borderRadius: BorderRadius.circular(20),
  106. borderSide: BorderSide(
  107. color: Colors.grey.shade100
  108. )
  109. ),
  110. ),
  111. onChanged: (value) => filterSearchResults(value.toLowerCase())
  112. ),
  113. ),
  114. Padding(
  115. padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
  116. child: list(),
  117. ),
  118. ],
  119. ),
  120. ),
  121. );
  122. }
  123. }