Add search mode
This commit is contained in:
parent
de29800f29
commit
874374d266
|
@ -35,7 +35,9 @@ class ChatList extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChatListState extends State<ChatList> {
|
class _ChatListState extends State<ChatList> {
|
||||||
|
bool searchMode = false;
|
||||||
StreamSubscription sub;
|
StreamSubscription sub;
|
||||||
|
final TextEditingController searchController = TextEditingController();
|
||||||
|
|
||||||
Future<bool> waitForFirstSync(BuildContext context) async {
|
Future<bool> waitForFirstSync(BuildContext context) async {
|
||||||
Client client = Matrix.of(context).client;
|
Client client = Matrix.of(context).client;
|
||||||
|
@ -46,9 +48,20 @@ class _ChatListState extends State<ChatList> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
searchController.addListener(
|
||||||
|
() => setState(() => null),
|
||||||
|
);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
sub?.cancel();
|
sub?.cancel();
|
||||||
|
searchController.removeListener(
|
||||||
|
() => setState(() => null),
|
||||||
|
);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,34 +69,53 @@ class _ChatListState extends State<ChatList> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(
|
title: searchMode
|
||||||
"Conversations",
|
? TextField(
|
||||||
),
|
autofocus: true,
|
||||||
actions: <Widget>[
|
autocorrect: false,
|
||||||
IconButton(
|
controller: searchController,
|
||||||
icon: Icon(Icons.search),
|
decoration: InputDecoration(
|
||||||
onPressed: () {},
|
border: InputBorder.none,
|
||||||
),
|
hintText: "Search for a chat",
|
||||||
PopupMenuButton(
|
),
|
||||||
onSelected: (String choice) {
|
)
|
||||||
switch (choice) {
|
: Text(
|
||||||
case "settings":
|
"FluffyChat",
|
||||||
Navigator.of(context).push(
|
|
||||||
AppRoute.defaultRoute(
|
|
||||||
context,
|
|
||||||
SettingsView(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
|
||||||
const PopupMenuItem<String>(
|
|
||||||
value: "settings",
|
|
||||||
child: Text('Settings'),
|
|
||||||
),
|
),
|
||||||
],
|
leading: searchMode
|
||||||
),
|
? IconButton(
|
||||||
],
|
icon: Icon(Icons.arrow_back),
|
||||||
|
onPressed: () => setState(() => searchMode = false),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
actions: searchMode
|
||||||
|
? null
|
||||||
|
: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.search),
|
||||||
|
onPressed: () => setState(() => searchMode = true),
|
||||||
|
),
|
||||||
|
PopupMenuButton(
|
||||||
|
onSelected: (String choice) {
|
||||||
|
switch (choice) {
|
||||||
|
case "settings":
|
||||||
|
Navigator.of(context).push(
|
||||||
|
AppRoute.defaultRoute(
|
||||||
|
context,
|
||||||
|
SettingsView(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) =>
|
||||||
|
<PopupMenuEntry<String>>[
|
||||||
|
const PopupMenuItem<String>(
|
||||||
|
value: "settings",
|
||||||
|
child: Text('Settings'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: SpeedDial(
|
floatingActionButton: SpeedDial(
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
|
@ -100,7 +132,7 @@ class _ChatListState extends State<ChatList> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(Icons.chat_bubble_outline),
|
child: Icon(Icons.person_add),
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
label: 'New private chat',
|
label: 'New private chat',
|
||||||
labelStyle: TextStyle(fontSize: 18.0),
|
labelStyle: TextStyle(fontSize: 18.0),
|
||||||
|
@ -114,7 +146,29 @@ class _ChatListState extends State<ChatList> {
|
||||||
future: waitForFirstSync(context),
|
future: waitForFirstSync(context),
|
||||||
builder: (BuildContext context, snapshot) {
|
builder: (BuildContext context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
List<Room> rooms = Matrix.of(context).client.rooms;
|
List<Room> rooms = List<Room>.from(Matrix.of(context).client.rooms);
|
||||||
|
rooms.removeWhere((Room room) =>
|
||||||
|
searchMode &&
|
||||||
|
!room.displayname
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(searchController.text.toLowerCase() ?? ""));
|
||||||
|
if (rooms.isEmpty) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(
|
||||||
|
searchMode ? Icons.search : Icons.add,
|
||||||
|
size: 80,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
Text(searchMode
|
||||||
|
? "No rooms found..."
|
||||||
|
: "Start your first chat :-)"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: rooms.length,
|
itemCount: rooms.length,
|
||||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||||
|
|
Loading…
Reference in a new issue