From b4849b7c2dfce46146054e6d9f0c2edc6ba86b49 Mon Sep 17 00:00:00 2001 From: Sudharshan Date: Sat, 22 Jun 2019 21:55:32 +0800 Subject: [PATCH] feat: added selectable contact support --- .../ui/conversation_tab/conversation_tab.dart | 4 + .../widgets/new_conversation_view.dart | 28 ++-- .../widgets/new_group_view.dart | 141 ++++++++++++++++++ 3 files changed, 161 insertions(+), 12 deletions(-) diff --git a/lib/src/ui/conversation_tab/conversation_tab.dart b/lib/src/ui/conversation_tab/conversation_tab.dart index 11ed6e6..fd31f7d 100644 --- a/lib/src/ui/conversation_tab/conversation_tab.dart +++ b/lib/src/ui/conversation_tab/conversation_tab.dart @@ -2,6 +2,7 @@ import "package:flutter/material.dart"; import "./widgets/home_view.dart"; import "./widgets/new_conversation_view.dart"; +import "./widgets/new_group_view.dart"; class ConversationTab extends StatefulWidget { @override @@ -24,6 +25,9 @@ class _ConversationTabState extends State { case "conversation/new": builder = (BuildContext _) => NewConversationView(); break; + case "conversation/group/new": + builder = (BuildContext _) => NewGroupView(); + break; default: throw Exception("Invalid route: ${settings.name}"); } diff --git a/lib/src/ui/conversation_tab/widgets/new_conversation_view.dart b/lib/src/ui/conversation_tab/widgets/new_conversation_view.dart index 14b99e5..edc3b97 100644 --- a/lib/src/ui/conversation_tab/widgets/new_conversation_view.dart +++ b/lib/src/ui/conversation_tab/widgets/new_conversation_view.dart @@ -41,7 +41,6 @@ class _NewConversationViewState extends State { Navigator.pop(context); }), Spacer(), - SmallTextButton(text: "Next", onClickCallback: () {}) ]), Expanded( child: StreamBuilder( @@ -130,17 +129,22 @@ class _NewConversationViewState extends State { child: Column(mainAxisSize: MainAxisSize.min, children: [ SearchInput( controller: searchController, hintText: "Search for people"), - Padding( - padding: EdgeInsets.only(top: 10.0, bottom: 10.0), - child: Row(children: [ - Icon(Icons.group_add, - color: Theme.of(context).primaryColorDark, size: 30.0), - Padding( - padding: EdgeInsets.only(left: 20.0), - child: Text("New Group", - style: Theme.of(context).textTheme.title.copyWith( - color: Theme.of(context).primaryColorDark))), - ])), + GestureDetector( + onTap: () { + Navigator.pushNamed(context, "conversation/group/new"); + }, + child: Padding( + padding: EdgeInsets.only(top: 10.0, bottom: 10.0), + child: Row(children: [ + Icon(Icons.group_add, + color: Theme.of(context).primaryColorDark, + size: 30.0), + Padding( + padding: EdgeInsets.only(left: 20.0), + child: Text("New Group", + style: Theme.of(context).textTheme.title.copyWith( + color: Theme.of(context).primaryColorDark))), + ]))), ])), ]); diff --git a/lib/src/ui/conversation_tab/widgets/new_group_view.dart b/lib/src/ui/conversation_tab/widgets/new_group_view.dart index e69de29..2d3a564 100644 --- a/lib/src/ui/conversation_tab/widgets/new_group_view.dart +++ b/lib/src/ui/conversation_tab/widgets/new_group_view.dart @@ -0,0 +1,141 @@ +import "package:flutter/material.dart"; +import 'package:sticky_headers/sticky_headers.dart'; + +import "../../../models/user_model.dart"; +import "../../../blocs/contact_bloc.dart"; + +import "../../widgets/contact_item.dart"; +import "../../widgets/top_bar.dart"; +import "../../widgets/search_input.dart"; +import "../../widgets/small_text_button.dart"; + +class NewGroupView extends StatefulWidget { + @override + State createState() { + return _NewGroupViewState(); + } +} + +class _NewGroupViewState extends State { + final searchController = TextEditingController(); + + @override + void initState() { + super.initState(); + contactBloc.fetchContacts(); + } + + @override + void dispose() { + searchController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Column(children: [ + TopBar(title: "New Group", children: [ + IconButton( + icon: Icon(Icons.arrow_back), + onPressed: () { + Navigator.pop(context); + }), + Spacer(), + SmallTextButton(text: "Next", onClickCallback: () {}) + ]), + Expanded( + child: StreamBuilder( + stream: contactBloc.contacts, + builder: (context, AsyncSnapshot> snapshot) { + if (snapshot.hasData) { + return buildList(snapshot); + } else if (snapshot.hasError) { + return Text(snapshot.error.toString()); + } + return Center(child: CircularProgressIndicator()); + })) + ]); + } + + Widget buildList(AsyncSnapshot> snapshot) { + final Map> sortedList = { + "A": null, + "B": null, + "C": null, + "D": null, + "E": null, + "F": null, + "G": null, + "H": null, + "I": null, + "J": null, + "K": null, + "L": null, + "M": null, + "N": null, + "O": null, + "P": null, + "Q": null, + "R": null, + "S": null, + "T": null, + "U": null, + "V": null, + "W": null, + "X": null, + "Y": null, + "Z": null + }; + + // Sort the list into alphabets + sortedList.forEach((letter, list) { + sortedList[letter] = snapshot.data + .where((user) => user.firstName.startsWith(letter)) + .toList(); + }); + + // Create list of children + final children = sortedList.entries.map((entry) { + if (entry.value.length == 0) { + return Container(); + } + + return Column(mainAxisSize: MainAxisSize.min, children: [ + StickyHeader( + header: Container( + height: 21.0, + color: Colors.grey[200], + padding: EdgeInsets.symmetric(horizontal: 15.0), + alignment: Alignment.centerLeft, + child: Text(entry.key, + style: Theme.of(context) + .primaryTextTheme + .display1 + .copyWith(color: Theme.of(context).primaryColorDark)), + ), + content: ListView.builder( + physics: const NeverScrollableScrollPhysics(), + padding: EdgeInsets.only(top: 0.0), + shrinkWrap: true, + itemCount: entry.value.length, + itemBuilder: (context, index) { + return ContactItem( + user: entry.value[index], + selectable: true, + onClickCallback: (state) {}); + })) + ]); + }).toList(); + + children.insertAll(0, [ + Padding( + padding: EdgeInsets.only(left: 15.0, right: 15.0), + child: Column(mainAxisSize: MainAxisSize.min, children: [ + SearchInput( + controller: searchController, hintText: "Search for people"), + ])), + ]); + + return ListView(padding: EdgeInsets.only(top: 10.0), children: children); + } +}