2024-02-10 19:57:17 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-27 17:21:29 +02:00
|
|
|
import 'package:flutter_lazy_indexed_stack/flutter_lazy_indexed_stack.dart';
|
2024-02-10 19:57:17 +01:00
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
2024-05-27 17:21:29 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2024-05-21 23:20:34 +02:00
|
|
|
import 'package:simplecloudnotifier/components/layout/app_bar.dart';
|
2024-05-26 00:20:25 +02:00
|
|
|
import 'package:simplecloudnotifier/pages/channel_list/channel_list.dart';
|
2024-02-18 16:23:10 +01:00
|
|
|
import 'package:simplecloudnotifier/pages/send/root.dart';
|
2024-05-25 22:06:43 +02:00
|
|
|
import 'package:simplecloudnotifier/components/bottom_fab/fab_bottom_app_bar.dart';
|
2024-05-27 17:21:29 +02:00
|
|
|
import 'package:simplecloudnotifier/pages/account/account.dart';
|
2024-05-25 22:06:43 +02:00
|
|
|
import 'package:simplecloudnotifier/pages/message_list/message_list.dart';
|
|
|
|
import 'package:simplecloudnotifier/pages/settings/root.dart';
|
2024-05-27 17:21:29 +02:00
|
|
|
import 'package:simplecloudnotifier/state/user_account.dart';
|
2024-05-31 23:21:24 +02:00
|
|
|
import 'package:simplecloudnotifier/utils/toaster.dart';
|
2024-02-10 19:57:17 +01:00
|
|
|
|
|
|
|
class SCNNavLayout extends StatefulWidget {
|
|
|
|
const SCNNavLayout({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<SCNNavLayout> createState() => _SCNNavLayoutState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SCNNavLayoutState extends State<SCNNavLayout> {
|
2024-02-18 16:23:10 +01:00
|
|
|
int _selectedIndex = 0; // 4 == FAB
|
2024-02-10 19:57:17 +01:00
|
|
|
|
2024-05-27 17:21:29 +02:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
final userAcc = Provider.of<UserAccount>(context, listen: false);
|
|
|
|
if (userAcc.auth == null) _selectedIndex = 2;
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:57:17 +01:00
|
|
|
void _onItemTapped(int index) {
|
2024-05-27 17:21:29 +02:00
|
|
|
final userAcc = Provider.of<UserAccount>(context, listen: false);
|
|
|
|
if (userAcc.auth == null) {
|
2024-05-31 23:21:24 +02:00
|
|
|
Toaster.info("Not logged in", "Please login or create a new account first");
|
2024-05-27 17:21:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:57:17 +01:00
|
|
|
setState(() {
|
|
|
|
_selectedIndex = index;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-18 16:23:10 +01:00
|
|
|
void _onFABTapped() {
|
2024-05-27 17:21:29 +02:00
|
|
|
final userAcc = Provider.of<UserAccount>(context, listen: false);
|
|
|
|
if (userAcc.auth == null) {
|
2024-05-31 23:21:24 +02:00
|
|
|
Toaster.info("Not logged in", "Please login or create a new account first");
|
2024-05-27 17:21:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-10 19:57:17 +01:00
|
|
|
setState(() {
|
2024-02-18 16:23:10 +01:00
|
|
|
_selectedIndex = 4;
|
2024-02-10 19:57:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2024-05-23 17:41:51 +02:00
|
|
|
appBar: SCNAppBar(
|
|
|
|
title: null,
|
|
|
|
showDebug: true,
|
|
|
|
showSearch: _selectedIndex == 0 || _selectedIndex == 1,
|
|
|
|
showThemeSwitch: true,
|
|
|
|
),
|
2024-05-27 17:21:29 +02:00
|
|
|
body: LazyIndexedStack(
|
2024-05-26 18:34:42 +02:00
|
|
|
children: [
|
|
|
|
MessageListPage(),
|
|
|
|
ChannelRootPage(),
|
|
|
|
AccountRootPage(),
|
|
|
|
SettingsRootPage(),
|
|
|
|
SendRootPage(),
|
|
|
|
],
|
|
|
|
index: _selectedIndex,
|
|
|
|
),
|
2024-02-10 19:57:17 +01:00
|
|
|
bottomNavigationBar: _buildNavBar(context),
|
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
|
|
floatingActionButton: _buildFAB(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildFAB(BuildContext context) {
|
|
|
|
return FloatingActionButton(
|
2024-02-18 16:23:10 +01:00
|
|
|
onPressed: _onFABTapped,
|
2024-02-10 19:57:17 +01:00
|
|
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(17))),
|
|
|
|
elevation: 2.0,
|
|
|
|
child: const Icon(FontAwesomeIcons.solidPaperPlaneTop),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildNavBar(BuildContext context) {
|
|
|
|
return FABBottomAppBar(
|
2024-02-18 16:23:10 +01:00
|
|
|
selectedIndex: _selectedIndex,
|
2024-02-10 19:57:17 +01:00
|
|
|
onTabSelected: _onItemTapped,
|
2024-02-11 01:08:51 +01:00
|
|
|
color: Theme.of(context).disabledColor,
|
|
|
|
selectedColor: Theme.of(context).primaryColorDark,
|
2024-02-10 19:57:17 +01:00
|
|
|
notchedShape: const AutomaticNotchedShape(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(15),
|
|
|
|
topRight: Radius.circular(15),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(17)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
items: [
|
|
|
|
FABBottomAppBarItem(iconData: FontAwesomeIcons.solidEnvelope, text: 'Messages'),
|
|
|
|
FABBottomAppBarItem(iconData: FontAwesomeIcons.solidSnake, text: 'Channels'),
|
|
|
|
FABBottomAppBarItem(iconData: FontAwesomeIcons.solidFileUser, text: 'Account'),
|
|
|
|
FABBottomAppBarItem(iconData: FontAwesomeIcons.solidGear, text: 'Settings'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|