From df86c222ff51ca71110bbe01790ed4a8e97cde3c Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Thu, 7 Oct 2021 23:12:28 -0400 Subject: [PATCH] Add settings store & video option --- lib/main.dart | 4 ++++ lib/screens/settings.dart | 19 +++++++++++++----- lib/screens/video_chat.dart | 13 +++++++++---- lib/stores/settings_store.dart | 10 ++++++++++ lib/stores/settings_store.g.dart | 33 ++++++++++++++++++++++++++++++++ pubspec.lock | 12 ++++++------ 6 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 lib/stores/settings_store.dart create mode 100644 lib/stores/settings_store.g.dart diff --git a/lib/main.dart b/lib/main.dart index 199a6258..7f253b60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:frosty/screens/home.dart'; import 'package:frosty/stores/auth_store.dart'; +import 'package:frosty/stores/settings_store.dart'; import 'package:provider/provider.dart'; void main() { @@ -15,6 +16,7 @@ class MyApp extends StatelessWidget { return MultiProvider( providers: [ Provider(create: (_) => AuthStore()), + Provider(create: (_) => SettingsStore()), ], child: Builder( builder: (context) { @@ -22,6 +24,8 @@ class MyApp extends StatelessWidget { title: 'Frosty', theme: ThemeData( primarySwatch: Colors.blue, + canvasColor: Colors.black, + cardColor: Colors.black, brightness: Brightness.dark, ), home: Scaffold( diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index d6969b21..dc87e4a3 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:frosty/stores/auth_store.dart'; +import 'package:frosty/stores/settings_store.dart'; import 'package:provider/provider.dart'; class Settings extends StatelessWidget { @@ -10,17 +11,25 @@ class Settings extends StatelessWidget { Widget build(BuildContext context) { debugPrint('settings'); final auth = context.read(); + final settings = context.watch(); return Scaffold( appBar: AppBar( title: const Text('Settings'), ), body: Observer( builder: (_) { - return Center( - child: ElevatedButton( - child: auth.isLoggedIn ? Text(auth.user!.displayName) : const Text('Login'), - onPressed: () => auth.isLoggedIn ? auth.logout() : auth.login(), - ), + return ListView( + children: [ + ElevatedButton( + child: auth.isLoggedIn ? Text(auth.user!.displayName) : const Text('Login'), + onPressed: () => auth.isLoggedIn ? auth.logout() : auth.login(), + ), + SwitchListTile( + title: const Text('Enable Video'), + value: settings.videoEnabled, + onChanged: (newValue) => settings.videoEnabled = newValue, + ), + ], ); }, ), diff --git a/lib/screens/video_chat.dart b/lib/screens/video_chat.dart index 71fc4a86..589d892e 100644 --- a/lib/screens/video_chat.dart +++ b/lib/screens/video_chat.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:frosty/models/channel.dart'; import 'package:frosty/stores/auth_store.dart'; +import 'package:frosty/stores/settings_store.dart'; import 'package:frosty/widgets/chat.dart'; import 'package:frosty/widgets/video.dart'; import 'package:provider/provider.dart'; @@ -17,13 +18,17 @@ class VideoChat extends StatelessWidget { body: SafeArea( child: Column( children: [ - AspectRatio( - aspectRatio: 16 / 9, - child: Video(channelName: channelInfo.userLogin), + Visibility( + visible: context.read().videoEnabled, + child: AspectRatio( + aspectRatio: 16 / 9, + child: Video(channelName: channelInfo.userLogin), + ), ), Expanded( child: Chat(auth: context.read(), channelInfo: channelInfo), - ) + ), + const TextField(), ], ), ), diff --git a/lib/stores/settings_store.dart b/lib/stores/settings_store.dart new file mode 100644 index 00000000..0397a113 --- /dev/null +++ b/lib/stores/settings_store.dart @@ -0,0 +1,10 @@ +import 'package:mobx/mobx.dart'; + +part 'settings_store.g.dart'; + +class SettingsStore = _SettingsStoreBase with _$SettingsStore; + +abstract class _SettingsStoreBase with Store { + @observable + bool videoEnabled = true; +} diff --git a/lib/stores/settings_store.g.dart b/lib/stores/settings_store.g.dart new file mode 100644 index 00000000..286c8dec --- /dev/null +++ b/lib/stores/settings_store.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'settings_store.dart'; + +// ************************************************************************** +// StoreGenerator +// ************************************************************************** + +// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic + +mixin _$SettingsStore on _SettingsStoreBase, Store { + final _$videoEnabledAtom = Atom(name: '_SettingsStoreBase.videoEnabled'); + + @override + bool get videoEnabled { + _$videoEnabledAtom.reportRead(); + return super.videoEnabled; + } + + @override + set videoEnabled(bool value) { + _$videoEnabledAtom.reportWrite(value, super.videoEnabled, () { + super.videoEnabled = value; + }); + } + + @override + String toString() { + return ''' +videoEnabled: ${videoEnabled} + '''; + } +} diff --git a/pubspec.lock b/pubspec.lock index 95ac6f30..2bb5c7b7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "27.0.0" + version: "28.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.5.0" args: dependency: transitive description: @@ -428,14 +428,14 @@ packages: name: mobx url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.0.5" mobx_codegen: dependency: "direct dev" description: name: mobx_codegen url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" nested: dependency: transitive description: @@ -685,7 +685,7 @@ packages: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "3.0.4" + version: "3.0.5" vector_math: dependency: transitive description: @@ -727,7 +727,7 @@ packages: name: webview_flutter_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.2.0" webview_flutter_wkwebview: dependency: transitive description: