@@ -5,6 +5,7 @@ import 'package:dropdown_button2/dropdown_button2.dart';
55import 'package:flutter/material.dart' ;
66import 'package:livekit_client/livekit_client.dart' ;
77import 'package:livekit_example/exts.dart' ;
8+ import 'package:shared_preferences/shared_preferences.dart' ;
89
910import '../theme.dart' ;
1011import 'room.dart' ;
@@ -43,6 +44,9 @@ class PreJoinPage extends StatefulWidget {
4344}
4445
4546class _PreJoinPageState extends State <PreJoinPage > {
47+ static const _prefKeyEnableVideo = 'prejoin-enable-video' ;
48+ static const _prefKeyEnableAudio = 'prejoin-enable-audio' ;
49+
4650 List <MediaDevice > _audioInputs = [];
4751 List <MediaDevice > _videoInputs = [];
4852 StreamSubscription ? _subscription;
@@ -60,8 +64,14 @@ class _PreJoinPageState extends State<PreJoinPage> {
6064 @override
6165 void initState () {
6266 super .initState ();
67+ unawaited (_initStateAsync ());
68+ }
69+
70+ Future <void > _initStateAsync () async {
71+ await _readPrefs ();
6372 _subscription = Hardware .instance.onDeviceChange.stream.listen (_loadDevices);
64- unawaited (Hardware .instance.enumerateDevices ().then (_loadDevices));
73+ final devices = await Hardware .instance.enumerateDevices ();
74+ await _loadDevices (devices);
6575 }
6676
6777 @override
@@ -70,7 +80,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
7080 super .deactivate ();
7181 }
7282
73- void _loadDevices (List <MediaDevice > devices) async {
83+ Future < void > _loadDevices (List <MediaDevice > devices) async {
7484 _audioInputs = devices.where ((d) => d.kind == 'audioinput' ).toList ();
7585 _videoInputs = devices.where ((d) => d.kind == 'videoinput' ).toList ();
7686
@@ -98,6 +108,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
98108
99109 Future <void > _setEnableVideo (value) async {
100110 _enableVideo = value;
111+ await _writePrefs ();
101112 if (! _enableVideo) {
102113 await _videoTrack? .stop ();
103114 _videoTrack = null ;
@@ -109,6 +120,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
109120
110121 Future <void > _setEnableAudio (value) async {
111122 _enableAudio = value;
123+ await _writePrefs ();
112124 if (! _enableAudio) {
113125 await _audioTrack? .stop ();
114126 _audioTrack = null ;
@@ -119,6 +131,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
119131 }
120132
121133 Future <void > _changeLocalAudioTrack () async {
134+ if (! _enableAudio) return ;
122135 if (_audioTrack != null ) {
123136 await _audioTrack! .stop ();
124137 _audioTrack = null ;
@@ -135,6 +148,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
135148 }
136149
137150 Future <void > _changeLocalVideoTrack () async {
151+ if (! _enableVideo) return ;
138152 if (_videoTrack != null ) {
139153 await _videoTrack! .stop ();
140154 _videoTrack = null ;
@@ -249,6 +263,20 @@ class _PreJoinPageState extends State<PreJoinPage> {
249263 Navigator .of (context).pop ();
250264 }
251265
266+ Future <void > _readPrefs () async {
267+ final prefs = await SharedPreferences .getInstance ();
268+ setState (() {
269+ _enableVideo = prefs.getBool (_prefKeyEnableVideo) ?? true ;
270+ _enableAudio = prefs.getBool (_prefKeyEnableAudio) ?? true ;
271+ });
272+ }
273+
274+ Future <void > _writePrefs () async {
275+ final prefs = await SharedPreferences .getInstance ();
276+ await prefs.setBool (_prefKeyEnableVideo, _enableVideo);
277+ await prefs.setBool (_prefKeyEnableAudio, _enableAudio);
278+ }
279+
252280 @override
253281 Widget build (BuildContext context) {
254282 return Scaffold (
0 commit comments