SimpleCloudNotifier/flutter/lib/nav_layout.dart

93 lines
2.9 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-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';
import 'package:simplecloudnotifier/pages/account/root.dart';
import 'package:simplecloudnotifier/pages/message_list/message_list.dart';
import 'package:simplecloudnotifier/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
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-05-26 18:34:42 +02:00
body: IndexedStack(
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'),
],
);
}
}