Setting key using a variable in FF Custom Data Types (similar to Firestore Map)

Database & APIs

I'm trying to build a coupon system for my ecommerce app. I want to be able to keep track of how many times a coupon has been used by each user. For this, I'm trying to figure out the appropriate Firestore collections architecture.

My ideal scenario would be to have a key-value pair user_uses inside the collection coupons where the key is the user_id and the value is an integer denoting the number of times that coupon has been used by that user.

This is what Firestore allows. Here "userId1" and "userId2" can be replaced with actual User IDs.

Flutterflow documentation describes Custom DataType as being similar to Firestore Map. However, I'm able to specify a custom key in the Firestore Map K-V pair but I cannot figure out how to do this in Flutterflow, if it is possible.

Flutterflow asks for the "Field Name" beforehand and doesn't allow to set it dynamically.

If this is not possible, then the alternative I can think of is to create a separate collection having fields "coupon_code", "user_id" and "count" but searching through this collection for every coupon individually would be very expensive.

Therefore, can we implement a Map like setup in FF with custom key value (like custom document ID that FF supports now)?

What have you tried so far?

I've tried to create custom data types in FF via multiple ways - as a list of docs, individually, etc.

Did you check FlutterFlow's Documentation for this topic?
Yes
3 replies