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.

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