Files
stream-chat-flutter/packages/stream_chat_flutter/example/lib/split_view.dart
T
Reuben TurnerandGitHub b306978da6 chore: apply linter to the various example and test directories (#550)
* chore: remove examples and tests from analysis exclusion

* chore: apply linter fixes to stream_chat_flutter_core/example/main.dart

* chore: apply linter fixes to stream_chat_flutter/example/main.dart

* chore: apply linter fixes to stream_chat_persistence/example/main.dart

* chore: apply linter fixes to stream_chat/example/main.dart

* chore: apply linter fixes to stream_chat_flutter/example/split_view.dart

* chore: renamte tutorial files per linter

* chore: apply linter fixes to tutorial_part_1.dart

* chore: apply linter fixes to tutorial_part_2.dart

* chore: apply linter fixes to tutorial_part_3.dart

* chore: apply linter fixes to tutorial_part_4.dart

* chore: apply linter fixes to tutorial_part_5.dart

* chore: make a widget const in tutorial_part_5.dart

* chore: apply linter fixes to tutorial_part_6.dart

* chore: sort and update dependencies in stream_chat_persistence/example/pubspec.yaml

* chore: sort and update dependencies in stream_chat_flutter_core/example/pubspec.yaml

* chore: sort and update dependencies in stream_chat_flutter/example/pubspec.yaml

* chore: sort dependencies in stream_chat_flutter/example/pubspec.yaml

* chore: apply linter fixes to channel_test.dart

* chore: apply linter fixes to client_test.dart

* chore: apply linter fixes to client_test.dart, stream_http_client_test.dart, and token_manager_test.dart

* chore: apply linter fixes to filter_test.dart

* chore: apply linter fixes to reaction_test.dart

* chore: apply linter fixes to chat_persistence_client_test.dart

* chore: apply linter fixes to channel_image_test.dart

* chore: apply linter fixes to deleted_message_test.dart

* chore: apply linter fixes to full_screen_media_test.dart

* chore: apply linter fixes to gallery_footer_theme_test.dart

* chore: apply linter fixes to gallery_header_theme_test.dart

* chore: apply linter fixes to message_text_test.dart

* chore: apply linter fixes to reaction_bubble_test.dart

* chore: apply linter fixes to system_message_test.dart

* chore: apply linter fixes to typing_indicator_test.dart

* chore: apply linter fixes to channel_list_core_test.dart

* chore: apply linter fixes to channels_bloc_test.dart

* chore: apply linter fixes to lazy_load_scroll_view_test.dart

* chore: apply linter fixes to channel_matcher.dart

* chore: apply linter fixes to message_matcher.dart

* chore: apply linter fixes to users_matcher.dart

* chore: apply linter fixes to message_list_core_test.dart

* chore: apply linter fixes to message_search_bloc_test.dart

* chore: apply linter fixes to message_search_list_core_test.dart

* chore: apply linter fixes to stream_channel_test.dart

* chore: apply linter fixes to stream_chat_core_test.dart

* chore: apply linter fixes to user_list_core_test.dart

* chore: apply linter fixes to channel_query_dao_test.dart, message_mapper_test.dart, user_mapper_test.dart, and users_bloc_test.dart

* chore: apply some missed dartfmt

* test: regenerate failinggolden test
2021-07-16 10:49:51 +02:00

141 lines
3.4 KiB
Dart

// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void main() async {
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
await client.connectUser(
User(id: 'super-band-9'),
'''eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A''',
);
runApp(
MyApp(
client: client,
),
);
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key,
required this.client,
}) : super(key: key);
final StreamChatClient client;
@override
Widget build(BuildContext context) => MaterialApp(
builder: (context, child) => StreamChat(
client: client,
child: child,
),
home: const SplitView(),
);
}
class SplitView extends StatefulWidget {
const SplitView({
Key? key,
}) : super(key: key);
@override
_SplitViewState createState() => _SplitViewState();
}
class _SplitViewState extends State<SplitView> {
Channel? selectedChannel;
@override
Widget build(BuildContext context) => Flex(
direction: Axis.horizontal,
children: <Widget>[
Flexible(
child: ChannelListPage(
onTap: (channel) {
setState(() {
selectedChannel = channel;
});
},
),
),
Flexible(
flex: 2,
child: Scaffold(
body: selectedChannel != null
? StreamChannel(
key: ValueKey(selectedChannel!.cid),
channel: selectedChannel!,
child: const ChannelPage(),
)
: Center(
child: Text(
'Pick a channel to show the messages 💬',
style: Theme.of(context).textTheme.headline5,
),
),
),
),
],
);
}
class ChannelListPage extends StatelessWidget {
const ChannelListPage({
Key? key,
this.onTap,
}) : super(key: key);
final void Function(Channel)? onTap;
@override
Widget build(BuildContext context) => Scaffold(
body: ChannelsBloc(
child: ChannelListView(
onChannelTap: onTap != null
? (channel, _) {
onTap!(channel);
}
: null,
filter: Filter.in_(
'members',
[StreamChat.of(context).user!.id],
),
sort: const [SortOption('last_message_at')],
pagination: const PaginationParams(
limit: 20,
),
),
),
);
}
class ChannelPage extends StatelessWidget {
const ChannelPage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) => Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => Scaffold(
appBar: const ChannelHeader(
showBackButton: false,
),
body: Column(
children: const <Widget>[
Expanded(
child: MessageListView(),
),
MessageInput(),
],
),
),
),
);
}