Checkout Flow
Loading preview
Starting the Flutter app
Stepper-based checkout - shipping, payment, order summary
import 'package:flutter/material.dart';
class CheckoutPage extends StatefulWidget {
const CheckoutPage({super.key});
@override
State<CheckoutPage> createState() => _CheckoutPageState();
}
class _CheckoutPageState extends State<CheckoutPage> {
var _step = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Checkout')),
body: Stepper(
currentStep: _step,
onStepContinue: () =>
setState(() => _step = (_step + 1).clamp(0, 2)),
onStepCancel: () =>
setState(() => _step = (_step - 1).clamp(0, 2)),
steps: [
Step(
title: const Text('Shipping'),
content: Column(
children: [
TextField(
decoration: const InputDecoration(
labelText: 'Address',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextField(
decoration: const InputDecoration(
labelText: 'City',
border: OutlineInputBorder(),
),
),
],
),
),
Step(
title: const Text('Payment'),
content: TextField(
decoration: const InputDecoration(
labelText: 'Card Number',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
),
),
Step(
title: const Text('Summary'),
content: const Text('Order total: \$75.98'),
),
],
),
);
}
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Material’s Stepper walks through Shipping, Payment and Summary using one int, _step. onStepContinue and onStepCancel move it with clamp(0, 2), so pressing Continue on Summary has no effect. The TextFields have no controllers or validation, which means nothing reads what the user types, and the $75.98 order total is a fixed string.
Adapting it
- Add a
TextEditingControllerper field, or aFormper step, and validate insideonStepContinuebefore advancing. - Check for
_step == 2inonStepContinueand place the order there. - Collect card details through your payment provider’s SDK rather than the plain
Card Numberfield.