153 lines
4.3 KiB
Dart
153 lines
4.3 KiB
Dart
// ignore_for_file: unused_import
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:localization/localization.dart';
|
|
import '../../business_logic/settings.dart' as settings;
|
|
import '../../global.dart' as global;
|
|
import 'package:flutter/material.dart';
|
|
|
|
class AppSettings extends StatelessWidget {
|
|
const AppSettings({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
PostBatchSlider(
|
|
initialSize: global.settings!.batchSize,
|
|
),
|
|
const ContentWidthSlider(),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
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,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Text("post-batch-size".i18n()),
|
|
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();
|
|
});
|
|
}),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
SelectableText("post-batch-size-description".i18n()),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
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!.postWidth;
|
|
String maxValue = global.settings!.maxPostWidth.round().toString();
|
|
final _formKey = GlobalKey<FormState>();
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
SelectableText(
|
|
"content-width-percentage-label".i18n(),
|
|
),
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SelectableText("content-max-width-description".i18n()),
|
|
],
|
|
);
|
|
}
|
|
}
|