Add settings store & video option

This commit is contained in:
Tommy Chow 2021-10-07 23:12:28 -04:00
parent ed9fe3dcf8
commit df86c222ff
6 changed files with 76 additions and 15 deletions

View file

@ -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<AuthStore>(create: (_) => AuthStore()),
Provider<SettingsStore>(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(

View file

@ -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<AuthStore>();
final settings = context.watch<SettingsStore>();
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,
),
],
);
},
),

View file

@ -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<SettingsStore>().videoEnabled,
child: AspectRatio(
aspectRatio: 16 / 9,
child: Video(channelName: channelInfo.userLogin),
),
),
Expanded(
child: Chat(auth: context.read<AuthStore>(), channelInfo: channelInfo),
)
),
const TextField(),
],
),
),

View file

@ -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;
}

View file

@ -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}
''';
}
}

View file

@ -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: