Skip to main content
RapidDev - Software Development Agency
flutterflow-tutorials

How to Create a Dynamic Pricing Model in FlutterFlow

Build dynamic pricing in FlutterFlow by creating a Cloud Function pricing engine that reads pricing_rules from Firestore (conditions like time of day, user tier, demand level) and calculates the final price by stacking applicable rules. Call the Cloud Function from FlutterFlow's API Manager when the user views a product or initiates checkout. Display the original price with strikethrough alongside the calculated dynamic price and a reason label.

What you'll learn

  • How to design a Firestore pricing_rules data structure for flexible rule management
  • How to build a Cloud Function pricing engine that stacks multiple pricing rules
  • How to display dynamic prices in FlutterFlow with strikethrough original price and savings badge
  • How to implement user-tier pricing so VIP and wholesale users see different prices
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner10 min read1-2 hoursFlutterFlow Free+ with Firebase (Cloud Functions for pricing engine)March 2026RapidDev Engineering Team
TL;DR

Build dynamic pricing in FlutterFlow by creating a Cloud Function pricing engine that reads pricing_rules from Firestore (conditions like time of day, user tier, demand level) and calculates the final price by stacking applicable rules. Call the Cloud Function from FlutterFlow's API Manager when the user views a product or initiates checkout. Display the original price with strikethrough alongside the calculated dynamic price and a reason label.

Dynamic pricing without rebuilding your app for every price change

Static prices hardcoded in your app require an app update to change. Dynamic pricing reads rules from Firestore at runtime, so you can adjust prices, add surge multipliers, or create flash sales by updating a database record — no app update, no code change. This tutorial builds a pricing engine: a pricing_rules Firestore collection defines the conditions and multipliers, a Cloud Function evaluates all applicable rules and returns the final price, and FlutterFlow displays the result with a clear explanation for the user. Common patterns covered: time-based surge pricing (peak hours cost more), user-tier pricing (wholesale customers get 20% off), and demand-based pricing (price increases when inventory is low).

Prerequisites

  • FlutterFlow project with Firebase Firestore and Cloud Functions enabled
  • Firebase Blaze (pay-as-you-go) plan for Cloud Functions
  • Firebase Authentication so user tier can be looked up
  • Basic understanding of FlutterFlow's API Manager and Action Flows

Step-by-step guide

1

Design the pricing_rules Firestore collection

In FlutterFlow's Firestore panel, create a collection named pricing_rules. Each document represents one pricing rule with these fields: ruleId (String, auto-generated), productId (String, or 'all' for global rules), ruleType (String: 'time_based', 'user_tier', 'demand_based', 'flash_sale'), conditions (Map: stores the rule's trigger conditions), multiplier (Double: 1.0 = no change, 0.8 = 20% discount, 1.5 = 50% surge), description (String: user-facing explanation like 'Peak demand pricing'), isActive (Boolean: toggle rules on/off without deleting them), priority (Integer: rules evaluated in priority order, higher number wins). Example time-based rule: {ruleType: 'time_based', conditions: {startHour: 17, endHour: 20, daysOfWeek: [1,2,3,4,5]}, multiplier: 1.3, description: 'Evening peak hours'}. Manage rules directly in FlutterFlow's Content Manager without touching code.

Expected result: The pricing_rules collection is configured with documents representing each pricing scenario you want to support.

2

Build the Cloud Function pricing engine

Create a Cloud Function named calculatePrice that accepts productId, userId, and basePrice. The function: (1) fetches the user's tier from Firestore users/{userId}, (2) queries active pricing_rules for the product (productId == productId OR productId == 'all'), (3) evaluates each rule's conditions against the current context (current time, user tier, current inventory), (4) applies applicable rules by multiplying the base price by each rule's multiplier, (5) returns the final price, the applied rules array, and a human-readable explanation. In FlutterFlow's API Manager, create an API Group pointing to your Cloud Functions base URL and add a calculatePrice endpoint. When a user views a product or opens the cart, call this endpoint with the product's base price and the current user's UID.

