Skip to content

Commit

Permalink
update ViewSettings
Browse files Browse the repository at this point in the history
TO-DO:
+ rimuovere il go back quando l'utente salva/cancella le impostazioni.
  • Loading branch information
mikyll committed Dec 16, 2023
1 parent 90b37ff commit fcd6733
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions app-mobile/flutter_application/lib/views/ViewSettings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class ViewSettingsState extends State<ViewSettings> {
bool _confirmAlerts = Settings.DEFAULT_CONFIRM_ALERTS;
bool _darkTheme = Settings.DEFAULT_DARK_THEME; // previous value

bool _wentBack =
false; // to check if the user went back while choosing the questions file
/// For Desktop platform: when a user leaves the Settings page with the
/// file picker dialog still open and then select a file, the upload will
/// fail.
bool _wentBack = false;
bool _isLoading = false;

void _updateQuizDefaults() {
Expand Down Expand Up @@ -230,7 +232,6 @@ class ViewSettingsState extends State<ViewSettings> {
FilePickerResult? result = await FilePicker.platform
.pickFiles(type: FileType.custom, allowedExtensions: ["txt"]);

// For Desktop platform: when a user leaves the Settings page, and then still uploads a questions file (the file picker window was still open).
if (_wentBack) {
return;
}
Expand Down Expand Up @@ -796,16 +797,20 @@ class ViewSettingsState extends State<ViewSettings> {
? null
: () {
widget.saveSettings(
_checkAppUpdate,
_checkQuestionsUpdate,
_questionNumber,
_timer,
_shuffleAnswers,
_confirmAlerts,
themeProvider.isDarkMode);
_darkTheme = themeProvider.isDarkMode;

setState(() => _wentBack = true);
_checkAppUpdate,
_checkQuestionsUpdate,
_questionNumber,
_timer,
_shuffleAnswers,
_confirmAlerts,
themeProvider.isDarkMode,
);

setState(() {
_darkTheme = themeProvider.isDarkMode;
_wentBack = true;
});

Navigator.pop(context);
},
child: Container(
Expand All @@ -826,12 +831,17 @@ class ViewSettingsState extends State<ViewSettings> {
FittedBox(
fit: BoxFit.fitWidth,
child: ElevatedButton(
onPressed: () {
themeProvider.toggleTheme(_darkTheme);
onPressed: !_isChanged(themeProvider)
? null
: () {
themeProvider.toggleTheme(_darkTheme);

setState(() => _wentBack = true);
Navigator.pop(context);
},
setState(() {
_wentBack = true;
});

Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
height: 50.0,
Expand Down

0 comments on commit fcd6733

Please sign in to comment.