added animation toggle
Some checks failed
BlockStorage/repertory_mac/pipeline/head There was a failure building this commit
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2025-09-08 07:47:04 -05:00
parent f0bd032cb9
commit d772a713a2
6 changed files with 80 additions and 22 deletions

View File

@@ -20,15 +20,41 @@ class Settings with ChangeNotifier {
bool get autoStart => _autoStart;
bool get enableAnimations => _enableAnimations;
set enableAnimations(bool enable) {
_enableAnimations = enable;
notifyListeners();
}
void _reset() {
_autoStart = false;
}
Future<void> setEnableAnimations(bool value) async {
try {
final auth = await _auth.createAuth();
final response = await http.put(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/setting?auth=$auth&name=Animations&value=$value',
),
),
);
if (response.statusCode == 401) {
_auth.logoff();
_reset();
return;
}
if (response.statusCode != 200) {
_reset();
return;
}
_enableAnimations = value;
notifyListeners();
} catch (e) {
debugPrint('$e');
_reset();
}
}
Future<void> setAutoStart(bool value) async {
try {
final auth = await _auth.createAuth();
@@ -77,7 +103,10 @@ class Settings with ChangeNotifier {
return;
}
_autoStart = jsonDecode(response.body)["AutoStart"] as bool;
final jsonData = jsonDecode(response.body);
_enableAnimations = jsonData["Animations"] as bool;
_autoStart = jsonData["AutoStart"] as bool;
notifyListeners();
} catch (e) {
debugPrint('$e');

View File

@@ -134,22 +134,36 @@ class AppScaffold extends StatelessWidget {
),
const SizedBox(width: constants.padding),
if (!showBack) ...[
const Text("Animations"),
Consumer<Settings>(
builder: (context, settings, _) => IconButton(
icon: Icon(
settings.enableAnimations
? Icons.toggle_on
: Icons.toggle_off,
),
color: settings.enableAnimations
? scheme.primary
: scheme.onSurface,
onPressed: () => settings.setEnableAnimations(
!settings.enableAnimations,
),
),
),
const Text("Auto-start"),
Consumer<Settings>(
builder: (context, settings, _) {
return IconButton(
icon: Icon(
settings.autoStart
? Icons.toggle_on
: Icons.toggle_off,
),
color: settings.autoStart
? scheme.primary
: scheme.onSurface,
onPressed: () =>
settings.setAutoStart(!settings.autoStart),
);
},
builder: (context, settings, _) => IconButton(
icon: Icon(
settings.autoStart
? Icons.toggle_on
: Icons.toggle_off,
),
color: settings.autoStart
? scheme.primary
: scheme.onSurface,
onPressed: () =>
settings.setAutoStart(!settings.autoStart),
),
),
IconButton(
tooltip: 'Settings',