1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/routes/home_route.dart

90 lines
2.3 KiB
Dart
Raw Normal View History

2019-04-24 15:46:25 +00:00
import 'package:comunic/ui/screens/conversations_list_screen.dart';
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-07-01 09:51:23 +00:00
import 'package:comunic/ui/widgets/navbar_widget.dart';
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> {
2019-07-01 09:51:23 +00:00
BarCallbackActions _currTab = BarCallbackActions.OPEN_CONVERSATIONS;
List<BarCallbackActions> history = List();
2019-04-23 09:08:38 +00:00
/// Change currently visible tab
2019-07-01 09:51:23 +00:00
void _changeTab(BarCallbackActions newTab) {
2019-04-23 09:08:38 +00:00
setState(() {
2019-07-01 09:51:23 +00:00
_currTab = newTab;
2019-04-23 09:08:38 +00:00
});
}
/// 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
2019-07-01 09:51:23 +00:00
void _onTap(BarCallbackActions action) {
if (_currTab != action) history.add(action);
_changeTab(action);
2019-04-23 09:08:38 +00:00
}
@override
void initState() {
super.initState();
history.add(_currTab);
}
/// Build the body of the application
Widget _buildBody(BuildContext context) {
switch (_currTab) {
2019-07-01 09:51:23 +00:00
case BarCallbackActions.OPEN_CONVERSATIONS:
2019-04-24 15:46:25 +00:00
return ConversationsListScreen();
2019-04-23 09:08:38 +00:00
2019-07-01 09:51:23 +00:00
case BarCallbackActions.OPEN_NEWEST_POSTS:
2019-05-04 18:01:17 +00:00
return NewestPostsScreen();
2019-07-01 09:51:23 +00:00
case BarCallbackActions.OPEN_FRIENDS:
2019-05-04 18:01:17 +00:00
return FriendsListScreen();
2019-04-23 09:08:38 +00:00
default:
2019-07-01 09:51:23 +00:00
throw "Invalid tab : " + _currTab.toString();
2019-04-23 09:08:38 +00:00
}
}
2019-04-22 17:16:26 +00:00
@override
Widget build(BuildContext context) {
2019-07-01 09:51:23 +00:00
return Container(
color: Colors.blueAccent,
child: SafeArea(
// Avoid OS areas
child: WillPopScope(
onWillPop: _willPop,
child: Scaffold(
appBar: ComunicAppBar(
onTap: _onTap,
selectedAction: _currTab,
),
body: SafeArea(
child: _buildBody(context),
),
),
2019-04-23 09:08:38 +00:00
),
),
);
2019-04-22 17:16:26 +00:00
}
2019-04-23 09:08:38 +00:00
}