add max width field
This commit is contained in:
parent
d97548c794
commit
cc6a67c855
|
@ -67,7 +67,9 @@ class AccountSettings {
|
|||
}
|
||||
|
||||
class Settings {
|
||||
late double maxPostWidth = 0.8;
|
||||
late double postWidth = 0.8;
|
||||
static const postWidthKey = "post-width";
|
||||
late double maxPostWidth = 1000;
|
||||
static const maxPostWidthKey = "max-post-width";
|
||||
late Locale locale;
|
||||
static const localeKey = "active-locale";
|
||||
|
@ -105,7 +107,8 @@ class Settings {
|
|||
settings.activeIdentity = settings.identities.keys.first;
|
||||
}
|
||||
|
||||
settings.maxPostWidth = settings.prefs.getDouble(maxPostWidthKey) ?? 0.8;
|
||||
settings.postWidth = settings.prefs.getDouble(postWidthKey) ?? 0.8;
|
||||
settings.maxPostWidth = settings.prefs.getDouble(maxPostWidthKey) ?? 1000;
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
@ -115,6 +118,11 @@ class Settings {
|
|||
return prefs.setDouble(maxPostWidthKey, width);
|
||||
}
|
||||
|
||||
Future<bool> savePostWidth(double width) {
|
||||
postWidth = width;
|
||||
return prefs.setDouble(postWidthKey, width);
|
||||
}
|
||||
|
||||
Future<bool> addNewIdentity(String key) async {
|
||||
List<String> a = identities.keys.toList();
|
||||
a.removeWhere((element) {
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
"local-timeline": "local",
|
||||
"home-timeline": "home",
|
||||
"public-timeline": "federated",
|
||||
"content-width-label": "max content width",
|
||||
"content-max-width-description": "determines how wide the timeline should be (requires reloading the timeline)"
|
||||
"content-width-percentage-label": "content width",
|
||||
"content-width-percentage-description": "determines what the regular width of content should be in percent (requires reloading the timeline)",
|
||||
"max-content-width-label": "max content width",
|
||||
"content-max-width-description": "determines what the maximum width of content should be, values below 375 get ignored (requires reloading the timeline)"
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// 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;
|
||||
|
@ -15,7 +16,7 @@ class AppSettings extends StatelessWidget {
|
|||
PostBatchSlider(
|
||||
initialSize: global.settings!.batchSize,
|
||||
),
|
||||
ContentWidthSlider(),
|
||||
const ContentWidthSlider(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -46,18 +47,20 @@ class _PostBatchSliderState extends State<PostBatchSlider> {
|
|||
Row(
|
||||
children: [
|
||||
Text("post-batch-size".i18n()),
|
||||
Slider(
|
||||
label: size.toString(),
|
||||
value: size.toDouble(),
|
||||
divisions: 19,
|
||||
min: 5,
|
||||
max: 100,
|
||||
onChanged: ((value) {
|
||||
global.settings!.saveBatchSize(value.toInt());
|
||||
setState(() {
|
||||
size = value.toInt();
|
||||
});
|
||||
}),
|
||||
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();
|
||||
});
|
||||
}),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -75,7 +78,9 @@ class ContentWidthSlider extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ContentWidthSliderState extends State<ContentWidthSlider> {
|
||||
double value = global.settings!.maxPostWidth;
|
||||
double value = global.settings!.postWidth;
|
||||
String maxValue = global.settings!.maxPostWidth.round().toString();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
|
@ -84,20 +89,59 @@ class _ContentWidthSliderState extends State<ContentWidthSlider> {
|
|||
Row(
|
||||
children: [
|
||||
SelectableText(
|
||||
"content-width-label".i18n(),
|
||||
"content-width-percentage-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);
|
||||
}),
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -22,9 +22,12 @@ class Thread extends StatelessWidget {
|
|||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
width: (MediaQuery.of(context).size.width *
|
||||
global.settings!.maxPostWidth) -
|
||||
global.settings!.postWidth) -
|
||||
56,
|
||||
constraints: const BoxConstraints(minWidth: 375),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: global.settings!.maxPostWidth,
|
||||
minWidth: 375,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
border:
|
||||
|
|
Loading…
Reference in New Issue