|
|
- import 'package:Envelope/models/friends.dart';
- import 'package:Envelope/views/main/conversation_edit_details.dart';
- import 'package:flutter/material.dart';
- import '/models/conversations.dart';
- import '/views/main/conversation_list_item.dart';
-
- class ConversationList extends StatefulWidget {
- final List<Conversation> conversations;
- final List<Friend> friends;
- const ConversationList({
- Key? key,
- required this.conversations,
- required this.friends,
- }) : super(key: key);
-
- @override
- State<ConversationList> createState() => _ConversationListState();
- }
-
- class _ConversationListState extends State<ConversationList> {
- List<Conversation> conversations = [];
- List<Friend> friends = [];
-
- @override
- void initState() {
- super.initState();
- conversations.addAll(widget.conversations);
- friends.addAll(widget.friends);
- setState(() {});
- }
-
- void filterSearchResults(String query) {
- List<Conversation> dummySearchList = [];
- dummySearchList.addAll(widget.conversations);
-
- if(query.isNotEmpty) {
- List<Conversation> dummyListData = [];
- dummySearchList.forEach((item) {
- if (item.name.toLowerCase().contains(query)) {
- dummyListData.add(item);
- }
- });
- setState(() {
- conversations.clear();
- conversations.addAll(dummyListData);
- });
- return;
- }
-
- setState(() {
- conversations.clear();
- conversations.addAll(widget.conversations);
- });
- }
-
- Widget list() {
- if (conversations.isEmpty) {
- return const Center(
- child: Text('No Conversations'),
- );
- }
-
- return ListView.builder(
- itemCount: conversations.length,
- shrinkWrap: true,
- padding: const EdgeInsets.only(top: 16),
- physics: const NeverScrollableScrollPhysics(),
- itemBuilder: (context, i) {
- return ConversationListItem(
- conversation: conversations[i],
- );
- },
- );
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: SingleChildScrollView(
- physics: const BouncingScrollPhysics(),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- SafeArea(
- child: Padding(
- padding: const EdgeInsets.only(left: 16,right: 16,top: 10),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: const <Widget>[
- Text(
- 'Conversations',
- style: TextStyle(
- fontSize: 32,
- fontWeight: FontWeight.bold
- )
- ),
- ],
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
- child: TextField(
- decoration: const InputDecoration(
- hintText: "Search...",
- prefixIcon: Icon(
- Icons.search,
- size: 20
- ),
- ),
- onChanged: (value) => filterSearchResults(value.toLowerCase())
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
- child: list(),
- ),
- ],
- ),
- ),
- floatingActionButton: Padding(
- padding: const EdgeInsets.only(right: 10, bottom: 10),
- child: FloatingActionButton(
- onPressed: () {
- Navigator.of(context).push(
- MaterialPageRoute(builder: (context) => ConversationEditDetails(
- friends: friends,
- )),
- ).then(onGoBack);
- },
- backgroundColor: Theme.of(context).colorScheme.primary,
- child: const Icon(Icons.add, size: 30),
- ),
- ),
- );
- }
-
- onGoBack(dynamic value) {
- setState(() {});
- }
- }
|