2019-04-24 15:46:25 +00:00
|
|
|
import 'package:comunic/ui/screens/conversations_list_screen.dart';
|
2019-05-01 15:52:41 +00:00
|
|
|
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
2019-04-23 09:48:49 +00:00
|
|
|
import 'package:comunic/ui/screens/menus_screen.dart';
|
2019-05-04 18:01:17 +00:00
|
|
|
import 'package:comunic/ui/screens/newest_posts.dart';
|
2019-04-23 15:31:41 +00:00
|
|
|
import 'package:comunic/ui/tiles/custom_bottom_navigation_bar_item.dart';
|
2019-05-01 15:52:41 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
2019-04-22 17:16:26 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Main route of the application
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-04-23 09:08:38 +00:00
|
|
|
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:
|
2019-04-24 15:46:25 +00:00
|
|
|
return ConversationsListScreen();
|
2019-04-23 09:08:38 +00:00
|
|
|
|
|
|
|
case 1:
|
2019-05-04 18:01:17 +00:00
|
|
|
return NewestPostsScreen();
|
2019-05-01 15:52:41 +00:00
|
|
|
|
|
|
|
case 2:
|
2019-05-04 18:01:17 +00:00
|
|
|
return FriendsListScreen();
|
|
|
|
|
|
|
|
case 3:
|
2019-04-23 09:48:49 +00:00
|
|
|
return MenuScreen();
|
2019-04-23 09:08:38 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
throw "Invalid tab number : " + _currTab.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build navigation bar items
|
|
|
|
List<BottomNavigationBarItem> _buildNavigationBarItems() {
|
|
|
|
return <BottomNavigationBarItem>[
|
|
|
|
CustomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.chat),
|
2019-05-01 15:52:41 +00:00
|
|
|
title: Text(tr("Conversations")),
|
|
|
|
),
|
2019-05-04 18:01:17 +00:00
|
|
|
CustomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.refresh),
|
|
|
|
title: Text(tr("Newest")),
|
|
|
|
),
|
2019-05-01 15:52:41 +00:00
|
|
|
CustomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.group),
|
|
|
|
title: Text(tr("Friends")),
|
2019-04-23 09:08:38 +00:00
|
|
|
),
|
|
|
|
CustomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.menu),
|
2019-05-01 15:52:41 +00:00
|
|
|
title: Text(tr("Menu")),
|
2019-04-23 09:08:38 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-04-22 17:16:26 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-04-23 09:08:38 +00:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: _willPop,
|
|
|
|
child: Scaffold(
|
2019-05-01 09:05:05 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: _buildNavigationBarItems()[_currTab].title,
|
|
|
|
),
|
2019-04-23 09:08:38 +00:00
|
|
|
body: SafeArea(
|
|
|
|
child: _buildBody(context),
|
|
|
|
),
|
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
|
|
currentIndex: _currTab,
|
|
|
|
items: _buildNavigationBarItems(),
|
|
|
|
onTap: (i) => _onTap(i, context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2019-04-22 17:16:26 +00:00
|
|
|
}
|
2019-04-23 09:08:38 +00:00
|
|
|
}
|