Learn how to easily integrate Stripe payments into your Flutter app using the latest Flutter SDK, Firebase Functions, and Stripe API. This complete 2025 guide walks you through every step — with code!
1. ✅ Why Use Stripe in Flutter?
Stripe is one of the most powerful and developer-friendly payment platforms. For Flutter developers, it offers:
- Simple API
- Global currency support
- Webhooks, one-time & recurring payments
- PCI-compliant infrastructure
Whether you’re building a SaaS or selling in-app content, Stripe is your go-to payment gateway.
2. 🔧 What You’ll Need
- Flutter 3.10+
- Firebase project
- Stripe account
- Stripe API Keys
- Basic Flutter/Firebase knowledge
3. 🧾 Create a Stripe Account & API Keys
- Go to dashboard.stripe.com
- Create a free developer account
- Copy the Publishable key and Secret key from the API keys section
These keys will be used on the client (publishable) and backend (secret).
4. 🛠️ Set Up Flutter Project
Run the following in your terminal:
flutter create flutter_stripe_demo
cd flutter_stripe_demo
5. 📦 Add Stripe Dependencies
Add the following to your pubspec.yaml
:
dependencies:
flutter_stripe: ^10.0.0
firebase_core: ^3.0.0
cloud_functions: ^5.0.0
Run flutter pub get
to install packages.
Also, initialize Firebase in your main.dart
:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
6. ☁️ Create Firebase Cloud Function
We’ll use Firebase Functions to securely call Stripe’s secret key.
Install the Firebase CLI and initialize your project:
firebase init functions
cd functions
npm install stripe
Then update index.js
like this:
const functions = require("firebase-functions");
const stripe = require("stripe")("sk_test_..."); // Your secret key
exports.createPaymentIntent = functions.https.onCall(async (data, context) => {
const paymentIntent = await stripe.paymentIntents.create({
amount: data.amount, // In cents
currency: "usd",
});
return {
clientSecret: paymentIntent.client_secret,
};
});
Deploy your function:
firebase deploy --only functions
7. 📱 Write Flutter Client Code
Import required packages:
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:cloud_functions/cloud_functions.dart';
Then create a function to handle payments:
Future<void> makePayment(int amount) async {
final HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('createPaymentIntent');
final result = await callable.call(<String, dynamic>{
'amount': amount,
});
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: result.data['clientSecret'],
merchantDisplayName: 'FlutterTalk',
),
);
await Stripe.instance.presentPaymentSheet();
}
Trigger makePayment(5000)
for a $50 payment.
8. 🧪 Test Stripe Payments
Use these test card numbers:
Card Number | Result |
---|---|
4242 4242 4242 4242 | Success |
4000 0000 0000 9995 | Declined |
4000 0000 0000 0341 | Requires 3D Secure |
Full list: Stripe Testing Docs
9. 🌍 Go Live!
- Replace the secret key with a live version
- Change the Firebase function to use live keys
- Enable production mode in Stripe
- Test again before releasing
10. 🧠 Final Thoughts + Source Code
Congrats! 🎉 You’ve just integrated Stripe into Flutter. This is a powerful setup for:
- One-time payments
- Donations
- Product purchases
- Subscription setups (with slight modifications)
💬 FAQ
❓ Can I use Stripe with Flutter Web?
Yes! Stripe supports Flutter Web via the JS SDK but integration is slightly different.
❓ Is it safe to use Stripe in production?
Yes, as long as secret keys are secured on the backend (Firebase Functions or other).