SimpleCloudNotifier/flutter/lib/nav_layout.dart

94 lines
2.8 KiB
Dart
Raw Normal View History

2024-02-10 19:57:17 +01:00
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
2024-05-21 23:20:34 +02:00
import 'package:simplecloudnotifier/components/layout/app_bar.dart';
2024-02-18 17:36:58 +01:00
import 'package:simplecloudnotifier/pages/channel_list/root.dart';
2024-02-18 16:23:10 +01:00
import 'package:simplecloudnotifier/pages/send/root.dart';
2024-02-10 19:57:17 +01:00
2024-05-21 23:20:34 +02:00
import 'components/bottom_fab/fab_bottom_app_bar.dart';
2024-02-11 01:08:51 +01:00
import 'pages/account/root.dart';
2024-02-10 19:57:17 +01:00
import 'pages/message_list/message_list.dart';
2024-02-18 17:36:58 +01:00
import 'pages/settings/root.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
static const List<Widget> _subPages = <Widget>[
2024-02-18 17:36:58 +01:00
MessageListPage(),
ChannelRootPage(),
2024-02-11 01:08:51 +01:00
AccountRootPage(),
2024-02-18 17:36:58 +01:00
SettingsRootPage(),
2024-02-18 16:23:10 +01:00
SendRootPage(),
2024-02-10 19:57:17 +01:00
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
2024-02-18 16:23:10 +01:00
void _onFABTapped() {
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-02-11 01:08:51 +01:00
body: _subPages.elementAt(_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
tooltip: 'Increment',
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'),
],
);
}
}