Invite others to view and contribute to your collection while ensuring that only authorized users have access to your valuable digital content.
This Flutter application demonstrates how to seamlessly integrate the Unkey API to generate and validate coupon codes for a custom coffee shop. It enables users to obtain unique discount codes, ensuring a smooth checkout experience while managing the codes securely through the Unkey API.
For demonstration purposes, I've included a feature that generates a coupon with a randomized discount. Users can easily create one by clicking the discount icon located on a coffee card within the shop page. Each coupon generated comes with a predefined lifespan, which is controlled by the configurable COUPON_DURATION
variable. This allows for flexible expiration times based on business requirements.
Once users have added their desired drinks to the cart, they can apply their coupon before proceeding to checkout. After clicking "Pay Now," the system simulates a successful payment. However, since this app is designed as a demonstration, I have not integrated any actual payment services. Instead, this example focuses on showcasing how to build a Flutter mobile app that integrates Unkey's API for secure and effective coupon validation.
Click here to view a full walkthrough of the Coffee Shop app in action, showcasing how to generate and validate coupon codes.
create_key
read_key
encrypt_key
decrypt_key
If you haven't installed the Flutter SDK on your macOS yet, you can follow the official setup guide here. This comprehensive guide walks you through everything you need to install Flutter, configure Xcode, and prepare your machine for iOS development with ease.
Clone the repository to your local machine:
1git clone git@github.com:unrenamed/unkey-coffee-shop2cd unkey-coffee-shop
Open your terminal and navigate to the project directory.
Create a .env
file in the root directory and populate it with the following environment variables:
1UNKEY_ROOT_KEY=your-unkey-root-key2UNKEY_API_ID=your-unkey-api-id3COUPON_DURATION=2m
Ensure you replace your-unkey-*
with your actual Unkey credentials.
COUPON_DURATION
supports duration in 10m
, 24h
, 5d
, 1w
, etc. formats.
Run the following command to get the necessary packages:
1flutter pub get
Launch the iOS simulator:
1open -a Simulator
Now, you can run the app:
1flutter run
If you use VSCode for coding, you can run the app by clicking Run
above the main function in lib/main.dart.
Once the app is running, you can test coupon generation and validation through the provided UI.
2500 verifications and 100K successful rate‑limited requests per month. No CC required.