loris/lib/pages/settings/app.dart

153 lines
4.3 KiB
Dart
Raw Normal View History

2022-08-12 17:00:09 +00:00
// ignore_for_file: unused_import
2022-08-14 20:43:36 +00:00
import 'package:flutter/services.dart';
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
),
2022-08-14 20:43:36 +00:00
const 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()),
2022-08-14 20:43:36 +00:00
Flexible(
child: Slider(
label: size.toString(),
value: size.toDouble(),
divisions: 19,
min: 5,
max: 100,
onChanged: ((value) {
global.settings!.saveBatchSize(value.toInt());
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> {
2022-08-14 20:43:36 +00:00
double value = global.settings!.postWidth;
String maxValue = global.settings!.maxPostWidth.round().toString();
final _formKey = GlobalKey<FormState>();
2022-08-14 18:02:42 +00:00
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SelectableText(
2022-08-14 20:43:36 +00:00
"content-width-percentage-label".i18n(),
2022-08-14 18:02:42 +00:00
),
2022-08-14 20:43:36 +00:00
Flexible(
child: 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!.savePostWidth(value);
}),
),
),
],
),
SelectableText("content-width-percentage-description".i18n()),
Row(
children: [
SelectableText(
"max-content-width-label".i18n(),
),
Flexible(
child: Form(
key: _formKey,
onChanged: () {
if (_formKey.currentState!.validate()) {}
},
child: TextFormField(
textAlign: TextAlign.right,
initialValue: maxValue,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
onChanged: (String value) {
setState(() {
maxValue = value;
});
if (maxValue.isNotEmpty) {
if (double.parse(maxValue) >= 375) {
global.settings!
.saveMaxPostWidth(double.parse(maxValue));
} else {
setState(() {
maxValue = 375.toString();
});
}
}
},
),
),
2022-08-14 18:02:42 +00:00
),
],
),
SelectableText("content-max-width-description".i18n()),
],
);
}
}