mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-04-23 02:17:51 +02:00
feat: Dead simple account switcher
This commit is contained in:
parent
a2d37102a4
commit
710a55ddbc
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user