diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 41d0475..4327952 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -35,7 +35,9 @@ class ChatList extends StatefulWidget { } class _ChatListState extends State { + bool searchMode = false; StreamSubscription sub; + final TextEditingController searchController = TextEditingController(); Future waitForFirstSync(BuildContext context) async { Client client = Matrix.of(context).client; @@ -46,9 +48,20 @@ class _ChatListState extends State { return true; } + @override + void initState() { + searchController.addListener( + () => setState(() => null), + ); + super.initState(); + } + @override void dispose() { sub?.cancel(); + searchController.removeListener( + () => setState(() => null), + ); super.dispose(); } @@ -56,34 +69,53 @@ class _ChatListState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text( - "Conversations", - ), - actions: [ - IconButton( - icon: Icon(Icons.search), - onPressed: () {}, - ), - PopupMenuButton( - onSelected: (String choice) { - switch (choice) { - case "settings": - Navigator.of(context).push( - AppRoute.defaultRoute( - context, - SettingsView(), - ), - ); - } - }, - itemBuilder: (BuildContext context) => >[ - const PopupMenuItem( - value: "settings", - child: Text('Settings'), + title: searchMode + ? TextField( + autofocus: true, + autocorrect: false, + controller: searchController, + decoration: InputDecoration( + border: InputBorder.none, + hintText: "Search for a chat", + ), + ) + : Text( + "FluffyChat", ), - ], - ), - ], + leading: searchMode + ? IconButton( + icon: Icon(Icons.arrow_back), + onPressed: () => setState(() => searchMode = false), + ) + : null, + actions: searchMode + ? null + : [ + 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) => + >[ + const PopupMenuItem( + value: "settings", + child: Text('Settings'), + ), + ], + ), + ], ), floatingActionButton: SpeedDial( child: Icon(Icons.add), @@ -100,7 +132,7 @@ class _ChatListState extends State { ), ), SpeedDialChild( - child: Icon(Icons.chat_bubble_outline), + child: Icon(Icons.person_add), backgroundColor: Colors.green, label: 'New private chat', labelStyle: TextStyle(fontSize: 18.0), @@ -114,7 +146,29 @@ class _ChatListState extends State { future: waitForFirstSync(context), builder: (BuildContext context, snapshot) { if (snapshot.hasData) { - List rooms = Matrix.of(context).client.rooms; + List rooms = List.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: [ + Icon( + searchMode ? Icons.search : Icons.add, + size: 80, + color: Colors.grey, + ), + Text(searchMode + ? "No rooms found..." + : "Start your first chat :-)"), + ], + ), + ); + } return ListView.builder( itemCount: rooms.length, itemBuilder: (BuildContext context, int i) => ChatListItem(