-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add serial device selector badge
- Loading branch information
1 parent
8c3c288
commit d167c05
Showing
13 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
|
||
list(APPEND FLUTTER_PLUGIN_LIST | ||
flutter_libserialport | ||
) | ||
|
||
list(APPEND FLUTTER_FFI_PLUGIN_LIST | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
|
||
list(APPEND FLUTTER_PLUGIN_LIST | ||
flutter_libserialport | ||
) | ||
|
||
list(APPEND FLUTTER_FFI_PLUGIN_LIST | ||
|