feat: Dead simple account switcher

This commit is contained in:
Christian Pauly 2021-09-18 13:37:55 +02:00
parent a2d37102a4
commit 710a55ddbc
3 changed files with 21 additions and 6 deletions

View File

@ -409,6 +409,10 @@ class ChatListController extends State<ChatList> {
}
}
void setActiveClient(int i) => setState(() {
Matrix.of(context).activeClient = i;
});
@override
Widget build(BuildContext context) {
Matrix.of(context).navigatorContext = context;

View File

@ -216,6 +216,20 @@ class ChatListView extends StatelessWidget {
child: Icon(CupertinoIcons.chat_bubble),
)
: 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(),
)
: null,
drawer: controller.spaces.isEmpty
? null
: Drawer(

View File

@ -58,7 +58,7 @@ class Matrix extends StatefulWidget {
}
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
int _activeClient = 0;
int activeClient = 0;
Store store = Store();
BuildContext navigatorContext;
@ -68,14 +68,11 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
bool get isMultiAccount => widget.clients.length > 1;
set activeClient(int newActiveClient) =>
setState(() => _activeClient = newActiveClient);
int get _safeActiveClient {
if (_activeClient < 0 || _activeClient >= widget.clients.length) {
if (activeClient < 0 || activeClient >= widget.clients.length) {
return 0;
}
return _activeClient;
return activeClient;
}
Client _loginClientCandidate;