mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 23:09:21 +00:00
105 lines
2.5 KiB
Dart
105 lines
2.5 KiB
Dart
import 'package:comunic/ui/screens/conversations_list_screen.dart';
|
|
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
|
import 'package:comunic/ui/screens/menus_screen.dart';
|
|
import 'package:comunic/ui/tiles/custom_bottom_navigation_bar_item.dart';
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Main route of the application
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
class HomeRoute extends StatefulWidget {
|
|
@override
|
|
State<StatefulWidget> createState() => _HomeRouteState();
|
|
}
|
|
|
|
class _HomeRouteState extends State<HomeRoute> {
|
|
int _currTab = 0;
|
|
List<int> history = List();
|
|
|
|
|
|
/// Change currently visible tab
|
|
void _changeTab(int newTabNumber) {
|
|
setState(() {
|
|
_currTab = newTabNumber;
|
|
});
|
|
}
|
|
|
|
/// Allows to go to previous tab
|
|
Future<bool> _willPop() async {
|
|
if (history.length == 1) return true;
|
|
|
|
history.removeLast();
|
|
_changeTab(history[history.length - 1]);
|
|
return false;
|
|
}
|
|
|
|
/// Handles a new tab being tapped
|
|
void _onTap(int number, BuildContext context) {
|
|
if (_currTab != number) history.add(number);
|
|
_changeTab(number);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
history.add(_currTab);
|
|
}
|
|
|
|
/// Build the body of the application
|
|
Widget _buildBody(BuildContext context) {
|
|
switch (_currTab) {
|
|
case 0:
|
|
return ConversationsListScreen();
|
|
|
|
case 1:
|
|
return FriendsListScreen();
|
|
|
|
case 2:
|
|
return MenuScreen();
|
|
|
|
default:
|
|
throw "Invalid tab number : " + _currTab.toString();
|
|
}
|
|
}
|
|
|
|
/// Build navigation bar items
|
|
List<BottomNavigationBarItem> _buildNavigationBarItems() {
|
|
return <BottomNavigationBarItem>[
|
|
CustomNavigationBarItem(
|
|
icon: Icon(Icons.chat),
|
|
title: Text(tr("Conversations")),
|
|
),
|
|
CustomNavigationBarItem(
|
|
icon: Icon(Icons.group),
|
|
title: Text(tr("Friends")),
|
|
),
|
|
CustomNavigationBarItem(
|
|
icon: Icon(Icons.menu),
|
|
title: Text(tr("Menu")),
|
|
),
|
|
];
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return WillPopScope(
|
|
onWillPop: _willPop,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: _buildNavigationBarItems()[_currTab].title,
|
|
),
|
|
body: SafeArea(
|
|
child: _buildBody(context),
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _currTab,
|
|
items: _buildNavigationBarItems(),
|
|
onTap: (i) => _onTap(i, context),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|