import 'package:flutter/material.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; // void main() async { // final client = StreamChatClient( // 'b4fqt99hw43q', // logLevel: Level.ALL // ); // // await client.connectUser( // User(id: '1324635'), // '''eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoibnV0c2J5In0.ECApkmJgBMAhcn90mqX67SAblSUE_CYhUuaWKey84jc''', // ); // // runApp( // chatList( // client: client, // ), // ); // } class chatList extends StatefulWidget { final StreamChatClient client; const chatList({ Key? key, required this.client, }) : super(key: key); @override State createState() => _chatListState(); } //left:user,right:admin class _chatListState extends State { @override void initState() { // TODO: implement initState super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( builder: (context, child) => StreamChat( client: widget.client, child: child, ), home: ChannelListPage( client: widget.client, ), ); } } class ChannelListPage extends StatefulWidget { const ChannelListPage({ Key? key, required this.client, }) : super(key: key); final StreamChatClient client; @override State createState() => _ChannelListPageState(); } class _ChannelListPageState extends State { late final _controller = StreamChannelListController( client: widget.client, filter: Filter.in_( 'members', [StreamChat.of(context).currentUser!.id], ), channelStateSort: const [SortOption('last_message_at')], ); @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) => Scaffold( body: SlidableAutoCloseBehavior( child: StreamChannelListView( controller: _controller, itemBuilder: (context, channels, index, tile) { final channel = channels[index]; final chatTheme = StreamChatTheme.of(context); final backgroundColor = chatTheme.colorTheme.inputBg; final canDeleteChannel = channel.ownCapabilities .contains(PermissionType.deleteChannel); return Slidable( groupTag: 'channels-actions', endActionPane: ActionPane( extentRatio: canDeleteChannel ? 0.40 : 0.20, motion: const BehindMotion(), children: [ CustomSlidableAction( onPressed: (_) { showChannelInfoModalBottomSheet( context: context, channel: channel, onViewInfoTap: () { Navigator.pop(context); // Navigate to info screen }, ); }, backgroundColor: backgroundColor, child: const Icon(Icons.more_horiz), ), if (canDeleteChannel) CustomSlidableAction( backgroundColor: backgroundColor, child: StreamSvgIcon.delete( color: chatTheme.colorTheme.accentError, ), onPressed: (_) async { final res = await showConfirmationBottomSheet( context, title: 'Delete Conversation', question: 'Are you sure you want to delete this conversation?', okText: 'Delete', cancelText: 'Cancel', icon: StreamSvgIcon.delete( color: chatTheme.colorTheme.accentError, ), ); if (res == true) { await _controller.deleteChannel(channel); } }, ), ], ), child: tile, ); }, onChannelTap: (channel) => Navigator.push( context, MaterialPageRoute( builder: (_) => StreamChannel( channel: channel, child: const ChannelPage(), ), ), ), ), ), ); } class ChannelPage extends StatelessWidget { const ChannelPage({ Key? key, }) : super(key: key); @override Widget build(BuildContext context) => Scaffold( appBar: const StreamChannelHeader(), body: Column( children: const [ Expanded( child: StreamMessageListView(), ), StreamMessageInput(), ], ), ); }