Fix premature disposal and state in video/chat
This commit is contained in:
parent
a7d7ccfed0
commit
7a12fb17eb
4 changed files with 77 additions and 53 deletions
|
|
@ -6,20 +6,13 @@ import 'package:frosty/screens/channel/chat/widgets/chat_message.dart';
|
|||
import 'package:frosty/screens/channel/chat/widgets/chat_user_modal.dart';
|
||||
import 'package:frosty/screens/channel/stores/chat_store.dart';
|
||||
|
||||
class Chat extends StatefulWidget {
|
||||
class Chat extends StatelessWidget {
|
||||
final ChatStore chatStore;
|
||||
|
||||
const Chat({Key? key, required this.chatStore}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ChatState createState() => _ChatState();
|
||||
}
|
||||
|
||||
class _ChatState extends State<Chat> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chatStore = widget.chatStore;
|
||||
|
||||
return Observer(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
|
|
@ -112,10 +105,4 @@ class _ChatState extends State<Chat> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.chatStore.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,52 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:frosty/core/auth/auth_store.dart';
|
||||
import 'package:frosty/screens/channel/chat/chat.dart';
|
||||
import 'package:frosty/screens/channel/stores/chat_store.dart';
|
||||
import 'package:frosty/screens/channel/stores/video_store.dart';
|
||||
import 'package:frosty/screens/channel/video/video.dart';
|
||||
import 'package:frosty/screens/settings/settings.dart';
|
||||
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class VideoChat extends StatelessWidget {
|
||||
final String title;
|
||||
final String userName;
|
||||
final String userLogin;
|
||||
class VideoChat extends StatefulWidget {
|
||||
final String displayName;
|
||||
final VideoStore videoStore;
|
||||
final ChatStore chatStore;
|
||||
|
||||
const VideoChat({
|
||||
Key? key,
|
||||
required this.title,
|
||||
required this.userName,
|
||||
required this.userLogin,
|
||||
required this.displayName,
|
||||
required this.videoStore,
|
||||
required this.chatStore,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_VideoChatState createState() => _VideoChatState();
|
||||
}
|
||||
|
||||
class _VideoChatState extends State<VideoChat> {
|
||||
final videoKey = GlobalKey();
|
||||
final chatKey = GlobalKey();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authStore = context.read<AuthStore>();
|
||||
final settingsStore = context.read<SettingsStore>();
|
||||
final videoStore = widget.videoStore;
|
||||
final chatStore = widget.chatStore;
|
||||
final settingsStore = chatStore.settings;
|
||||
|
||||
final video = Video(
|
||||
key: GlobalKey(),
|
||||
userLogin: userLogin,
|
||||
videoStore: VideoStore(
|
||||
userLogin: userLogin,
|
||||
authStore: authStore,
|
||||
settingsStore: settingsStore,
|
||||
),
|
||||
key: videoKey,
|
||||
userLogin: videoStore.userLogin,
|
||||
videoStore: videoStore,
|
||||
);
|
||||
|
||||
final chat = Chat(
|
||||
key: GlobalKey(),
|
||||
chatStore: ChatStore(
|
||||
auth: authStore,
|
||||
settings: settingsStore,
|
||||
channelName: userLogin,
|
||||
),
|
||||
key: chatKey,
|
||||
chatStore: chatStore,
|
||||
);
|
||||
|
||||
final appBar = AppBar(
|
||||
title: Text(
|
||||
userName,
|
||||
widget.displayName,
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
actions: [
|
||||
|
|
@ -58,7 +56,7 @@ class VideoChat extends StatelessWidget {
|
|||
onPressed: () => showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (_) => SizedBox(
|
||||
builder: (context) => SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.8,
|
||||
child: Settings(settingsStore: settingsStore),
|
||||
),
|
||||
|
|
@ -135,4 +133,10 @@ class VideoChat extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.chatStore.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:frosty/models/channel.dart';
|
||||
import 'package:frosty/screens/channel/stores/chat_store.dart';
|
||||
import 'package:frosty/screens/channel/stores/video_store.dart';
|
||||
import 'package:frosty/screens/channel/video_chat.dart';
|
||||
import 'package:frosty/screens/home/stores/search_store.dart';
|
||||
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
||||
import 'package:frosty/widgets/loading_indicator.dart';
|
||||
import 'package:frosty/widgets/profile_picture.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SearchResultsChannels extends StatelessWidget {
|
||||
final SearchStore searchStore;
|
||||
|
|
@ -23,10 +27,18 @@ class SearchResultsChannels extends StatelessWidget {
|
|||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => VideoChat(
|
||||
title: channelInfo!.title,
|
||||
userName: channelInfo.broadcasterName,
|
||||
userLogin: channelInfo.broadcasterLogin,
|
||||
builder: (context) => VideoChat(
|
||||
displayName: channelInfo!.broadcasterName,
|
||||
videoStore: VideoStore(
|
||||
userLogin: channelInfo.broadcasterLogin,
|
||||
authStore: searchStore.authStore,
|
||||
settingsStore: context.read<SettingsStore>(),
|
||||
),
|
||||
chatStore: ChatStore(
|
||||
channelName: channelInfo.broadcasterLogin,
|
||||
auth: searchStore.authStore,
|
||||
settings: context.read<SettingsStore>(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -84,10 +96,18 @@ class SearchResultsChannels extends StatelessWidget {
|
|||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => VideoChat(
|
||||
title: channel.title,
|
||||
userName: channel.displayName,
|
||||
userLogin: channel.broadcasterLogin,
|
||||
builder: (context) => VideoChat(
|
||||
displayName: channel.displayName,
|
||||
videoStore: VideoStore(
|
||||
userLogin: channel.broadcasterLogin,
|
||||
authStore: searchStore.authStore,
|
||||
settingsStore: context.read<SettingsStore>(),
|
||||
),
|
||||
chatStore: ChatStore(
|
||||
channelName: channel.broadcasterLogin,
|
||||
auth: searchStore.authStore,
|
||||
settings: context.read<SettingsStore>(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frosty/core/auth/auth_store.dart';
|
||||
import 'package:frosty/models/stream.dart';
|
||||
import 'package:frosty/screens/channel/stores/chat_store.dart';
|
||||
import 'package:frosty/screens/channel/stores/video_store.dart';
|
||||
import 'package:frosty/screens/channel/video_chat.dart';
|
||||
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
||||
import 'package:frosty/widgets/profile_picture.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
/// A tappable card widget that displays a stream's thumbnail and details.
|
||||
class StreamCard extends StatelessWidget {
|
||||
|
|
@ -27,10 +32,18 @@ class StreamCard extends StatelessWidget {
|
|||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => VideoChat(
|
||||
title: streamInfo.title,
|
||||
userName: streamInfo.userName,
|
||||
userLogin: streamInfo.userLogin,
|
||||
builder: (context) => VideoChat(
|
||||
displayName: streamInfo.userName,
|
||||
videoStore: VideoStore(
|
||||
userLogin: streamInfo.userLogin,
|
||||
authStore: context.read<AuthStore>(),
|
||||
settingsStore: context.read<SettingsStore>(),
|
||||
),
|
||||
chatStore: ChatStore(
|
||||
channelName: streamInfo.userLogin,
|
||||
auth: context.read<AuthStore>(),
|
||||
settings: context.read<SettingsStore>(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue