98 lines
2.7 KiB
Dart
98 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:localization/localization.dart';
|
|
import 'package:loris/dialogues/makepost.dart';
|
|
import 'package:loris/pages/chat/chat.dart';
|
|
import 'package:loris/pages/notifications/notifications.dart';
|
|
import 'package:loris/pages/timeline/timeline.dart';
|
|
import 'package:loris/pages/settings/settings.dart';
|
|
import '../business_logic/websocket.dart' as websocket;
|
|
|
|
class MainScaffold extends StatefulWidget {
|
|
const MainScaffold({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<MainScaffold> createState() => _MainScaffoldState();
|
|
}
|
|
|
|
class _MainScaffoldState extends State<MainScaffold> {
|
|
int index = 0;
|
|
int unreadNotifs = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
notifStream.stream.listen((event) {
|
|
if (index != 2) {
|
|
if (mounted) {
|
|
setState(() {
|
|
unreadNotifs = event;
|
|
});
|
|
}
|
|
}
|
|
});
|
|
websocket.reloadWebsockets();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final screens = [
|
|
const Timeline(),
|
|
chat(context),
|
|
const Notifications(),
|
|
settings(context),
|
|
];
|
|
final buttons = [
|
|
FloatingActionButton(
|
|
child: const Icon(Icons.create),
|
|
onPressed: () => showDialog(
|
|
context: context,
|
|
builder: (context) => const MakePost(),
|
|
),
|
|
),
|
|
FloatingActionButton(
|
|
onPressed: () {},
|
|
child: const Icon(Icons.person_add),
|
|
),
|
|
null,
|
|
null,
|
|
];
|
|
return Scaffold(
|
|
extendBody: true,
|
|
body: IndexedStack(
|
|
index: index,
|
|
children: screens,
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
floatingActionButton: buttons[index],
|
|
bottomNavigationBar: BottomAppBar(
|
|
child: NavigationBar(
|
|
onDestinationSelected: (index) => setState(() {
|
|
this.index = index;
|
|
if (index == 2) {
|
|
unreadNotifs = 0;
|
|
}
|
|
}),
|
|
selectedIndex: index,
|
|
destinations: [
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.forum), label: "timeline".i18n()),
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.chat), label: "chat".i18n()),
|
|
NavigationDestination(
|
|
icon: Icon((unreadNotifs >= 1)
|
|
? Icons.notifications_active
|
|
: Icons.notifications),
|
|
label: "notifications".i18n()),
|
|
NavigationDestination(
|
|
icon: const Icon(Icons.settings), label: "settings".i18n()),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|