Skip to content

Commit

Permalink
Merge pull request #792 from gjwgit/kev/761_dataset_keep_rows_settings
Browse files Browse the repository at this point in the history
Kev/761_dataset_keep_rows_settings
  • Loading branch information
gjwgit authored Jan 14, 2025
2 parents fe6010c + b19f316 commit cc0d918
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 32 deletions.
2 changes: 2 additions & 0 deletions lib/providers/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ final stripCommentsProvider = StateProvider<bool>((ref) => false);
// Settings provider for the session control.

final askOnExitProvider = StateProvider<bool>((ref) => true);

final ignoreMissingTargetProvider = StateProvider<bool>((ref) => true);
92 changes: 74 additions & 18 deletions lib/settings/widgets/section_dataset_toggles.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Dataset toggles section.
/// Dataset section.
//
// Time-stamp: <Monday 2025-01-06 15:20:25 +1100 Graham Williams>
//
Expand Down Expand Up @@ -29,6 +29,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:markdown_tooltip/markdown_tooltip.dart';
import 'package:rattle/settings/widgets/section_partition.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:rattle/constants/spacing.dart';
Expand All @@ -49,6 +50,7 @@ class DatasetToggles extends ConsumerWidget {
final partition = ref.watch(partitionProvider);
final keepInSync = ref.watch(keepInSyncProvider);
final useValidation = ref.watch(useValidationSettingProvider);
final ignoreMissingTarget = ref.watch(ignoreMissingTargetProvider);

Future<void> _saveToggleStates() async {
final prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -97,30 +99,14 @@ class DatasetToggles extends ConsumerWidget {
''',
child: const Text(
'Dataset Toggles',
'Dataset',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),

configRowGap,

// Reset Dataset Toggles to default button.

MarkdownTooltip(
message: '''
**Reset Toggles:** Tap here to reset the Dataset Toggles
setting to the default for Rattle.
''',
child: ElevatedButton(
onPressed: _resetToggleStates,
child: const Text('Reset'),
),
),
],
),

Expand All @@ -131,6 +117,17 @@ class DatasetToggles extends ConsumerWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Toggles section.

const Text(
'Toggles',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),

configRowGap,

Expanded(
child: ToggleRow(
label: 'Cleanse',
Expand Down Expand Up @@ -235,9 +232,68 @@ class DatasetToggles extends ConsumerWidget {
},
),
),

configRowGap,

// Reset Dataset Toggles to default button.

MarkdownTooltip(
message: '''
**Reset Toggles:** Tap here to reset the Dataset Toggles
setting to the default for Rattle.
''',
child: ElevatedButton(
onPressed: _resetToggleStates,
child: const Text('Reset'),
),
),
],
),
settingsGroupGap,
Partition(),
settingsGroupGap,

// Ignore Missing Target row.

Row(
spacing: configRowSpace,
children: [
MarkdownTooltip(
message: '''
*Note: This setting is not yet having any effect.*
**Ignore Missing Target:**
- **On:** Exclude observations with missing target values from analysis.
- **Off:** Include all observations, even those with missing target values.
''',
child: Row(
children: [
const Text(
'Ignore observations with missing target',
style: TextStyle(fontSize: 16),
),
configRowGap,
Switch(
value: ignoreMissingTarget,
onChanged: (value) async {
ref.read(ignoreMissingTargetProvider.notifier).state =
value;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('ignoreMissingTarget', value);
},
),
],
),
),
],
),
settingsGroupGap,

Divider(),
],
);
Expand Down
20 changes: 8 additions & 12 deletions lib/settings/widgets/section_partition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Partition extends ConsumerWidget {
children: [
MarkdownTooltip(
message: '''
**Dataset Partition Setting:** Configure the dataset
partitioning ratios for the training, validation, and
testing datasets.
Expand All @@ -83,12 +82,19 @@ class Partition extends ConsumerWidget {
child: const Text(
'Partition',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
configRowGap,
PartitionControls(
onTrainChanged: _savePartitionTrain,
onTuneChanged: _savePartitionTune,
onTestChanged: _savePartitionTest,
onValidationChanged: _saveValidation,
showOutOfRangeWarning: () => showOutOfRangeWarning(context),
),
configRowGap,
MarkdownTooltip(
message: '''
Expand All @@ -113,16 +119,6 @@ class Partition extends ConsumerWidget {
),
],
),
configRowGap,
PartitionControls(
onTrainChanged: _savePartitionTrain,
onTuneChanged: _savePartitionTune,
onTestChanged: _savePartitionTest,
onValidationChanged: _saveValidation,
showOutOfRangeWarning: () => showOutOfRangeWarning(context),
),
settingsGroupGap,
const Divider(),
],
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/settings/widgets/settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import 'package:shared_preferences/shared_preferences.dart';

import 'package:rattle/settings/widgets/section_dataset_toggles.dart';
import 'package:rattle/settings/widgets/section_graphic_theme.dart';
import 'package:rattle/settings/widgets/section_partition.dart';
import 'package:rattle/settings/widgets/section_random_seed.dart';
import 'package:rattle/settings/widgets/section_session.dart';
import 'package:rattle/providers/cleanse.dart';
Expand Down Expand Up @@ -113,6 +112,11 @@ class SettingsDialogState extends ConsumerState<SettingsDialog> {

ref.read(stripCommentsProvider.notifier).state =
prefs.getBool('stripComments') ?? false;

// Load ignore missing target setting from shared preferences.

ref.read(ignoreMissingTargetProvider.notifier).state =
prefs.getBool('ignoreMissingTarget') ?? true;
}

Future<void> _loadRandomSeed() async {
Expand Down Expand Up @@ -175,7 +179,6 @@ class SettingsDialogState extends ConsumerState<SettingsDialog> {
Divider(),
DatasetToggles(),
GraphicTheme(),
Partition(),
RandomSeed(),
Session(),
Script(),
Expand Down

0 comments on commit cc0d918

Please sign in to comment.