import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/dialogs/alert_dialog.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/routes/main_route/page_info.dart'; import 'package:comunic/ui/screens/conversations_list_screen.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/ui/widgets/status_widget.dart'; import 'package:comunic/ui/widgets/tab_transition_widget.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; /// Forez route /// /// @author Pierre Hubert class ForezRoute extends StatefulWidget implements MainRoute { const ForezRoute({Key key}) : super(key: key); @override State createState() => _MainRouteState(); } /// Private implementation of HomeController class _MainRouteState extends MainController { @override PageInfo get defaultPage => PageInfo( type: PageType.OTHER_PAGE, child: ForezRouteBody(), hideNavBar: true); @override Widget build(BuildContext context) { return StatusWidget( child: (c) => SafeArea( // Avoid OS areas child: WillPopScope( onWillPop: willPop, child: Scaffold( appBar: currentPage.hideNavBar ? null : AppBar(), body: SafeArea(key: currentPage.key, child: currentPage.child), ), ), ), ); } @override void openConversation(Conversation conv, {fullScreen: false}) { // Forcefully open conversations in a "normal" way (do not display groups) openConversationById(conv.id, fullScreen: fullScreen); } @override void openGroup(int groupID, {int conversationID}) { alert(context, tr("This feature is available only in the Comunic application!")); } } enum _PopupMenuItems { ACTION_SETTINGS, ACTION_SIGN_OUT } class ForezRouteBody extends StatefulWidget { @override _ForezRouteBodyState createState() => _ForezRouteBodyState(); } class _ForezRouteBodyState extends SafeState { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return DefaultTabController( length: _tabs.length, child: Scaffold( appBar: AppBar( title: Text("#Forez"), actions: [_buildPopupMenuButton()], bottom: TabBar(tabs: _tabs), ), body: TabBarView(children: _tabsPages), ), ); } Widget _buildPopupMenuButton() => PopupMenuButton<_PopupMenuItems>( itemBuilder: (c) => [ PopupMenuItem( child: Text(tr("Settings")), value: _PopupMenuItems.ACTION_SETTINGS, ), PopupMenuItem( child: Text(tr("Sign out")), value: _PopupMenuItems.ACTION_SIGN_OUT, ), ], onSelected: _onMenuSelection, ); void _onMenuSelection(_PopupMenuItems value) { switch (value) { case _PopupMenuItems.ACTION_SETTINGS: MainController.of(context).openSettings(); break; case _PopupMenuItems.ACTION_SIGN_OUT: // TODO : handle logout break; } } final _list = <_Tab>[ // Presence tab _Tab( icon: Icons.calendar_today, title: tr("Presence"), widget: Text("Presence"), ), // Conversations tab _Tab( icon: Icons.question_answer, title: tr("Conversations"), widget: ConversationsListScreen(), isUnread: (c) => StatusWidgetState.of(c).unreadConversations > 0, ), // Directory tab _Tab( icon: Icons.import_contacts, title: tr("Directory"), widget: Text("Directory"), ), ]; List get _tabs => _list .map((e) => Tab( icon: Stack( children: [ Icon(e.icon), e.isUnread?.call(context) ?? false ? Container(color: Colors.red, width: 10, height: 10) : Container(width: 0) ], ), text: e.title)) .toList(); List get _tabsPages => _list.map((e) => TabTransitionWidget(e.widget)).toList(); } class _Tab { final IconData icon; final String title; final Widget widget; final bool Function(BuildContext) isUnread; const _Tab({ @required this.icon, @required this.title, @required this.widget, this.isUnread, }) : assert(icon != null), assert(title != null), assert(widget != null); }