nc-photos/lib/widget/lab_settings.dart

117 lines
2.8 KiB
Dart
Raw Normal View History

2021-08-08 20:46:16 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/theme.dart';
class LabSettings extends StatefulWidget {
static const routeName = "/lab-settings";
2021-09-15 08:58:06 +02:00
const LabSettings({
Key? key,
}) : super(key: key);
2021-08-08 20:46:16 +02:00
@override
createState() => _LabSettingsState();
}
class _LabSettingsState extends State<LabSettings> {
@override
initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((_) {
showDialog(
context: context,
builder: (context) => AlertDialog(
2021-09-15 08:58:06 +02:00
title: const Text("Warning"),
content: const Text(
2021-08-08 20:46:16 +02:00
"Features listed here may be untested, unfinished, or even completely broken. They may break the app and corrupt your data. No help/support will be provided.\n\nDO NOT proceed unless you understand the risk"),
actions: [
Align(
alignment: AlignmentDirectional.centerEnd,
child: TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
2021-09-15 08:58:06 +02:00
child: const Text("I UNDERSTAND"),
2021-08-08 20:46:16 +02:00
),
),
],
),
).then((value) {
if (value != true) {
Navigator.of(context).pop();
}
});
});
}
@override
build(BuildContext context) {
return AppTheme(
child: Scaffold(
body: Builder(builder: (context) => _buildContent(context)),
appBar: AppBar(
2021-09-15 08:58:06 +02:00
title: const Text("Lab Settings"),
2021-08-08 20:46:16 +02:00
),
),
);
}
Widget _buildContent(BuildContext context) {
return ListView(
children: [
_LabBoolItem(
2021-09-15 08:58:06 +02:00
title: const Text("enableSharedAlbum"),
2021-08-08 20:46:16 +02:00
isSelected: Pref.inst().isLabEnableSharedAlbumOr(false),
onChanged: (value) {
Pref.inst().setLabEnableSharedAlbum(value);
},
),
],
);
}
}
class _LabBoolItem extends StatefulWidget {
2021-09-15 08:58:06 +02:00
const _LabBoolItem({
2021-08-08 20:46:16 +02:00
Key? key,
required this.title,
this.subtitle,
required this.isSelected,
this.onChanged,
}) : super(key: key);
@override
createState() => _LabBoolItemState();
final Widget title;
final Widget? subtitle;
final bool isSelected;
final ValueChanged<bool>? onChanged;
}
class _LabBoolItemState extends State<_LabBoolItem> {
@override
initState() {
super.initState();
_isSelected = widget.isSelected;
}
@override
build(BuildContext context) {
return CheckboxListTile(
title: widget.title,
subtitle: widget.subtitle,
value: _isSelected,
onChanged: (value) {
setState(() {
_isSelected = value!;
});
widget.onChanged?.call(value!);
},
);
}
late bool _isSelected;
}