From 91b604a1915ababbce3a771619e8851c9f0cb241 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sun, 3 Apr 2022 00:18:28 +0900 Subject: [PATCH] adaptiveStream and dynacast option in example --- example/lib/pages/connect.dart | 58 ++++++++++++++++++++++++++++++---- example/lib/theme.dart | 23 ++++++++------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index ec8709b..cb954ac 100644 --- a/example/lib/pages/connect.dart +++ b/example/lib/pages/connect.dart @@ -23,10 +23,14 @@ class _ConnectPageState extends State { static const _storeKeyUri = 'uri'; static const _storeKeyToken = 'token'; static const _storeKeySimulcast = 'simulcast'; + static const _storeKeyAdaptiveStream = 'adaptive-stream'; + static const _storeKeyDynacast = 'dynacast'; final _uriCtrl = TextEditingController(); final _tokenCtrl = TextEditingController(); bool _simulcast = true; + bool _adaptiveStream = true; + bool _dynacast = true; bool _busy = false; @override @@ -49,6 +53,8 @@ class _ConnectPageState extends State { _tokenCtrl.text = prefs.getString(_storeKeyToken) ?? ''; setState(() { _simulcast = prefs.getBool(_storeKeySimulcast) ?? true; + _adaptiveStream = prefs.getBool(_storeKeyAdaptiveStream) ?? true; + _dynacast = prefs.getBool(_storeKeyDynacast) ?? true; }); } @@ -58,6 +64,8 @@ class _ConnectPageState extends State { await prefs.setString(_storeKeyUri, _uriCtrl.text); await prefs.setString(_storeKeyToken, _tokenCtrl.text); await prefs.setBool(_storeKeySimulcast, _simulcast); + await prefs.setBool(_storeKeyAdaptiveStream, _adaptiveStream); + await prefs.setBool(_storeKeyDynacast, _dynacast); } Future _connect(BuildContext ctx) async { @@ -79,8 +87,8 @@ class _ConnectPageState extends State { _uriCtrl.text, _tokenCtrl.text, roomOptions: RoomOptions( - adaptiveStream: true, - dynacast: true, + adaptiveStream: _adaptiveStream, + dynacast: _dynacast, defaultVideoPublishOptions: VideoPublishOptions( simulcast: _simulcast, ), @@ -108,6 +116,20 @@ class _ConnectPageState extends State { }); } + void _setAdaptiveStream(bool? value) async { + if (value == null || _adaptiveStream == value) return; + setState(() { + _adaptiveStream = value; + }); + } + + void _setDynacast(bool? value) async { + if (value == null || _dynacast == value) return; + setState(() { + _dynacast = value; + }); + } + @override Widget build(BuildContext context) => Scaffold( body: Container( @@ -144,7 +166,7 @@ class _ConnectPageState extends State { ), ), Padding( - padding: const EdgeInsets.only(bottom: 50), + padding: const EdgeInsets.only(bottom: 5), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -152,10 +174,32 @@ class _ConnectPageState extends State { Switch( value: _simulcast, onChanged: (value) => _setSimulcast(value), - inactiveTrackColor: Colors.white.withOpacity(.2), - activeTrackColor: LKColors.lkBlue, - inactiveThumbColor: Colors.white.withOpacity(.5), - activeColor: Colors.white, + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 5), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text('Adaptive Stream'), + Switch( + value: _adaptiveStream, + onChanged: (value) => _setAdaptiveStream(value), + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 25), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text('Dynacast'), + Switch( + value: _dynacast, + onChanged: (value) => _setDynacast(value), ), ], ), diff --git a/example/lib/theme.dart b/example/lib/theme.dart index 4ab4865..74f3b3c 100644 --- a/example/lib/theme.dart +++ b/example/lib/theme.dart @@ -57,15 +57,20 @@ class LiveKitTheme { checkColor: MaterialStateProperty.all(Colors.white), fillColor: MaterialStateProperty.all(accentColor), ), - // switchTheme: SwitchThemeData( - // trackColor: MaterialStateProperty.resolveWith((states) { - // print('states: $states'); - // if (states.contains(MaterialState.disabled)) { - // return Colors.red; - // } - // return accentColor; - // }), - // ), + switchTheme: SwitchThemeData( + trackColor: MaterialStateProperty.resolveWith((states) { + if (states.contains(MaterialState.selected)) { + return accentColor; + } + return accentColor.withOpacity(0.3); + }), + thumbColor: MaterialStateProperty.resolveWith((states) { + if (states.contains(MaterialState.selected)) { + return Colors.white; + } + return Colors.white.withOpacity(0.3); + }), + ), dialogTheme: DialogTheme( backgroundColor: cardColor, shape: RoundedRectangleBorder(