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.

110 lines
5.9 KiB

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