Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NetworkTables Singleton #42

Merged
merged 42 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d0bb545
Removed singleton NT instance
Gold872 Apr 22, 2024
b908c3d
Began work on passing shared instances
Gold872 Apr 22, 2024
e5c9d4c
Separately pass nt instance and preferences
Gold872 Apr 23, 2024
18154e6
Pass a shared preferences instance to every widget
Gold872 Apr 23, 2024
1013556
Change IP address mode to work off of shared preferences
Gold872 Apr 23, 2024
4b0fddb
Fixed unit tests
Gold872 Apr 23, 2024
8d0bfc9
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Apr 29, 2024
c926da0
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 May 18, 2024
6655d8c
Began adding unit tests to nt widgets
Gold872 May 18, 2024
45d44f8
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 May 19, 2024
6f4a20b
Manage subscription sharing through nt connection wrapper
Gold872 May 22, 2024
049a4bb
Added encoder widget test
Gold872 May 25, 2024
9b3da1a
Added FMSInfo test
Gold872 May 25, 2024
0b47d85
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 May 25, 2024
a26d988
Removed broken method
Gold872 May 25, 2024
ef6c48e
Added tests for gyro, motor controller, network alerts, and pid contr…
Gold872 May 25, 2024
3d8dee3
Added tests for pdp, profiled pid controller, and relay
Gold872 May 25, 2024
41fe484
Added test for robot preferences and fixed search bug
Gold872 May 25, 2024
893e4f8
Added remaining multi topic widget tests
Gold872 May 25, 2024
9ecf59b
Make NTWidgetBuilder constructor private
Gold872 May 25, 2024
60a5349
Added boolean box, graph, and match time tests
Gold872 May 26, 2024
51c5c25
Added more single topic widget tests
Gold872 May 26, 2024
0ee90fc
Fixed number slider tests
Gold872 May 26, 2024
69c28ef
Added text display test
Gold872 May 26, 2024
4f7e64c
added bool and bool array tests for text display
Gold872 May 26, 2024
bc9a76a
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 May 26, 2024
2d6b7c6
Replaced deprecated APIs
Gold872 May 26, 2024
87bd0a4
Merge branch 'replace-deprecated-apis' of https://github.com/Gold872/…
Gold872 May 26, 2024
73de192
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 May 26, 2024
b9f1fe6
Added remaining single topic widget tests
Gold872 May 26, 2024
9e8d40c
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jun 25, 2024
0f43387
Refactor notifications to new API changes
Gold872 Jun 25, 2024
c28656d
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jun 25, 2024
ecef2d9
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jun 25, 2024
160e933
Restructure tab grid state (#47)
Gold872 Jun 25, 2024
cb6cba1
Fixed unit tests
Gold872 Jun 25, 2024
d669002
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jun 29, 2024
b0d5f56
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jul 12, 2024
942f7b0
Create unit tests for robot notifications (#51)
EmeraldWither Jul 12, 2024
9bea89e
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jul 18, 2024
8c40ba8
Changed location of default theme variables
Gold872 Jul 18, 2024
c598093
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 23 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import 'package:window_manager/window_manager.dart';

import 'package:elastic_dashboard/pages/dashboard_page.dart';
import 'package:elastic_dashboard/services/field_images.dart';
import 'package:elastic_dashboard/services/ip_address_util.dart';
import 'package:elastic_dashboard/services/log.dart';
import 'package:elastic_dashboard/services/nt_connection.dart';
import 'package:elastic_dashboard/services/nt_widget_builder.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/widgets/settings_dialog.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -57,33 +55,12 @@ void main() async {

await windowManager.ensureInitialized();

Settings.teamNumber =
preferences.getInt(PrefKeys.teamNumber) ?? Settings.teamNumber;
Settings.ipAddressMode =
IPAddressMode.fromIndex(preferences.getInt(PrefKeys.ipAddressMode));

Settings.layoutLocked =
preferences.getBool(PrefKeys.layoutLocked) ?? Settings.layoutLocked;
Settings.gridSize =
preferences.getInt(PrefKeys.gridSize) ?? Settings.gridSize;
Settings.showGrid =
preferences.getBool(PrefKeys.showGrid) ?? Settings.showGrid;
Settings.cornerRadius =
preferences.getDouble(PrefKeys.cornerRadius) ?? Settings.cornerRadius;
Settings.autoResizeToDS =
preferences.getBool(PrefKeys.autoResizeToDS) ?? Settings.autoResizeToDS;
Settings.defaultPeriod =
preferences.getDouble(PrefKeys.defaultPeriod) ?? Settings.defaultPeriod;
Settings.defaultGraphPeriod =
preferences.getDouble(PrefKeys.defaultGraphPeriod) ??
Settings.defaultGraphPeriod;

NTWidgetBuilder.ensureInitialized();

Settings.ipAddress =
preferences.getString(PrefKeys.ipAddress) ?? Settings.ipAddress;
String ipAddress =
preferences.getString(PrefKeys.ipAddress) ?? Defaults.ipAddress;

ntConnection.nt4Connect(Settings.ipAddress);
NTConnection ntConnection = NTConnection(ipAddress);

await FieldImages.loadFields('assets/fields/');

Expand All @@ -107,7 +84,13 @@ void main() async {
await windowManager.show();
await windowManager.focus();

runApp(Elastic(version: packageInfo.version, preferences: preferences));
runApp(
Elastic(
ntConnection: ntConnection,
preferences: preferences,
version: packageInfo.version,
),
);
}

Future<void> _restoreWindowPosition(SharedPreferences preferences,
Expand Down Expand Up @@ -190,10 +173,15 @@ Future<void> _restorePreferencesFromBackup(String appFolderPath) async {
}

class Elastic extends StatefulWidget {
final NTConnection ntConnection;
final SharedPreferences preferences;
final String version;

const Elastic({super.key, required this.version, required this.preferences});
const Elastic(
{super.key,
required this.ntConnection,
required this.preferences,
required this.version});

@override
State<Elastic> createState() => _ElasticState();
Expand All @@ -202,7 +190,7 @@ class Elastic extends StatefulWidget {
class _ElasticState extends State<Elastic> {
late Color teamColor = Color(
widget.preferences.getInt(PrefKeys.teamColor) ?? Colors.blueAccent.value);
late FlexSchemeVariant flexSchemeVariant = FlexSchemeVariant.values
late FlexSchemeVariant themeVariant = FlexSchemeVariant.values
.firstWhereOrNull((element) =>
element.variantName ==
widget.preferences.getString(PrefKeys.themeVariant)) ??
Expand All @@ -215,25 +203,26 @@ class _ElasticState extends State<Elastic> {
colorScheme: SeedColorScheme.fromSeeds(
primaryKey: teamColor,
brightness: Brightness.dark,
variant: Settings.themeVariant,
variant: themeVariant,
),
);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Elastic',
theme: theme,
home: DashboardPage(
ntConnection: widget.ntConnection,
preferences: widget.preferences,
version: widget.version,
onColorChanged: (color) => setState(() {
teamColor = color;
widget.preferences.setInt(PrefKeys.teamColor, color.value);
}),
onThemeVariantChanged: (variant) async {
flexSchemeVariant = variant;
if (variant == SettingsDialog.defaultVariant) {
await widget.preferences.setString(
PrefKeys.themeVariant, SettingsDialog.defaultVariantName);
themeVariant = variant;
if (variant == Defaults.themeVariant) {
await widget.preferences
.setString(PrefKeys.themeVariant, Defaults.defaultVariantName);
} else {
await widget.preferences
.setString(PrefKeys.themeVariant, variant.variantName);
Expand Down
Loading
Loading