2022-11-22 16:12:38 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:mobile_nebula/components/SimplePage.dart';
|
|
|
|
import 'package:mobile_nebula/components/config/ConfigItem.dart';
|
|
|
|
import 'package:mobile_nebula/components/config/ConfigPageItem.dart';
|
|
|
|
import 'package:mobile_nebula/components/config/ConfigSection.dart';
|
2022-11-22 16:12:38 +00:00
|
|
|
import 'package:mobile_nebula/screens/EnrollmentScreen.dart';
|
2020-07-27 20:43:58 +00:00
|
|
|
import 'package:mobile_nebula/services/settings.dart';
|
|
|
|
import 'package:mobile_nebula/services/utils.dart';
|
|
|
|
|
|
|
|
import 'AboutScreen.dart';
|
|
|
|
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
2022-11-22 16:12:38 +00:00
|
|
|
final StreamController stream;
|
|
|
|
|
|
|
|
const SettingsScreen(this.stream, {super.key});
|
|
|
|
|
2020-07-27 20:43:58 +00:00
|
|
|
@override
|
2022-11-22 16:12:38 +00:00
|
|
|
_SettingsScreenState createState() => _SettingsScreenState();
|
2020-07-27 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
|
|
var settings = Settings();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
//TODO: we need to unregister on dispose?
|
|
|
|
settings.onChange().listen((_) {
|
|
|
|
if (this.mounted) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
List<Widget> colorSection = [];
|
|
|
|
|
|
|
|
colorSection.add(ConfigItem(
|
|
|
|
label: Text('Use system colors'),
|
|
|
|
labelWidth: 200,
|
|
|
|
content: Align(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Switch.adaptive(
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
onChanged: (value) {
|
|
|
|
settings.useSystemColors = value;
|
|
|
|
},
|
|
|
|
value: settings.useSystemColors,
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
|
|
|
|
if (!settings.useSystemColors) {
|
|
|
|
colorSection.add(ConfigItem(
|
|
|
|
label: Text('Dark mode'),
|
|
|
|
content: Align(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Switch.adaptive(
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
onChanged: (value) {
|
|
|
|
settings.darkMode = value;
|
|
|
|
},
|
|
|
|
value: settings.darkMode,
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> items = [];
|
|
|
|
items.add(ConfigSection(children: colorSection));
|
2021-02-05 15:09:56 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
));
|
2022-11-22 16:12:38 +00:00
|
|
|
|
|
|
|
items.add(ConfigSection(children: [
|
|
|
|
ConfigPageItem(
|
2024-09-20 18:19:23 +00:00
|
|
|
label: Text('Enroll with Managed Nebula'),
|
|
|
|
labelWidth: 200,
|
|
|
|
onPressed: () =>
|
|
|
|
Utils.openPage(context, (context) => EnrollmentScreen(stream: widget.stream, allowCodeEntry: true)))
|
2022-11-22 16:12:38 +00:00
|
|
|
]));
|
|
|
|
|
2021-02-05 15:09:56 +00:00
|
|
|
items.add(ConfigSection(children: [
|
|
|
|
ConfigPageItem(
|
|
|
|
label: Text('About'),
|
|
|
|
onPressed: () => Utils.openPage(context, (context) => AboutScreen()),
|
|
|
|
)
|
|
|
|
]));
|
2020-07-27 20:43:58 +00:00
|
|
|
|
|
|
|
return SimplePage(
|
2022-11-17 21:43:16 +00:00
|
|
|
title: Text('Settings'),
|
2020-07-27 20:43:58 +00:00
|
|
|
child: Column(children: items),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|