feat: Nicer bottombar

This commit is contained in:
Christian Pauly 2021-09-18 15:15:50 +02:00
parent a973f8d371
commit d619fefa62
2 changed files with 60 additions and 13 deletions

View File

@ -412,7 +412,8 @@ class ChatListController extends State<ChatList> {
void setActiveClient(int i) => setState(() {
_activeSpaceId = null;
selectedRoomIds.clear();
Matrix.of(context).activeClient = i;
Matrix.of(context).activeClient =
i - (Matrix.of(context).hasComplexBundles ? 1 : 0);
});
@override

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/pages/chat_list.dart';
@ -17,6 +19,43 @@ class ChatListView extends StatelessWidget {
const ChatListView(this.controller, {Key key}) : super(key: key);
List<BottomNavigationBarItem> getBottomBarItems(BuildContext context) {
final items = Matrix.of(context)
.widget
.clients
.map((client) => BottomNavigationBarItem(
label: client.userID,
icon: FutureBuilder<Profile>(
future: client.ownProfile,
builder: (context, snapshot) {
return Avatar(
snapshot.data?.avatarUrl,
snapshot.data?.displayName ?? client.userID.localpart,
size: 32,
);
}),
))
.toList();
if (Matrix.of(context).hasComplexBundles) {
items.insert(
0,
BottomNavigationBarItem(
label: 'Bundles',
icon: PopupMenuButton(
icon: Icon(
Icons.menu,
color: Theme.of(context).textTheme.bodyText1.color,
),
itemBuilder: (_) => [
PopupMenuItem(child: Text('Arbeit')),
PopupMenuItem(child: Text('Privat')),
],
)));
}
return items;
}
@override
Widget build(BuildContext context) {
return StreamBuilder<Object>(
@ -217,17 +256,24 @@ class ChatListView extends StatelessWidget {
)
: null,
bottomNavigationBar: Matrix.of(context).isMultiAccount
? BottomNavigationBar(
onTap: controller.setActiveClient,
currentIndex: Matrix.of(context).activeClient,
items: Matrix.of(context)
.widget
.clients
.map((client) => BottomNavigationBarItem(
label: client.userID,
icon: Icon(Icons.account_box_outlined),
))
.toList(),
? SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: max(
MediaQuery.of(context).size.width,
Matrix.of(context).widget.clients.length * 84.0,
),
child: BottomNavigationBar(
onTap: controller.setActiveClient,
currentIndex: Matrix.of(context).activeClient +
(Matrix.of(context).hasComplexBundles ? 1 : 0),
showUnselectedLabels: false,
showSelectedLabels: true,
type: BottomNavigationBarType.shifting,
selectedItemColor: Theme.of(context).primaryColor,
items: getBottomBarItems(context),
),
),
)
: null,
drawer: controller.spaces.isEmpty
@ -235,7 +281,7 @@ class ChatListView extends StatelessWidget {
: Drawer(
child: SafeArea(
child: ListView.builder(
itemCount: controller.spaces.length + 1,
itemCount: controller.spaces.length,
itemBuilder: (context, i) {
if (i == 0) {
return ListTile(