functions/pricing.js
1// Cloud Function: calculatePrice
2const admin = require('firebase-admin');
3
4exports.calculatePrice = async (req, res) => {
5 const { productId, userId, basePrice } = req.body;
6 const now = new Date();
7
8 // Get user tier
9 const userDoc = await admin.firestore()
10 .doc(`users/${userId}`).get();
11 const userTier = userDoc.data()?.tier || 'standard';
12
13 // Get active rules for this product
14 const rulesSnap = await admin.firestore()
15 .collection('pricing_rules')
16 .where('isActive', '==', true)
17 .get();
18
19 let finalPrice = parseFloat(basePrice);
20 const appliedRules = [];
21
22 for (const ruleDoc of rulesSnap.docs) {
23 const rule = ruleDoc.data();
24
25 // Skip if rule is for a different product
26 if (rule.productId !== 'all'
27 && rule.productId !== productId) continue;
28
29 let applies = false;
30
31 if (rule.ruleType === 'time_based') {
32 const hour = now.getHours();
33 const day = now.getDay();
34 const { startHour, endHour, daysOfWeek } = rule.conditions;
35 applies = hour >= startHour && hour < endHour
36 && (!daysOfWeek || daysOfWeek.includes(day));
37 } else if (rule.ruleType === 'user_tier') {
38 applies = rule.conditions.tiers.includes(userTier);
39 } else if (rule.ruleType === 'flash_sale') {
40 const start = rule.conditions.startTime.toDate();
41 const end = rule.conditions.endTime.toDate();
42 applies = now >= start && now <= end;
43 }
44
45 if (applies) {
46 finalPrice *= rule.multiplier;
47 appliedRules.push(rule.description);
48 }
49 }
50
51 res.json({
52 finalPrice: Math.round(finalPrice * 100) / 100,
53 basePrice: parseFloat(basePrice),
54 savings: Math.max(0,
55 Math.round((basePrice - finalPrice) * 100) / 100),
56 appliedRules,
57 priceReason: appliedRules[0] || null,
58 });
59};

Expected result: The pricing engine returns a calculated final price with explanation of which rules applied.

3

Call the pricing engine from FlutterFlow

In FlutterFlow's API Manager, add an API Call to your Cloud Function endpoint. Set Method to POST, add the endpoint path (/calculatePrice), and set the request body to JSON with productId, userId (bind to Current User UID from Authenticated User global property), and basePrice (bind to the product's price field from your Backend Query result). In the Response & Test tab, extract these fields: finalPrice (Double), basePrice (Double), savings (Double), priceReason (String). On your product page, add a Backend Query fetching the product. In the page's On Page Load action, call the calculatePrice API Call and store the result in Page State variables. Display the dynamic price in the main price Text widget. Only show the original price with strikethrough if finalPrice differs from basePrice.

Expected result: Product pages display calculated dynamic prices based on current time, user tier, and active promotional rules.

4

Display dynamic pricing UI with original price and savings badge

Create a price display Container with three elements stacked vertically: (1) a Row with the original price Text (conditionally visible when savings > 0, styled with a strikethrough decoration by using a Custom Function to format as plain text with the product page state savings > 0 as the visibility condition, or use a Custom Widget for strikethrough text), (2) the dynamic price Text in a large bold font with your primary color, (3) a Container badge (background: green, rounded corners) containing a Text like 'Save $12.50' bound to the savings value from the pricing API response (conditionally visible when savings > 0). Below the price, show a small italic Text bound to the priceReason field (e.g., 'VIP member discount' or 'Evening peak pricing'). This transparency builds trust and reduces cart abandonment from price surprise.

Expected result: Product pages show original price crossed out, dynamic price prominently, savings amount, and a human-readable price reason.

5

Create an admin screen to manage pricing rules

Add an admin-only page in FlutterFlow for managing pricing rules without developer involvement. Add a ListView bound to the pricing_rules collection (Backend Query). Each list item shows: rule description, ruleType, multiplier formatted as a percentage, and an on/off Switch bound to the isActive field. The Switch's onChange action calls Update Document on the pricing rule document, setting isActive to the new switch value. Add a FAB (Floating Action Button) that navigates to a Create Rule page with a Form containing all rule fields as inputs. Protect this page with a Conditional widget that checks if the current user's role field equals 'admin' — redirect non-admins to the home page. With this admin screen, your marketing team can activate flash sales, adjust surge pricing windows, and create user-tier discounts without touching FlutterFlow.

Expected result: Admins can toggle pricing rules on and off and create new rules from a FlutterFlow admin screen.

Complete working example

dynamic_pricing_architecture.txt
1Dynamic Pricing Architecture for FlutterFlow
2
3FIRESTORE SCHEMA:
4 pricing_rules/{ruleId}
5 ruleId: String (auto)
6 productId: String ('all' or specific ID)
7 ruleType: 'time_based' | 'user_tier'
8 | 'demand_based' | 'flash_sale'
9 conditions: Map {
10 // time_based:
11 startHour: 17, endHour: 20
12 daysOfWeek: [1,2,3,4,5]
13 // user_tier:
14 tiers: ['wholesale', 'vip']
15 // flash_sale:
16 startTime: Timestamp, endTime: Timestamp
17 }
18 multiplier: Double (0.8 = 20% off, 1.3 = 30% up)
19 description: 'Evening peak hours'
20 isActive: Boolean
21 priority: Integer
22
23CLOUD FUNCTION FLOW:
24 calculatePrice(productId, userId, basePrice)
25 1. Fetch user tier from Firestore
26 2. Query active pricing_rules
27 3. For each rule:
28 - Check productId matches
29 - Evaluate conditions vs current context
30 - If applies: multiply finalPrice
31 4. Return: finalPrice, savings, priceReason
32
33FLUTTERFLOW PAGE FLOW:
34 On Page Load:
35 1. Backend Query load product (basePrice)
36 2. API Call calculatePrice
37 3. Store in Page State:
38 - dynamicPrice (Double)
39 - savings (Double)
40 - priceReason (String)
41 UI:
42 [strikethrough original price if savings > 0]
43 [bold dynamic price]
44 [green badge: 'Save $X.XX' if savings > 0]
45 [italic reason label]

