feat: added selectable contact support
parent
6bc3b4ad85
commit
b4849b7c2d
|
@ -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<ConversationTab> {
|
|||
case "conversation/new":
|
||||
builder = (BuildContext _) => NewConversationView();
|
||||
break;
|
||||
case "conversation/group/new":
|
||||
builder = (BuildContext _) => NewGroupView();
|
||||
break;
|
||||
default:
|
||||
throw Exception("Invalid route: ${settings.name}");
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ class _NewConversationViewState extends State<NewConversationView> {
|
|||
Navigator.pop(context);
|
||||
}),
|
||||
Spacer(),
|
||||
SmallTextButton(text: "Next", onClickCallback: () {})
|
||||
]),
|
||||
Expanded(
|
||||
child: StreamBuilder(
|
||||
|
@ -130,17 +129,22 @@ class _NewConversationViewState extends State<NewConversationView> {
|
|||
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
SearchInput(
|
||||
controller: searchController, hintText: "Search for people"),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
||||
child: Row(children: <Widget>[
|
||||
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: <Widget>[
|
||||
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))),
|
||||
]))),
|
||||
])),
|
||||
]);
|
||||
|
||||
|
|
|
@ -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<StatefulWidget> createState() {
|
||||
return _NewGroupViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _NewGroupViewState extends State<NewGroupView> {
|
||||
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: <Widget>[
|
||||
TopBar(title: "New Group", children: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
Spacer(),
|
||||
SmallTextButton(text: "Next", onClickCallback: () {})
|
||||
]),
|
||||
Expanded(
|
||||
child: StreamBuilder(
|
||||
stream: contactBloc.contacts,
|
||||
builder: (context, AsyncSnapshot<List<User>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return buildList(snapshot);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}))
|
||||
]);
|
||||
}
|
||||
|
||||
Widget buildList(AsyncSnapshot<List<User>> snapshot) {
|
||||
final Map<String, List<User>> 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<Widget>((entry) {
|
||||
if (entry.value.length == 0) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||
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: <Widget>[
|
||||
SearchInput(
|
||||
controller: searchController, hintText: "Search for people"),
|
||||
])),
|
||||
]);
|
||||
|
||||
return ListView(padding: EdgeInsets.only(top: 10.0), children: children);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue