import 'package:example/routes/routes.dart'; import 'package:example/user_mentions_page.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; import 'channel_list_page.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { int _currentIndex = 0; bool _isSelected(int index) => _currentIndex == index; List get _navBarItems { return [ BottomNavigationBarItem( icon: Stack( clipBehavior: Clip.none, children: [ StreamSvgIcon.message( color: _isSelected(0) ? StreamChatTheme.of(context).colorTheme.black : Colors.grey, ), Positioned( top: -3, right: -16, child: UnreadIndicator(), ), ], ), label: 'Chats', ), BottomNavigationBarItem( icon: Stack( clipBehavior: Clip.none, children: [ StreamSvgIcon.mentions( color: _isSelected(1) ? StreamChatTheme.of(context).colorTheme.black : Colors.grey, ), ], ), label: 'Mentions', ), ]; } @override Widget build(BuildContext context) { final user = StreamChat.of(context).user!; return Scaffold( backgroundColor: StreamChatTheme.of(context).colorTheme.whiteSnow, appBar: ChannelListHeader( onNewChatButtonTap: () { Navigator.pushNamed(context, Routes.NEW_CHAT); }, preNavigationCallback: () { FocusScope.of(context).requestFocus(FocusNode()); }, ), drawer: LeftDrawer( user: user, ), drawerEdgeDragWidth: 50, bottomNavigationBar: BottomNavigationBar( backgroundColor: StreamChatTheme.of(context).colorTheme.white, currentIndex: _currentIndex, items: _navBarItems, selectedLabelStyle: StreamChatTheme.of(context).textTheme.footnoteBold, unselectedLabelStyle: StreamChatTheme.of(context).textTheme.footnoteBold, type: BottomNavigationBarType.fixed, selectedItemColor: StreamChatTheme.of(context).colorTheme.black, unselectedItemColor: Colors.grey, onTap: (index) { setState(() => _currentIndex = index); }, ), body: IndexedStack( index: _currentIndex, children: [ ChannelListPage(), UserMentionsPage(), ], ), ); } } class LeftDrawer extends StatelessWidget { const LeftDrawer({ Key? key, required this.user, }) : super(key: key); final User user; @override Widget build(BuildContext context) { return Drawer( child: Container( color: StreamChatTheme.of(context).colorTheme.white, child: SafeArea( child: Padding( padding: EdgeInsets.only( top: MediaQuery.of(context).viewPadding.top + 8, ), child: Column( children: [ Padding( padding: const EdgeInsets.only( bottom: 20.0, left: 8, ), child: Row( children: [ UserAvatar( user: user, showOnlineStatus: false, constraints: BoxConstraints.tight(Size.fromRadius(20)), ), Padding( padding: const EdgeInsets.only(left: 16.0), child: Text( user.name, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), ), ], ), ), ListTile( leading: StreamSvgIcon.penWrite( color: StreamChatTheme.of(context) .colorTheme .black .withOpacity(.5), ), onTap: () { Navigator.popAndPushNamed( context, Routes.NEW_CHAT, ); }, title: Text( 'New direct message', style: TextStyle( fontSize: 14.5, ), ), ), ListTile( leading: StreamSvgIcon.contacts( color: StreamChatTheme.of(context) .colorTheme .black .withOpacity(.5), ), onTap: () { Navigator.popAndPushNamed( context, Routes.NEW_GROUP_CHAT, ); }, title: Text( 'New group', style: TextStyle( fontSize: 14.5, ), ), ), Expanded( child: Container( alignment: Alignment.bottomCenter, child: ListTile( onTap: () async { Navigator.pop(context); if (!kIsWeb) { final secureStorage = FlutterSecureStorage(); await secureStorage.deleteAll(); } StreamChat.of(context).client.disconnectUser(); await Navigator.pushNamedAndRemoveUntil( context, Routes.APP, ModalRoute.withName(Routes.APP), ); }, leading: StreamSvgIcon.user( color: StreamChatTheme.of(context) .colorTheme .black .withOpacity(.5), ), title: Text( 'Sign out', style: TextStyle( fontSize: 14.5, ), ), trailing: IconButton( icon: StreamSvgIcon.iconMoon( size: 24, ), color: StreamChatTheme.of(context).colorTheme.grey, onPressed: () async { final sp = await StreamingSharedPreferences.instance; sp.setInt( 'theme', Theme.of(context).brightness == Brightness.dark ? 1 : -1, ); }, ), ), ), ), ], ), ), ), ), ); } }