loris/lib/partials/main_scaffold.dart

98 lines
2.7 KiB
Dart
Raw Normal View History

2022-06-16 20:30:02 +00:00
import 'package:flutter/material.dart';
2022-07-03 13:47:24 +00:00
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';
2022-08-15 13:08:37 +00:00
import '../business_logic/websocket.dart' as websocket;
2022-06-16 20:30:02 +00:00
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;
});
}
}
});
super.initState();
}
2022-06-16 20:30:02 +00:00
2022-08-22 11:32:40 +00:00
@override
void dispose() {
super.dispose();
}
2022-06-16 20:30:02 +00:00
@override
Widget build(BuildContext context) {
2022-08-15 13:08:37 +00:00
websocket.reloadWebsockets();
2022-07-02 22:03:10 +00:00
final screens = [
2022-08-15 18:31:44 +00:00
const Timeline(),
2022-07-02 22:03:10 +00:00
chat(context),
2022-08-15 18:31:44 +00:00
const Notifications(),
2022-07-02 22:03:10 +00:00
settings(context),
];
final buttons = [
FloatingActionButton(
2022-07-03 20:02:57 +00:00
child: const Icon(Icons.create),
2022-07-03 14:56:41 +00:00
onPressed: () => showDialog(
context: context,
builder: (context) => const MakePost(),
),
2022-07-02 22:03:10 +00:00
),
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.person_add),
),
2022-08-22 11:32:40 +00:00
null,
2022-07-02 22:03:10 +00:00
null,
];
2022-06-16 20:30:02 +00:00
return Scaffold(
2022-07-02 22:03:10 +00:00
extendBody: true,
2022-08-10 16:47:34 +00:00
body: IndexedStack(
index: index,
children: screens,
),
2022-07-02 22:03:10 +00:00
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: buttons[index],
bottomNavigationBar: BottomAppBar(
child: NavigationBar(
onDestinationSelected: (index) => setState(() {
this.index = index;
if (index == 2) {
unreadNotifs = 0;
}
}),
2022-07-02 22:03:10 +00:00
selectedIndex: index,
2022-07-03 13:47:24 +00:00
destinations: [
2022-07-02 22:03:10 +00:00
NavigationDestination(
2022-07-03 13:47:24 +00:00
icon: const Icon(Icons.forum), label: "timeline".i18n()),
2022-07-02 22:03:10 +00:00
NavigationDestination(
2022-07-03 13:47:24 +00:00
icon: const Icon(Icons.chat), label: "chat".i18n()),
NavigationDestination(
icon: Icon((unreadNotifs >= 1)
? Icons.notifications_active
: Icons.notifications),
2022-07-03 13:47:24 +00:00
label: "notifications".i18n()),
NavigationDestination(
icon: const Icon(Icons.settings), label: "settings".i18n()),
2022-07-02 22:03:10 +00:00
]),
),
2022-06-16 20:30:02 +00:00
);
}
}