PopupMenu for inspector
moved making property null to popup menu
MODIFY
packages/isar_inspector/lib/desktop/app.dart
packages/isar_inspector/lib/desktop/app.dart
@@ -28,10 +28,13 @@ class _AppState extends State<App> {
scaffoldBackgroundColor: Colors.transparent,
primaryColor: Colors.blue,
cardColor: const Color(0xff1f2128),
- dividerColor: const Color.fromARGB(255, 40, 41, 46),
+ dividerColor: Colors.grey,
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.all(Colors.blue),
),
+ popupMenuTheme: const PopupMenuThemeData(
+ color: Color.fromARGB(255, 40, 41, 46),
+ ),
buttonTheme: const ButtonThemeData(
alignedDropdown: true,
),

MODIFY
packages/isar_inspector/lib/edit_popup.dart
packages/isar_inspector/lib/edit_popup.dart
@@ -7,12 +7,10 @@ class EditPopup extends StatefulWidget {
super.key,
required this.type,
required this.value,
- required this.enableNull,
});
final IsarType type;
final dynamic value;
- final bool enableNull;
@override
State<EditPopup> createState() => _EditPopupState();
@@ -25,18 +23,13 @@ class _EditPopupState extends State<EditPopup> {
CustomTextInputFormatter? _inputFormatter;
bool? _boolValue;
- bool _null = false;
@override
void initState() {
- if (widget.enableNull && widget.value == null) {
- _null = true;
- }
-
if (widget.type == IsarType.Bool) {
- _boolValue = _null || widget.value as bool;
+ _boolValue = widget.value == null || widget.value as bool;
} else {
- _controller.text = _null ? '' : widget.value.toString();
+ _controller.text = widget.value == null ? '' : widget.value.toString();
_controller.selection = TextSelection(
baseOffset: 0,
extentOffset: _controller.text.length,
@@ -46,10 +39,8 @@ class _EditPopupState extends State<EditPopup> {
_inputFormatter = CustomTextInputFormatter(widget.type);
}
- if (!_null) {
_focus.requestFocus();
}
- }
super.initState();
}
@@ -61,20 +52,6 @@ class _EditPopupState extends State<EditPopup> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
- if (widget.enableNull) ...[
- CheckboxListTile(
- value: _null,
- title: const Text('NULL'),
- onChanged: (value) {
- if (value != null) {
- setState(() {
- _null = value;
- });
- }
- },
- ),
- const SizedBox(height: 15),
- ],
if (widget.type == IsarType.Bool)
DropdownButtonHideUnderline(
child: DropdownButton<bool>(
@@ -89,9 +66,7 @@ class _EditPopupState extends State<EditPopup> {
child: Text('FALSE'),
),
],
- onChanged: _null
- ? null
- : (value) {
+ onChanged: (value) {
if (value != null) {
setState(() {
_boolValue = value;
@@ -106,7 +81,6 @@ class _EditPopupState extends State<EditPopup> {
child: TextFormField(
controller: _controller,
focusNode: _focus,
- enabled: !_null,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
@@ -152,9 +126,6 @@ class _EditPopupState extends State<EditPopup> {
void _save() {
dynamic value;
- if (_null) {
- value = null;
- } else {
if (widget.type == IsarType.Bool) {
value = _boolValue;
} else {
@@ -177,7 +148,6 @@ class _EditPopupState extends State<EditPopup> {
return;
}
}
- }
Navigator.pop(context, {'value': value});
}

MODIFY
packages/isar_inspector/lib/query_table.dart
packages/isar_inspector/lib/query_table.dart
@@ -245,16 +245,8 @@ class _TableItemState extends State<TableItem> {
@override
Widget build(BuildContext context) {
return MouseRegion(
- onEnter: (_) {
- setState(() {
- _entered = true;
- });
- },
- onExit: (e) {
- setState(() {
- _entered = false;
- });
- },
+ onEnter: (_) => setState(() => _entered = true),
+ onExit: (_) => setState(() => _entered = false),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: Row(
@@ -267,11 +259,54 @@ class _TableItemState extends State<TableItem> {
)
: _createText(),
),
- if (_entered) ...[
+ if (_entered)
+ PopupMenuButton<dynamic>(
+ elevation: 20,
+ itemBuilder: (context) => [
+ PopupMenuItem<dynamic>(
+ onTap: _copy,
+ child: const PopUpMenuRow(
+ icon: Icon(Icons.copy, size: PopUpMenuRow.iconSize),
+ text: 'Copy to clipboard',
+ ),
+ ),
if (!widget.data.property.isId &&
- !widget.data.property.type.isList) ...[
- GestureDetector(
- onTap: () async {
+ !widget.data.property.type.isList)
+ PopupMenuItem<dynamic>(
+ onTap: () {
+ WidgetsBinding.instance
+ .addPostFrameCallback((_) => _edit());
+ },
+ child: const PopUpMenuRow(
+ icon: Icon(Icons.edit, size: PopUpMenuRow.iconSize),
+ text: 'Edit item',
+ ),
+ ),
+ if (widget.data.property.type.isList)
+ PopupMenuItem<dynamic>(
+ onTap: () => _setValue(<dynamic>[]),
+ child: const PopUpMenuRow(
+ text: 'Clear list',
+ ),
+ ),
+ if (!widget.data.property.isId && widget.data.value != null)
+ PopupMenuItem<dynamic>(
+ onTap: () => _setValue(null),
+ child: const PopUpMenuRow(
+ text: 'Set value to null',
+ ),
+ ),
+ ],
+ tooltip: 'Options',
+ child: const Icon(Icons.more_vert, size: 18),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Future<void> _edit() async {
final result = await showDialog<Map<String, dynamic>?>(
context: context,
builder: (context) {
@@ -279,30 +314,17 @@ class _TableItemState extends State<TableItem> {
content: EditPopup(
type: widget.data.property.type,
value: widget.data.value,
- enableNull: widget.data.index == null,
),
);
},
);
if (result != null) {
- widget.editor(
- widget.objectId,
- widget.data.property.name,
- widget.data.index,
- result['value'],
- );
+ await _setValue(result['value']);
}
- },
- child: const Tooltip(
- message: 'Edit property',
- child: Icon(Icons.edit, size: 18),
- ),
- ),
- const SizedBox(width: 10),
- ],
- GestureDetector(
- onTap: () async {
+ }
+
+ Future<void> _copy() async {
ScaffoldMessenger.of(context).removeCurrentSnackBar();
await Clipboard.setData(
@@ -326,18 +348,14 @@ class _TableItemState extends State<TableItem> {
),
);
}
- },
- child: const Center(
- child: Tooltip(
- message: 'Copy to clipboard',
- child: Icon(Icons.copy, size: 18),
- ),
- ),
- ),
- ],
- ],
- ),
- ),
+ }
+
+ Future<void> _setValue(dynamic value) async {
+ widget.editor(
+ widget.objectId,
+ widget.data.property.name,
+ widget.data.index,
+ value,
);
}
@@ -421,6 +439,26 @@ class _TableItemState extends State<TableItem> {
}
}
+class PopUpMenuRow extends StatelessWidget {
+ const PopUpMenuRow({super.key, this.icon, required this.text});
+
+ final Icon? icon;
+ final String text;
+
+ static const double iconSize = 18;
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ children: [
+ if (icon != null) icon! else const SizedBox(width: iconSize),
+ const SizedBox(width: 15),
+ Text(text, style: const TextStyle(fontSize: 15)),
+ ],
+ );
+ }
+}
+
class TreeViewHelper {
const TreeViewHelper({
required this.property,

MODIFY
packages/isar_inspector/lib/web/app.dart
packages/isar_inspector/lib/web/app.dart
@@ -56,10 +56,13 @@ class App extends StatelessWidget {
scaffoldBackgroundColor: Colors.transparent,
primaryColor: Colors.blue,
cardColor: const Color(0xff1f2128),
- dividerColor: const Color.fromARGB(255, 40, 41, 46),
+ dividerColor: Colors.grey,
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.all(Colors.blue),
),
+ popupMenuTheme: const PopupMenuThemeData(
+ color: Color.fromARGB(255, 40, 41, 46),
+ ),
buttonTheme: const ButtonThemeData(
alignedDropdown: true,
),

PopupMenu for inspector

moved making property null to popup menu