Skip to content

Commit

Permalink
Fixed build errors and added settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Nov 22, 2024
1 parent 481261f commit 8cb5bff
Showing 2 changed files with 33 additions and 23 deletions.
47 changes: 26 additions & 21 deletions lib/mini.dart
Original file line number Diff line number Diff line change
@@ -15,29 +15,21 @@ import "package:flutter/material.dart";
import "package:rover_dashboard/app.dart";
import "package:rover_dashboard/data.dart";
import "package:rover_dashboard/models.dart";
import "package:rover_dashboard/pages.dart";
import "package:rover_dashboard/services.dart";
import "package:rover_dashboard/src/pages/mini_home.dart";
import "package:rover_dashboard/src/pages/mini_logs.dart";
import "package:rover_dashboard/src/pages/mini_metrics.dart";
import "package:rover_dashboard/widgets.dart";

class MiniViewModel with ChangeNotifier {
bool _darkMode = false;
Widget Function(BuildContext context)? _footerWidget;

/// Constructor for [MiniViewModel], calls [init] to setup mini dashboard
MiniViewModel() {
init();
}

set darkMode(bool darkMode) {
_darkMode = darkMode;
notifyListeners();
}

/// Whether or not dark mode is enabled
bool get darkMode => _darkMode;

set footerWidget(Widget Function(BuildContext context)? footerWidget) {
_footerWidget = footerWidget;
notifyListeners();
@@ -56,8 +48,16 @@ class MiniViewModel with ChangeNotifier {
await models.sockets.setRover(RoverType.localhost);
await models.sockets.disable();

models.settings.addListener(notifyListeners);

notifyListeners();
}

@override
void dispose() {
models.settings.removeListener(notifyListeners);
super.dispose();
}
}

class MiniHomePage extends StatelessWidget {
@@ -72,15 +72,9 @@ class MiniHomePage extends StatelessWidget {
automaticallyImplyLeading: false,
title: Text("Dashboard v${models.home.version ?? ''}"),
actions: [
Row(
children: [
const Text(
"Dark Mode",
style: TextStyle(color: Colors.white),
),
const SizedBox(width: 5),
Switch(value: model.darkMode, onChanged: (value) => model.darkMode = value),
],
IconButton(
onPressed: () => Navigator.of(context).pushNamed(Routes.settings),
icon: const Icon(Icons.settings),
),
const SizedBox(width: 10),
const PowerButton(),
@@ -185,7 +179,7 @@ class MiniDashboard extends ReactiveWidget<MiniViewModel> {
Widget build(BuildContext context, MiniViewModel model) => MaterialApp(
title: "Binghamton University Rover Team",
debugShowCheckedModeBanner: false,
themeMode: model.darkMode ? ThemeMode.dark : ThemeMode.light,
themeMode: models.isReady ? models.settings.dashboard.themeMode : ThemeMode.system,
theme: ThemeData(
colorScheme: const ColorScheme.light(
primary: binghamtonGreen,
@@ -203,6 +197,10 @@ class MiniDashboard extends ReactiveWidget<MiniViewModel> {
),
),
home: MiniHomePage(model: model),
routes: {
Routes.home: (_) => MiniHomePage(model: model),
Routes.settings: (_) => SettingsPage(),
},
);
}

@@ -214,8 +212,15 @@ void main() async {
if (error is SocketException && networkErrors.contains(error.osError!.errorCode)) {
models.home.setMessage(severity: Severity.critical, text: "Network error, restart by clicking the network icon");
} else {
models.home.setMessage(severity: Severity.critical, text: "Dashboard error. See the logs");
await services.files.logError(error, stack);
models.home.setMessage(severity: Severity.critical, text: "Dashboard error. See the logs", logMessage: false);
models.logs.handleLog(
BurtLog(
level: BurtLogLevel.critical,
title: "Dashboard Error. Click for details",
body: "$error\n$stack",
device: Device.DASHBOARD,
),
);
Error.throwWithStackTrace(error, stack);
}
});
9 changes: 7 additions & 2 deletions lib/src/pages/mini_home.dart
Original file line number Diff line number Diff line change
@@ -143,11 +143,16 @@ class MiniHomeToggleOptions extends ReusableReactiveWidget<Sockets> {
Switch(
value: model.isEnabled,
onChanged: (enabled) async {
if (model.rover != RoverType.localhost) {
await model.setRover(RoverType.localhost);
if (enabled) {
if (model.rover != RoverType.localhost) {
await model.setRover(RoverType.localhost);
}
}

if (!enabled) {
for (final socket in model.sockets) {
await socket.dispose();
}
await model.disable();
} else {
await model.init();

0 comments on commit 8cb5bff

Please sign in to comment.