Common mistakes when creating a Dynamic Pricing Model in FlutterFlow

Why it's a problem: Showing a surge price with no explanation to the user

How to avoid: Always display the priceReason alongside the dynamic price. 'Evening peak demand' or 'High demand — limited availability' explains the price increase. Users who understand the reason are significantly more likely to complete the purchase.

Why it's a problem: Applying dynamic prices only on the product page but not recalculating at checkout

How to avoid: Always recalculate the price in the Cloud Function at checkout time before charging. Compare the displayed price with the recalculated price — if they differ by more than a small threshold, show the user the updated price and ask for confirmation before processing payment.

Why it's a problem: Doing pricing calculations in the FlutterFlow app (client-side) instead of a Cloud Function

How to avoid: Always calculate final prices in a Cloud Function. The Cloud Function is the source of truth for pricing. Your payment charge should use the Cloud Function's returned price, not a value entered or calculated by the client.

Best practices

  • Store all pricing rules in Firestore so non-technical team members can manage them without code changes — add a simple admin screen as shown in Step 5
  • Log every pricing calculation to a price_events collection (productId, userId, basePrice, finalPrice, appliedRules, timestamp) for auditing and dispute resolution
  • Always show the original price with strikethrough when a discount applies — seeing the crossed-out higher price increases conversion
  • Cap surge pricing at a maximum multiplier (e.g., 2.0x) and communicate the cap in your terms of service to avoid regulatory issues
  • Test pricing rules in a staging environment with a test user account before activating them in production
  • Cache pricing calculations in Page State for 5 minutes — recalculating on every scroll is unnecessary and adds Cloud Function latency
  • Use Firebase Remote Config for emergency price overrides that take effect in under a minute without a Cloud Function redeployment

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I am building a FlutterFlow app with dynamic pricing. Write me a Firebase Cloud Function in Node.js that implements a pricing engine. The function accepts productId, userId, and basePrice. It should: (1) look up the user's tier (standard/vip/wholesale) from Firestore, (2) query the pricing_rules collection for active rules matching the product, (3) evaluate time-based rules (check current hour and day of week), user-tier rules, and flash sale rules with start/end timestamps, (4) apply each matching rule's multiplier to the base price, and (5) return finalPrice, savings amount, and a priceReason string explaining which rule applied.

FlutterFlow Prompt

Create a product price display component in FlutterFlow. The component should show the original price with a strikethrough decoration when savings are greater than zero, display the dynamic final price in large bold text using my primary theme color, show a green rounded badge with the savings amount (formatted as 'Save $12.50') when savings are greater than zero, and display a small italic text below the price explaining the reason for the dynamic price. All values should be bound to Page State variables dynamicPrice, originalPrice, savings, and priceReason.

Frequently asked questions

Is dynamic pricing legal in all markets?

Dynamic pricing is legal in most markets for general goods and services. Restrictions apply in: utilities and essential services (regulated pricing), healthcare (surprise billing laws in some US states), and real estate. Some jurisdictions require disclosure that prices may vary (e.g., EU digital markets act). Surge pricing during declared emergencies is illegal in many US states. Always review local pricing regulations for your specific industry and market.

Can dynamic pricing hurt customer trust and conversions?

Unexplained price variation can damage trust. Explained price variation — 'VIP member discount applied' or 'Flash sale: ends in 2 hours' — typically increases conversions. Research shows that visible discounts from original prices (strikethrough + badge) increase purchase rates by 10-25%. The key is transparency: always show both the original and dynamic price and explain why the price changed.

How do I prevent users from gaming my pricing rules?

Calculate prices server-side in Cloud Functions where users cannot inspect or modify the logic. For time-based rules, use server time in the Cloud Function, not the user's device time (which can be changed). For user-tier pricing, fetch the tier from a server-side Firestore document the user cannot write to. For demand-based pricing, calculate inventory levels server-side from admin-controlled data.

How do I handle dynamic pricing for subscriptions vs one-time purchases?

For subscriptions, apply dynamic pricing at the subscription creation step (Stripe price ID selection) and honor that rate for the entire billing cycle — do not change a subscriber's price mid-cycle without notice. For one-time purchases, recalculate at each checkout. Log the price at purchase time in your orders collection so customer service can see exactly what price was charged and why.

What analytics should I track for a dynamic pricing model?

Track: which pricing rules fired most frequently, conversion rates with and without each rule active, average order value by rule combination, cart abandonment rate by price tier, and customer lifetime value by acquisition price. Store pricing rule applications in a price_events Firestore collection for custom analysis. This data lets you optimize which rules actually improve revenue versus which just confuse customers.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.