Files
flutter-samples/packages/stream_chat_v1/lib/pinned_messages_screen.dart
T
Salvatore Giordano 3e048711f5 align with v4
2022-04-29 15:24:35 +02:00

131 lines
4.0 KiB
Dart

import 'package:example/localizations.dart';
import 'package:example/routes/routes.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'channel_page.dart';
class PinnedMessagesScreen extends StatefulWidget {
@override
State<PinnedMessagesScreen> createState() => _PinnedMessagesScreenState();
}
class _PinnedMessagesScreenState extends State<PinnedMessagesScreen> {
late final controller = StreamMessageSearchListController(
client: StreamChat.of(context).client,
filter: Filter.in_(
'cid',
[StreamChannel.of(context).channel.cid!],
),
messageFilter: Filter.equal(
'pinned',
true,
),
sort: [
SortOption(
'created_at',
direction: SortOption.ASC,
),
],
limit: 20,
);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: StreamChatTheme.of(context).colorTheme.barsBg,
appBar: AppBar(
elevation: 1,
centerTitle: true,
title: Text(
AppLocalizations.of(context).pinnedMessages,
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.textHighEmphasis,
fontSize: 16.0,
),
),
leading: StreamBackButton(),
backgroundColor: StreamChatTheme.of(context).colorTheme.barsBg,
),
body: StreamMessageSearchListView(
controller: controller,
emptyBuilder: (_) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
StreamSvgIcon.pin(
size: 136.0,
color: StreamChatTheme.of(context).colorTheme.disabled,
),
SizedBox(height: 16.0),
Text(
AppLocalizations.of(context).noPinnedItems,
style: TextStyle(
fontSize: 17.0,
color:
StreamChatTheme.of(context).colorTheme.textHighEmphasis,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8.0),
RichText(
textAlign: TextAlign.center,
text: TextSpan(children: [
TextSpan(
text: '${AppLocalizations.of(context).longPressMessage} ',
style: TextStyle(
fontSize: 14.0,
color: StreamChatTheme.of(context)
.colorTheme
.textHighEmphasis
.withOpacity(0.5),
),
),
TextSpan(
text: AppLocalizations.of(context).pinToConversation,
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
color: StreamChatTheme.of(context)
.colorTheme
.textHighEmphasis
.withOpacity(0.5),
),
),
]),
),
],
),
);
},
onMessageTap: (messageResponse) async {
final client = StreamChat.of(context).client;
final message = messageResponse.message;
final channel = client.channel(
messageResponse.channel!.type,
id: messageResponse.channel!.id,
);
if (channel.state == null) {
await channel.watch();
}
Navigator.pushNamed(
context,
Routes.CHANNEL_PAGE,
arguments: ChannelPageArgs(
channel: channel,
initialMessage: message,
),
);
},
),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}