loris/lib/pages/settings/app.dart

109 lines
2.7 KiB
Dart
Raw Normal View History

2022-08-12 17:00:09 +00:00
// ignore_for_file: unused_import
2022-08-10 16:47:34 +00:00
import 'package:localization/localization.dart';
import '../../business_logic/settings.dart' as settings;
2022-08-12 17:00:09 +00:00
import '../../global.dart' as global;
2022-08-10 16:47:34 +00:00
import 'package:flutter/material.dart';
class AppSettings extends StatelessWidget {
const AppSettings({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
2022-08-10 18:49:51 +00:00
children: [
2022-08-12 17:00:09 +00:00
PostBatchSlider(
initialSize: global.settings!.batchSize,
2022-08-14 18:02:42 +00:00
),
ContentWidthSlider(),
2022-08-10 18:49:51 +00:00
],
);
}
}
class PostBatchSlider extends StatefulWidget {
const PostBatchSlider({required this.initialSize, Key? key})
: super(key: key);
final int initialSize;
@override
State<PostBatchSlider> createState() => _PostBatchSliderState();
}
class _PostBatchSliderState extends State<PostBatchSlider> {
late int size;
@override
void initState() {
size = widget.initialSize;
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
2022-08-10 16:47:34 +00:00
children: [
Row(
children: [
Text("post-batch-size".i18n()),
Slider(
2022-08-10 18:49:51 +00:00
label: size.toString(),
value: size.toDouble(),
divisions: 19,
min: 5,
2022-08-10 16:47:34 +00:00
max: 100,
2022-08-10 18:49:51 +00:00
onChanged: ((value) {
2022-08-12 17:00:09 +00:00
global.settings!.saveBatchSize(value.toInt());
2022-08-10 18:49:51 +00:00
setState(() {
size = value.toInt();
});
}),
2022-08-10 16:47:34 +00:00
)
],
2022-08-10 18:49:51 +00:00
),
SelectableText("post-batch-size-description".i18n()),
2022-08-10 16:47:34 +00:00
],
);
}
}
2022-08-14 18:02:42 +00:00
class ContentWidthSlider extends StatefulWidget {
const ContentWidthSlider({Key? key}) : super(key: key);
@override
State<ContentWidthSlider> createState() => _ContentWidthSliderState();
}
class _ContentWidthSliderState extends State<ContentWidthSlider> {
double value = global.settings!.maxPostWidth;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SelectableText(
"content-width-label".i18n(),
),
Slider(
min: 0.4,
max: 1.0,
label: "${(value * 100).round()}%",
value: value,
divisions: 6,
onChanged: ((double v) async {
setState(() {
value = v;
});
await global.settings!.saveMaxPostWidth(value);
}),
),
],
),
SelectableText("content-max-width-description".i18n()),
],
);
}
}