save ui settings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart' show GlobalKey, NavigatorState;
|
||||
|
||||
const addMountTitle = 'Add New Mount';
|
||||
const appSettingsTitle = 'Portal Settings';
|
||||
const appTitle = 'Repertory Management Portal';
|
||||
const databaseTypeList = ['rocksdb', 'sqlite'];
|
||||
const downloadTypeList = ['default', 'direct', 'ring_buffer'];
|
||||
|
@@ -52,7 +52,8 @@ class _MyAppState extends State<MyApp> {
|
||||
'/add':
|
||||
(context) => const AddMountScreen(title: constants.addMountTitle),
|
||||
'/settings':
|
||||
(context) => const EditSettingsScreen(title: constants.appTitle),
|
||||
(context) =>
|
||||
const EditSettingsScreen(title: constants.appSettingsTitle),
|
||||
},
|
||||
onGenerateRoute: (settings) {
|
||||
if (settings.name != '/edit') {
|
||||
|
@@ -1,21 +1,23 @@
|
||||
import 'dart:convert' show jsonDecode, jsonEncode;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/helpers.dart'
|
||||
show getSettingDescription, getSettingValidators, trimNotEmptyValidator;
|
||||
import 'package:repertory/models/mount.dart';
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
show
|
||||
convertAllToString,
|
||||
getBaseUri,
|
||||
getSettingDescription,
|
||||
getSettingValidators,
|
||||
trimNotEmptyValidator;
|
||||
import 'package:repertory/settings.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
|
||||
class UISettingsWidget extends StatefulWidget {
|
||||
final bool showAdvanced;
|
||||
final Function? onChanged;
|
||||
final Map<String, dynamic> settings;
|
||||
const UISettingsWidget({
|
||||
super.key,
|
||||
this.onChanged,
|
||||
required this.settings,
|
||||
required this.showAdvanced,
|
||||
});
|
||||
@@ -25,6 +27,8 @@ class UISettingsWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
late Map<String, dynamic> _origSettings;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<SettingsTile> commonSettings = [];
|
||||
@@ -94,6 +98,32 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (!DeepCollectionEquality().equals(widget.settings, _origSettings)) {
|
||||
http
|
||||
.put(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/settings?data=${convertAllToString(widget.settings)})',
|
||||
),
|
||||
),
|
||||
)
|
||||
.then((_) {})
|
||||
.catchError((e) {
|
||||
debugPrint('$e');
|
||||
});
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_origSettings = jsonDecode(jsonEncode(widget.settings));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(VoidCallback fn) {
|
||||
if (!mounted) {
|
||||
|
Reference in New Issue
Block a user