Skip to content

Commit

Permalink
feat: Add serial device selector badge
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeLayer committed Oct 19, 2024
1 parent 8c3c288 commit d167c05
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 1 deletion.
66 changes: 66 additions & 0 deletions configurator/lib/components/device_selector.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:configurator/models/serial_descriptor.dart';

class DeviceSelector extends StatefulWidget {
const DeviceSelector({super.key});

@override
State<DeviceSelector> createState() => _DeviceSelectorState();
}

class _DeviceSelectorState extends State<DeviceSelector> {
List<SerialDescriptor> _serialDescriptors = [
SerialDescriptor('COM', 'asdf'),
SerialDescriptor('EACH', 'None')
];
String? _selected;

@override
Widget build(BuildContext context) {
return Container(
child: FilledButton(
style: FilledButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 12.0),
minimumSize: Size(0, 0), // Remove minimum size constraints
tapTargetSize: MaterialTapTargetSize.shrinkWrap, // Shrink to fit
),
onPressed: () async {
final RenderBox button = context.findRenderObject() as RenderBox;
final RenderBox overlay =
Overlay.of(context).context.findRenderObject() as RenderBox;

// Calculate the position where the menu should appear
final Offset buttonPosition =
button.localToGlobal(Offset.zero, ancestor: overlay);
final RelativeRect position = RelativeRect.fromRect(
Rect.fromLTWH(
buttonPosition.dx,
buttonPosition.dy,
button.size.width,
button.size.height,
),
Offset.zero & overlay.size,
);

// Show the menu
final result = await showMenu<String>(
context: context,
position: position,
items: _serialDescriptors.map<PopupMenuEntry<String>>((each) {
return PopupMenuItem<String>(
value: each.port,
child: Text('(${each.port}) ${each.description}'));
}).toList(),
);

// Handle the selection
if (result != null) {
setState(() {
_selected = result;
});
}
},
child: Text('State'),
));
}
}
1 change: 0 additions & 1 deletion configurator/lib/components/key_config_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:configurator/widgets/key_detect_field.dart';
import 'package:flutter/material.dart';
import 'package:configurator/models/keycode.dart';
import 'package:configurator/globals.dart';
import 'dart:developer';

class KeyConfigListItemContainer {
KeyConfigListItemContainer(
Expand Down
5 changes: 5 additions & 0 deletions configurator/lib/models/serial_descriptor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SerialDescriptor {
late final String port;
late final String description;
SerialDescriptor(this.port, this.description);
}
3 changes: 3 additions & 0 deletions configurator/lib/screens/main_config_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:configurator/components/device_selector.dart';
import 'package:flutter/material.dart';
import 'package:configurator/components/key_config_list.dart';

Expand All @@ -19,6 +20,8 @@ class _MainConfigPageState extends State<MainConfigPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Align(alignment: Alignment.center, child:
DeviceSelector(),),
Text(
'Key Configuration',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
Expand Down
4 changes: 4 additions & 0 deletions configurator/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "generated_plugin_registrant.h"

#include <flutter_libserialport/flutter_libserialport_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_libserialport_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterLibserialportPlugin");
flutter_libserialport_plugin_register_with_registrar(flutter_libserialport_registrar);
}
1 change: 1 addition & 0 deletions configurator/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
flutter_libserialport
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions configurator/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import flutter_libserialport

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLibserialportPlugin.register(with: registry.registrar(forPlugin: "FlutterLibserialportPlugin"))
}
2 changes: 2 additions & 0 deletions configurator/macos/Runner/DebugProfile.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.device.serial</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions configurator/macos/Runner/Release.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.serial</key>
<true/>
</dict>
</plist>
40 changes: 40 additions & 0 deletions configurator/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dylib:
dependency: transitive
description:
name: dylib
sha256: bf609b3eb6492a3309b3d1dbe8f83a4031de5535dd7686be33487051cc760bb0
url: "https://pub.dev"
source: hosted
version: "0.3.3"
fake_async:
dependency: transitive
description:
Expand All @@ -57,11 +65,27 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_libserialport:
dependency: "direct main"
description:
name: flutter_libserialport
sha256: "20c320dcde8592a16f9badc0cacad61b1fb283dbec647b6ebfc1020f8274c67b"
url: "https://pub.dev"
source: hosted
version: "0.4.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -99,6 +123,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
libserialport:
dependency: transitive
description:
name: libserialport
sha256: "392e1592def65282429832ec66fa25e9e163d3b37716b97691482e2406720727"
url: "https://pub.dev"
source: hosted
version: "0.3.0+1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -139,6 +171,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
sky_engine:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions configurator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
flutter_libserialport: ^0.4.0

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions configurator/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include "generated_plugin_registrant.h"

#include <flutter_libserialport/flutter_libserialport_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterLibserialportPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterLibserialportPlugin"));
}
1 change: 1 addition & 0 deletions configurator/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
flutter_libserialport
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit d167c05

Please sign in to comment.