$ in the property name eror in the objectbox.g.dart file
Closed this issue · 2 comments
Is there an existing issue?
- I have searched existing issues
Build info
- objectbox version: 2.5.1
- Flutter/Dart version: Flutter 3.19.4 Dart 3.3.2
- Build OS: MacOS 14.4.1
- Deployment OS or device: Android 13
Steps to reproduce
just create an entity with a $ at the beginning of one of its properties:
class Plan {
@Id()
int id;
@Unique()
String $uid;
String name;
}
Expected behavior
Generated objectbox.g.dart file with correct escaping like
obx_int.ModelProperty(
id: const obx_int.IdUid(2, 2870122101975113894),
name: '\$id',
type: 9,
flags: 2080,
indexId: const obx_int.IdUid(1, 6518471420466642677)
)
Actual behavior
Generated code does not have character escaping:
obx_int.ModelProperty(
id: const obx_int.IdUid(2, 2870122101975113894),
name: '$id',
type: 9,
flags: 2080,
indexId: const obx_int.IdUid(1, 6518471420466642677)
)
Code
Logs, stack traces
VSCode show the message on file: Undefined name 'id'. Try correcting the name to one that is defined, or defining the name.
Thanks for reporting! I'm surprised this is allowed, especially as you have shown it conflicts with the template dollar-sign syntax.
I can't really find any official guidance on allowed characters for variable names (except _
for private visibility), do you know any? A Stack Overflow answer hints that the dollar-sign is reserved for generated code. Still, the generator should maybe support this.
So, im using objectbox with appwrite, and in appwrite the document ID are with $ on begin.
But, I create one new model with docId to avoid conflicts.