2023-01-18 05:34:54 -05:00
|
|
|
import 'dart:io';
|
2023-10-22 18:38:32 -04:00
|
|
|
import 'dart:ui';
|
2023-01-18 05:34:54 -05:00
|
|
|
|
2021-08-20 21:18:51 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-01 00:10:50 -04:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2023-01-18 05:34:54 -05:00
|
|
|
import 'package:frosty/screens/channel/chat/emote_menu/emote_menu_panel.dart';
|
|
|
|
|
import 'package:frosty/screens/channel/chat/emote_menu/recent_emotes_panel.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:frosty/screens/channel/chat/stores/chat_store.dart';
|
2022-01-10 12:26:43 -05:00
|
|
|
import 'package:frosty/screens/channel/chat/widgets/chat_bottom_bar.dart';
|
|
|
|
|
import 'package:frosty/screens/channel/chat/widgets/chat_message.dart';
|
2023-01-18 05:34:54 -05:00
|
|
|
import 'package:frosty/widgets/page_view.dart';
|
2021-09-03 02:14:17 -04:00
|
|
|
|
2022-01-10 17:34:01 -05:00
|
|
|
class Chat extends StatelessWidget {
|
2021-10-09 03:49:12 -04:00
|
|
|
final ChatStore chatStore;
|
2021-08-21 22:59:30 -04:00
|
|
|
|
2021-10-10 00:10:58 -04:00
|
|
|
const Chat({Key? key, required this.chatStore}) : super(key: key);
|
2021-08-20 21:18:51 -04:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2021-12-15 03:07:29 -05:00
|
|
|
return Observer(
|
2022-04-08 22:50:40 -04:00
|
|
|
builder: (context) {
|
2022-08-05 22:53:24 -04:00
|
|
|
return Column(
|
2022-04-08 22:50:40 -04:00
|
|
|
children: [
|
2022-08-05 22:53:24 -04:00
|
|
|
Expanded(
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
if (chatStore.assetsStore.showEmoteMenu) {
|
|
|
|
|
chatStore.assetsStore.showEmoteMenu = false;
|
|
|
|
|
} else if (chatStore.textFieldFocusNode.hasFocus) {
|
|
|
|
|
chatStore.textFieldFocusNode.unfocus();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Stack(
|
|
|
|
|
alignment: AlignmentDirectional.bottomCenter,
|
|
|
|
|
children: [
|
|
|
|
|
MediaQuery(
|
2023-04-29 11:34:28 -04:00
|
|
|
data: MediaQuery.of(context).copyWith(
|
2023-10-22 18:38:32 -04:00
|
|
|
textScaleFactor: chatStore.settings.messageScale,
|
|
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
child: DefaultTextStyle(
|
2023-04-29 11:34:28 -04:00
|
|
|
style: DefaultTextStyle.of(context)
|
|
|
|
|
.style
|
|
|
|
|
.copyWith(fontSize: chatStore.settings.fontSize),
|
2023-10-22 18:38:32 -04:00
|
|
|
child: Scrollbar(
|
|
|
|
|
controller: chatStore.scrollController,
|
|
|
|
|
child: Observer(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
reverse: true,
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
addAutomaticKeepAlives: false,
|
|
|
|
|
controller: chatStore.scrollController,
|
|
|
|
|
itemCount: chatStore.renderMessages.length,
|
|
|
|
|
itemBuilder: (context, index) => ChatMessage(
|
|
|
|
|
ircMessage: chatStore.renderMessages.reversed
|
|
|
|
|
.toList()[index],
|
|
|
|
|
chatStore: chatStore,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2022-04-08 22:50:40 -04:00
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
2023-10-22 18:38:32 -04:00
|
|
|
padding: const EdgeInsets.all(4),
|
2022-08-05 22:53:24 -04:00
|
|
|
child: Observer(
|
|
|
|
|
builder: (_) => AnimatedSwitcher(
|
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2023-01-18 05:34:54 -05:00
|
|
|
switchInCurve: Curves.easeOut,
|
|
|
|
|
switchOutCurve: Curves.easeIn,
|
2022-08-05 22:53:24 -04:00
|
|
|
child: chatStore.autoScroll
|
|
|
|
|
? null
|
2023-10-22 18:38:32 -04:00
|
|
|
: ElevatedButton.icon(
|
2022-08-05 22:53:24 -04:00
|
|
|
onPressed: chatStore.resumeScroll,
|
2023-10-22 18:38:32 -04:00
|
|
|
icon:
|
|
|
|
|
const Icon(Icons.arrow_downward_rounded),
|
|
|
|
|
label: Text(
|
|
|
|
|
chatStore.messageBuffer.isNotEmpty
|
|
|
|
|
? '${chatStore.messageBuffer.length} new ${chatStore.messageBuffer.length == 1 ? 'message' : 'messages'}'
|
|
|
|
|
: 'Resume scroll',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontFeatures: [
|
|
|
|
|
FontFeature.tabularFigures(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
),
|
2022-06-27 23:23:09 -04:00
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
),
|
2022-01-19 23:08:28 -05:00
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
],
|
2022-04-08 22:50:40 -04:00
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
),
|
2021-12-13 02:19:06 -05:00
|
|
|
),
|
2023-04-29 11:34:28 -04:00
|
|
|
if (chatStore.settings.showBottomBar)
|
|
|
|
|
ChatBottomBar(chatStore: chatStore),
|
2023-01-18 05:34:54 -05:00
|
|
|
WillPopScope(
|
|
|
|
|
onWillPop: Platform.isAndroid
|
|
|
|
|
? () async {
|
|
|
|
|
// If pressing the back button on Android while the emote menu is open, close it instead of going back to the streams list.
|
|
|
|
|
if (chatStore.assetsStore.showEmoteMenu) {
|
|
|
|
|
chatStore.assetsStore.showEmoteMenu = false;
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
: null,
|
|
|
|
|
child: AnimatedContainer(
|
2022-08-05 22:53:24 -04:00
|
|
|
curve: Curves.ease,
|
|
|
|
|
duration: const Duration(milliseconds: 200),
|
2023-01-18 05:34:54 -05:00
|
|
|
height: chatStore.assetsStore.showEmoteMenu
|
|
|
|
|
? MediaQuery.of(context).size.height /
|
2023-04-29 11:34:28 -04:00
|
|
|
(MediaQuery.of(context).orientation ==
|
|
|
|
|
Orientation.portrait
|
|
|
|
|
? 3
|
|
|
|
|
: 2)
|
2023-01-18 05:34:54 -05:00
|
|
|
: 0,
|
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
|
switchInCurve: Curves.easeOut,
|
|
|
|
|
switchOutCurve: Curves.easeIn,
|
|
|
|
|
child: chatStore.assetsStore.showEmoteMenu
|
2023-10-22 18:38:32 -04:00
|
|
|
? Column(
|
2023-01-18 05:34:54 -05:00
|
|
|
children: [
|
2023-10-22 18:38:32 -04:00
|
|
|
const Divider(),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: FrostyPageView(
|
|
|
|
|
headers: const [
|
|
|
|
|
'Recent',
|
|
|
|
|
'Twitch',
|
|
|
|
|
'7TV',
|
|
|
|
|
'BTTV',
|
|
|
|
|
'FFZ',
|
|
|
|
|
],
|
|
|
|
|
children: [
|
|
|
|
|
RecentEmotesPanel(
|
|
|
|
|
chatStore: chatStore,
|
|
|
|
|
),
|
|
|
|
|
EmoteMenuPanel(
|
|
|
|
|
chatStore: chatStore,
|
|
|
|
|
twitchEmotes: chatStore
|
|
|
|
|
.assetsStore.userEmoteSectionToEmotes,
|
|
|
|
|
),
|
|
|
|
|
...[
|
|
|
|
|
chatStore.assetsStore.sevenTVEmotes,
|
|
|
|
|
chatStore.assetsStore.bttvEmotes,
|
|
|
|
|
chatStore.assetsStore.ffzEmotes,
|
|
|
|
|
].map(
|
|
|
|
|
(emotes) => EmoteMenuPanel(
|
|
|
|
|
chatStore: chatStore,
|
|
|
|
|
emotes: emotes,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2023-01-18 05:34:54 -05:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
2022-08-05 22:53:24 -04:00
|
|
|
),
|
2022-06-25 22:50:16 -04:00
|
|
|
),
|
2022-04-08 22:50:40 -04:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
2021-08-20 21:18:51 -04:00
|
|
|
);
|
|
|
|
|
}
|
2021-08-26 16:37:37 -04:00
|
|
|
}
|