Bladeren bron

add initial value property in ToggleSwitchWidget for setting the initial value of toggle

ashilkn 2 jaren geleden
bovenliggende
commit
02479a9955

+ 6 - 0
lib/ui/backup_settings_screen.dart

@@ -68,6 +68,8 @@ class BackupSettingsScreen extends StatelessWidget {
                                         .shouldBackupOverMobileData(),
                                   );
                                 },
+                                initialValue: Configuration.instance
+                                    .shouldBackupOverMobileData(),
                               ),
                               borderRadius: 8,
                               alignCaptionedTextToLeft: true,
@@ -91,6 +93,8 @@ class BackupSettingsScreen extends StatelessWidget {
                                     .setShouldBackupVideos(
                                   !Configuration.instance.shouldBackupVideos(),
                                 ),
+                                initialValue:
+                                    Configuration.instance.shouldBackupVideos(),
                               ),
                               borderRadius: 8,
                               alignCaptionedTextToLeft: true,
@@ -121,6 +125,8 @@ class BackupSettingsScreen extends StatelessWidget {
                                               .shouldKeepDeviceAwake(),
                                         );
                                       },
+                                      initialValue: Configuration.instance
+                                          .shouldKeepDeviceAwake(),
                                     ),
                                     borderRadius: 8,
                                     alignCaptionedTextToLeft: true,

+ 3 - 2
lib/ui/components/toggle_switch_widget.dart

@@ -15,9 +15,11 @@ typedef FutureValueCallBack = Future<bool> Function();
 class ToggleSwitchWidget extends StatefulWidget {
   final FutureValueCallBack value;
   final OnChangedCallBack onChanged;
+  final bool initialValue;
   const ToggleSwitchWidget({
     required this.value,
     required this.onChanged,
+    required this.initialValue,
     Key? key,
   }) : super(key: key);
 
@@ -33,8 +35,7 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
   @override
   void initState() {
     futureToggleValue = widget.value.call();
-//need to assign correct intiial value of toggleValue here
-    toggleValue = true;
+    toggleValue = widget.initialValue;
     super.initState();
   }
 

+ 3 - 0
lib/ui/settings/security_section_widget.dart

@@ -69,6 +69,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
             ),
             trailingSwitch: ToggleSwitchWidget(
               value: () => UserService.instance.fetchTwoFactorStatus(),
+              initialValue: false,
               onChanged: () async {
                 final hasAuthenticated = await LocalAuthenticationService
                     .instance
@@ -108,6 +109,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
               "To enable lockscreen, please setup device passcode or screen lock in your system settings.",
             );
           },
+          initialValue: _config.shouldShowLockScreen(),
         ),
       ),
       sectionOptionSpacing,
@@ -122,6 +124,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
             trailingSwitch: ToggleSwitchWidget(
               value: () => Future.value(_config.shouldHideFromRecents()),
               onChanged: _hideFromRecentsOnChanged,
+              initialValue: _config.shouldHideFromRecents(),
             ),
           ),
           sectionOptionSpacing,