3
0
Fork 0

Add logWrap to global settings

`logWrap` is a configuration that allows for users to decide if when
viewing logs the lines should extend off screen allowing for scroll
behavior or if they should wrap at screen edge.

We also considered allowing users to toggle this setting at the Site
level but decided that since users would likely want this setting to
apply to all sites, we hoisted the configuration.

Advances #3
This commit is contained in:
micha3lbrown 2021-02-05 10:09:56 -05:00
parent dd1bc9e3f9
commit e844e2c195
No known key found for this signature in database
GPG Key ID: 3F02D82B487AD431
4 changed files with 42 additions and 8 deletions

View File

@ -109,4 +109,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: e8d4fb1ed5b0713de2623a28dfae2585e15c0d00 PODFILE CHECKSUM: e8d4fb1ed5b0713de2623a28dfae2585e15c0d00
COCOAPODS: 1.9.0 COCOAPODS: 1.10.0

View File

@ -66,7 +66,27 @@ class _SettingsScreenState extends State<SettingsScreen> {
List<Widget> items = []; List<Widget> items = [];
items.add(ConfigSection(children: colorSection)); items.add(ConfigSection(children: colorSection));
items.add(ConfigSection(children: [ConfigPageItem(label: Text('About'), onPressed: () => Utils.openPage(context, (context) => AboutScreen()),)])); items.add(ConfigItem(
label: Text('Wrap log output'),
labelWidth: 200,
content: Align(
alignment: Alignment.centerRight,
child: Switch.adaptive(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
value: settings.logWrap,
onChanged: (value) {
setState(() {
settings.logWrap = value;
});
},
)),
));
items.add(ConfigSection(children: [
ConfigPageItem(
label: Text('About'),
onPressed: () => Utils.openPage(context, (context) => AboutScreen()),
)
]));
return SimplePage( return SimplePage(
title: 'Settings', title: 'Settings',

View File

@ -7,6 +7,7 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:mobile_nebula/components/SimplePage.dart'; import 'package:mobile_nebula/components/SimplePage.dart';
import 'package:mobile_nebula/components/SpecialSelectableText.dart'; import 'package:mobile_nebula/components/SpecialSelectableText.dart';
import 'package:mobile_nebula/models/Site.dart'; import 'package:mobile_nebula/models/Site.dart';
import 'package:mobile_nebula/services/settings.dart';
import 'package:mobile_nebula/services/share.dart'; import 'package:mobile_nebula/services/share.dart';
import 'package:mobile_nebula/services/utils.dart'; import 'package:mobile_nebula/services/utils.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
@ -25,6 +26,7 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
ScrollController controller = ScrollController(); ScrollController controller = ScrollController();
RefreshController refreshController = RefreshController(initialRefresh: false); RefreshController refreshController = RefreshController(initialRefresh: false);
var settings = Settings();
@override @override
void initState() { void initState() {
loadLogs(); loadLogs();
@ -52,10 +54,7 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
refreshController.loadComplete(); refreshController.loadComplete();
}, },
refreshController: refreshController, refreshController: refreshController,
child: Container( child: Container(padding: EdgeInsets.all(5), constraints: logBoxConstraints(context), child: SpecialSelectableText(logs.trim(), style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14))),
padding: EdgeInsets.all(5),
constraints: BoxConstraints(minWidth: MediaQuery.of(context).size.width),
child: SpecialSelectableText(logs.trim(), style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14))),
bottomBar: _buildBottomBar(), bottomBar: _buildBottomBar(),
); );
} }
@ -95,8 +94,7 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
padding: padding, padding: padding,
icon: Icon(context.platformIcons.downArrow, size: 30), icon: Icon(context.platformIcons.downArrow, size: 30),
onPressed: () async { onPressed: () async {
controller.animateTo(controller.position.maxScrollExtent, controller.animateTo(controller.position.maxScrollExtent, duration: const Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
duration: const Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
}, },
)), )),
])); ]));
@ -120,4 +118,12 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
await file.writeAsBytes([]); await file.writeAsBytes([]);
await loadLogs(); await loadLogs();
} }
logBoxConstraints(BuildContext context) {
if (settings.logWrap) {
return BoxConstraints(maxWidth: MediaQuery.of(context).size.width);
} else {
return BoxConstraints(minWidth: MediaQuery.of(context).size.width);
}
}
} }

View File

@ -30,6 +30,14 @@ class Settings {
_set('darkMode', enabled); _set('darkMode', enabled);
} }
bool get logWrap {
return _getBool('logWrap', false);
}
set logWrap(bool enabled) {
_set('logWrap', enabled);
}
String _getString(String key, String defaultValue) { String _getString(String key, String defaultValue) {
final val = _settings[key]; final val = _settings[key];
if (val is String) { if (val is String) {