frosty/lib/screens/home/search/search_results_channels.dart
Tommy Chow 9a6892746d
Update to Material 3/You and other changes/fixes (#280)
* Use adaptive refresh indicators

* Add new message count indicator in chat

* Sync pubspec.lock

* Initial migration to material 3

* Restore default bottom sheet style

* Remove FrostyListTile and reset styles

* Use "Clear" button for all search history

* Add `require_trailing_commas` lint rule

* Exclude generated files from linter

* Use ListView for safe area support in bottom sheet

* Add initial dark theme

* Make sizing and units consistent

* Update onbaording spacings & copy

* Migrate to default material 3 buttons

* Add headers to chat details bottom sheet

* Simplify token log in method

* Use bottom sheet for account options

* Remove `AnimateScale` widget

* Tweak search paddings

* Update message spacing divisions

* Upgrade packages

* Update message spacing divisions

* Regenerate splash screens

* Update Inter & add google fonts

* Add initial material 3 themes

* Use adaptive alert dialogs

* Revert to oultined inputs

* Fix tooltip message

* Revert add google_fonts

* Improve themes and various styling

* Convert categories grid to list

* Tweak stream card thumbnail radii

* Tweak settings headers

* Left align floating snackbars

* Tweak search header padding

* Fix profile pics occasionally not rounded

* Use profile pic for settings button if logged in

* Redesign sleep timer

* Use divider theme and reduce thickness

* Use 0 letter spacing for tab bar titles

* Redesign category streams list

* Add border to tooltips

* Increase category card font weight

* Use outlined icon btton for chat user modal

* Reduce profile pic radius in search results

* Fix scrolll to top button safe area

* Add support for reply threads

* Reduce tooltip and snackbar border thickness

* Rebuild reply threads on new messages

* Upgrade packages (iOS)

* Reduce font weight for all chat alerts

* Use tabbars for pageview

* Add dividers everywhere

* Revert "Add dividers everywhere"

This reverts commit 5f0d349fdb.

* Remove fill from inputs

* Add dividers to settings

* Use segmented button for settings list

* Add scrollbar to lists with scrollcontroller

* Redesign badge/emote tooltip

* Remove outline from chat user modal buttons

* Remove divider from reply thread

* Use tap for chatters list and increase font weight

* Constrain emote tooltip width
2023-10-22 18:38:32 -04:00

153 lines
5.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:frosty/constants.dart';
import 'package:frosty/models/channel.dart';
import 'package:frosty/screens/channel/channel.dart';
import 'package:frosty/screens/home/search/search_store.dart';
import 'package:frosty/widgets/alert_message.dart';
import 'package:frosty/widgets/block_report_modal.dart';
import 'package:frosty/widgets/loading_indicator.dart';
import 'package:frosty/widgets/profile_picture.dart';
import 'package:frosty/widgets/uptime.dart';
import 'package:mobx/mobx.dart';
class SearchResultsChannels extends StatefulWidget {
final SearchStore searchStore;
final String query;
const SearchResultsChannels({
Key? key,
required this.searchStore,
required this.query,
}) : super(key: key);
@override
State<SearchResultsChannels> createState() => _SearchResultsChannelsState();
}
class _SearchResultsChannelsState extends State<SearchResultsChannels> {
Future<void> _handleSearch(BuildContext context, String search) async {
try {
final channelInfo = await widget.searchStore.searchChannel(search);
if (!mounted) return;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoChat(
userId: channelInfo.broadcasterId,
userName: channelInfo.broadcasterName,
userLogin: channelInfo.broadcasterLogin,
),
),
);
} catch (error) {
final snackBar = SnackBar(
content: AlertMessage(
message: error.toString(),
centered: false,
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
@override
Widget build(BuildContext context) {
return Observer(
builder: (context) {
final future = widget.searchStore.channelFuture;
switch (future!.status) {
case FutureStatus.pending:
return const SliverToBoxAdapter(
child: LoadingIndicator(
subtitle: 'Loading channels...',
),
);
case FutureStatus.rejected:
return const SliverToBoxAdapter(
child: SizedBox(
height: 100.0,
child: AlertMessage(message: 'Failed to get channels'),
),
);
case FutureStatus.fulfilled:
final results = (future.result as List<ChannelQuery>).where(
(channel) => !widget.searchStore.authStore.user.blockedUsers
.map((blockedUser) => blockedUser.userId)
.contains(channel.id),
);
return SliverList(
delegate: SliverChildListDelegate.fixed(
[
...results.map(
(channel) {
final displayName = regexEnglish
.hasMatch(channel.displayName)
? channel.displayName
: '${channel.displayName} (${channel.broadcasterLogin})';
return InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoChat(
userId: channel.id,
userName: channel.displayName,
userLogin: channel.broadcasterLogin,
),
),
),
onLongPress: () {
HapticFeedback.lightImpact();
showModalBottomSheet(
context: context,
builder: (context) => BlockReportModal(
authStore: widget.searchStore.authStore,
name: displayName,
userLogin: channel.broadcasterLogin,
userId: channel.id,
),
);
},
child: ListTile(
title: Text(displayName),
leading: ProfilePicture(
userLogin: channel.broadcasterLogin,
radius: 16,
),
subtitle: channel.isLive
? Row(
children: [
const Icon(
Icons.circle,
color: Colors.red,
size: 10,
),
const SizedBox(width: 5),
Uptime(startTime: channel.startedAt),
],
)
: null,
),
);
},
),
ListTile(
title: Text('Go to channel "${widget.query}"'),
onTap: () => _handleSearch(context, widget.query),
trailing: const Icon(Icons.chevron_right_rounded),
),
],
),
);
}
},
);
}
}