accept negative numbers in inspector
better text input formatter
fix bug in listview
MODIFY
packages/isar_inspector/lib/collections.dart
packages/isar_inspector/lib/collections.dart
@@ -24,6 +24,7 @@ class CollectionsList extends ConsumerWidget {
final selectedInstance = ref.watch(selectedInstancePod).value!;
return ListView.builder(
+ primary: false,
itemBuilder: (BuildContext context, int index) {
final collection = collections.elementAt(index);
final info = collectionInfo[collection.name];

MODIFY
packages/isar_inspector/lib/common.dart
packages/isar_inspector/lib/common.dart
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:isar/isar.dart';
+import 'package:isar_inspector/schema.dart';
class IsarCard extends StatelessWidget {
IsarCard({
@@ -85,3 +88,65 @@ class CheckBoxLabel extends StatelessWidget {
);
}
}
+
+class CustomTextInputFormatter extends TextInputFormatter {
+ CustomTextInputFormatter(this.type) {
+ if (type == IsarType.Byte) {
+ _callback = _byte;
+ } else if (type == IsarType.Long || type == IsarType.Int) {
+ _callback = _int;
+ } else if (type == IsarType.Double || type == IsarType.Float) {
+ _callback = _double;
+ } else {
+ throw IsarError('new IsarType (${type.name}), rule not defined');
+ }
+ }
+
+ final IsarType type;
+ late TextEditingValue Function(TextEditingValue, TextEditingValue) _callback;
+
+ @override
+ TextEditingValue formatEditUpdate(
+ TextEditingValue oldValue,
+ TextEditingValue newValue,
+ ) {
+ return _callback(oldValue, newValue);
+ }
+
+ TextEditingValue _byte(
+ TextEditingValue oldValue,
+ TextEditingValue newValue,
+ ) {
+ if (newValue.text.isEmpty ||
+ newValue.text.length <= 3 && int.tryParse(newValue.text) != null) {
+ return newValue;
+ }
+ return oldValue;
+ }
+
+ TextEditingValue _int(
+ TextEditingValue oldValue,
+ TextEditingValue newValue,
+ ) {
+ if (newValue.text.isEmpty ||
+ (newValue.text.length == 1 && newValue.text == '-') ||
+ int.tryParse(newValue.text) != null) {
+ return newValue;
+ }
+
+ return oldValue;
+ }
+
+ TextEditingValue _double(
+ TextEditingValue oldValue,
+ TextEditingValue newValue,
+ ) {
+ if (newValue.text.isEmpty ||
+ (newValue.text.length == 1 && newValue.text == '-') ||
+ double.tryParse(newValue.text) != null) {
+ return newValue;
+ }
+
+ return oldValue;
+ }
+}

MODIFY
packages/isar_inspector/lib/edit_popup.dart
packages/isar_inspector/lib/edit_popup.dart
import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-import 'package:isar/isar.dart';
+import 'package:isar_inspector/common.dart';
import 'package:isar_inspector/schema.dart';
class EditPopup extends StatefulWidget {
@@ -23,7 +22,7 @@ class _EditPopupState extends State<EditPopup> {
final _formKey = GlobalKey<FormState>();
final _controller = TextEditingController();
final _focus = FocusNode();
- RegExp? _re;
+ CustomTextInputFormatter? _inputFormatter;
bool? _boolValue;
bool _null = false;
@@ -43,16 +42,8 @@ class _EditPopupState extends State<EditPopup> {
extentOffset: _controller.text.length,
);
- if ([IsarType.Float, IsarType.Double].contains(widget.type)) {
- _re = RegExp(r'^(\d+)?\.?\d*$');
- } else if ([IsarType.Int, IsarType.Long].contains(widget.type)) {
- _re = RegExp(r'^\d*$');
- } else if (widget.type == IsarType.Byte) {
- _re = RegExp(r'^\d{0,3}$');
- } else if (widget.type == IsarType.String) {
- _re = null;
- } else {
- throw IsarError('new IsarType (${widget.type.name}), rule not defined');
+ if (widget.type != IsarType.String) {
+ _inputFormatter = CustomTextInputFormatter(widget.type);
}
if (!_null) {
@@ -127,7 +118,7 @@ class _EditPopupState extends State<EditPopup> {
contentPadding: const EdgeInsets.all(20),
),
inputFormatters: [
- if (_re != null) FilteringTextInputFormatter.allow(_re!)
+ if (_inputFormatter != null) _inputFormatter!
],
maxLines: widget.type == IsarType.String ? 3 : 1,
validator: (value) {

MODIFY
packages/isar_inspector/lib/query_builder.dart
packages/isar_inspector/lib/query_builder.dart
import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:isar/isar.dart';
import 'package:isar_inspector/common.dart';
@@ -506,8 +505,8 @@ class _ConditionUIState extends State<_ConditionUI> {
contentPadding: const EdgeInsets.all(20),
),
inputFormatters: [
- if (widget.helper.textRe != null)
- FilteringTextInputFormatter.allow(widget.helper.textRe!)
+ if (widget.helper.textFormatter != null)
+ widget.helper.textFormatter!
],
style: GoogleFonts.sourceCodePro(),
),
@@ -686,7 +685,7 @@ class _ConditionHelper extends QueryBuilderUIHelper {
}
}
- RegExp? get textRe {
+ CustomTextInputFormatter? get textFormatter {
switch (property.type) {
case IsarType.String:
case IsarType.StringList:
@@ -698,17 +697,17 @@ class _ConditionHelper extends QueryBuilderUIHelper {
case IsarType.LongList:
case IsarType.Int:
case IsarType.Long:
- return RegExp(r'^\d*$');
+ return CustomTextInputFormatter(IsarType.Int);
case IsarType.ByteList:
case IsarType.Byte:
- return RegExp(r'^\d{0,3}$');
+ return CustomTextInputFormatter(IsarType.Byte);
case IsarType.FloatList:
case IsarType.DoubleList:
case IsarType.Float:
case IsarType.Double:
- return RegExp(r'^(\d+)?\.?\d*$');
+ return CustomTextInputFormatter(IsarType.Double);
}
}

MODIFY
packages/isar_inspector/lib/query_table.dart
packages/isar_inspector/lib/query_table.dart
@@ -43,7 +43,7 @@ class QueryTable extends ConsumerWidget {
children: [
Expanded(
child: ListView.separated(
- controller: ScrollController(),
+ primary: true,
itemCount: objects.length,
itemBuilder: (context, index) {
return Stack(

accept negative numbers in inspector

better text input formatter
fix bug in listview