Use sliver shorthands

This commit is contained in:
Tommy Chow 2024-09-08 11:37:12 -07:00
parent d89980e0de
commit fbe3ee09b4
3 changed files with 137 additions and 145 deletions

View file

@ -120,48 +120,45 @@ class _ChattersListState extends State<ChattersList> {
),
)
else
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => InkWell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
child: Text(
widget.chatDetailsStore.filteredUsers
.elementAt(index),
),
SliverList.builder(
itemBuilder: (context, index) => InkWell(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
child: Text(
widget.chatDetailsStore.filteredUsers
.elementAt(index),
),
onTap: () async {
final userInfo = await context
.read<TwitchApi>()
.getUser(
headers: context
.read<AuthStore>()
.headersTwitch,
userLogin: widget
.chatDetailsStore.filteredUsers
.elementAt(index),
);
if (!context.mounted) return;
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) => ChatUserModal(
chatStore: widget.chatStore,
username: userInfo.login,
userId: userInfo.id,
displayName: userInfo.displayName,
),
);
},
),
childCount: widget
.chatDetailsStore.filteredUsers.length,
onTap: () async {
final userInfo =
await context.read<TwitchApi>().getUser(
headers: context
.read<AuthStore>()
.headersTwitch,
userLogin: widget.chatDetailsStore
.filteredUsers
.elementAt(index),
);
if (!context.mounted) return;
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) => ChatUserModal(
chatStore: widget.chatStore,
username: userInfo.login,
userId: userInfo.id,
displayName: userInfo.displayName,
),
);
},
),
itemCount: widget
.chatDetailsStore.filteredUsers.length,
),
],
);

View file

@ -29,7 +29,7 @@ class RecentEmotesPanel extends StatelessWidget {
child: AlertMessage(message: 'No recent emotes'),
)
else
SliverGrid(
SliverGrid.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
MediaQuery.of(context).orientation == Orientation.portrait
@ -38,55 +38,52 @@ class RecentEmotesPanel extends StatelessWidget {
? 6
: 16,
),
delegate: SliverChildBuilderDelegate(
(context, index) {
final emote = chatStore.assetsStore.recentEmotes[index];
final validEmotes = [
...chatStore.assetsStore.emoteToObject.values,
...chatStore.assetsStore.userEmoteToObject.values,
];
final matchingEmotes = validEmotes.where(
(existingEmote) =>
existingEmote.name == emote.name &&
existingEmote.type == emote.type,
);
itemBuilder: (context, index) {
final emote = chatStore.assetsStore.recentEmotes[index];
final validEmotes = [
...chatStore.assetsStore.emoteToObject.values,
...chatStore.assetsStore.userEmoteToObject.values,
];
final matchingEmotes = validEmotes.where(
(existingEmote) =>
existingEmote.name == emote.name &&
existingEmote.type == emote.type,
);
return InkWell(
onTap: matchingEmotes.isNotEmpty
? () => chatStore.addEmote(emote)
: null,
onLongPress: () {
HapticFeedback.lightImpact();
return InkWell(
onTap: matchingEmotes.isNotEmpty
? () => chatStore.addEmote(emote)
: null,
onLongPress: () {
HapticFeedback.lightImpact();
IRCMessage.showEmoteDetailsBottomSheet(
context,
emote: emote,
launchExternal: chatStore.settings.launchUrlExternal,
);
},
child: Padding(
padding: const EdgeInsets.all(8),
child: Center(
child: FrostyCachedNetworkImage(
imageUrl: matchingEmotes.isNotEmpty
? matchingEmotes.first.url
: emote.url,
color: matchingEmotes.isNotEmpty
? null
: const Color.fromRGBO(255, 255, 255, 0.5),
colorBlendMode: matchingEmotes.isNotEmpty
? null
: BlendMode.modulate,
height:
emote.height?.toDouble() ?? defaultEmoteSize,
width: emote.width?.toDouble(),
),
IRCMessage.showEmoteDetailsBottomSheet(
context,
emote: emote,
launchExternal: chatStore.settings.launchUrlExternal,
);
},
child: Padding(
padding: const EdgeInsets.all(8),
child: Center(
child: FrostyCachedNetworkImage(
imageUrl: matchingEmotes.isNotEmpty
? matchingEmotes.first.url
: emote.url,
color: matchingEmotes.isNotEmpty
? null
: const Color.fromRGBO(255, 255, 255, 0.5),
colorBlendMode: matchingEmotes.isNotEmpty
? null
: BlendMode.modulate,
height: emote.height?.toDouble() ?? defaultEmoteSize,
width: emote.width?.toDouble(),
),
),
);
},
childCount: chatStore.assetsStore.recentEmotes.length,
),
),
);
},
itemCount: chatStore.assetsStore.recentEmotes.length,
),
],
);

View file

@ -82,70 +82,68 @@ class _SearchResultsChannelsState extends State<SearchResultsChannels> {
.contains(channel.id),
);
return SliverList(
delegate: SliverChildListDelegate.fixed(
[
...results.map(
(channel) {
final displayName = getReadableName(
channel.displayName,
channel.broadcasterLogin,
);
return SliverList.list(
children: [
...results.map(
(channel) {
final displayName = getReadableName(
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(
return InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoChat(
userId: channel.id,
userName: channel.displayName,
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),
),
],
),
),
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),
),
],
);
}
},