Ottu Flutter SDK containing repo
- In the merchant application go to the
pubspec.yaml
file and find the dependencies: tag. - Below that tag add dependency tag with
ottu_flutter_checkout:
name. - Below that dependency name add git dependency to the Flutter Ottu SDK with this url:
https://github.com/ottuco/ottu-flutter.git
- Run
flutter pub get
command
Please add the section below to your pubspec.yaml
file
dependencies:
flutter:
sdk: flutter
ottu_flutter_checkout:
#to use ottu_flutter_checkout sdk from the local source uncomment line below and comment 3 lines with git specification
#path: ../ottu_flutter_checkout
git:
url: https://github.com/ottuco/ottu-flutter.git
ref: main
For source samples please refer to Sample
folder.
All steps those you will find bellow have already been implemented in the Sample
app.
Here are steps to implement Ottu checkout widget from scratch:
- You have successfully setup the plugin that mentioned above.
- In your screen-widget override this method
@override void didChangeDependencies()
- Then in that method implement
MethodChannel.setMethodCallHandler()
withMETHOD_CHECKOUT_HEIGHT
method name. Seechackout_screen.dart
for instance in theSample
app. - Next, define
ValueNotifier<int>
property in a State class of a Widget. It is essential to handle the height change of the native view. - Now, in the
MethodCallHandler
handle callback of a native method and assignint
argument to theValueNotifier
- This step is to add
OttuCheckoutWidget
, so next decide a place on your screen where you want to show the checkout widget. - Wrap the
OttuCheckoutWidget
withSizedBox
other container widget, is just for checkout view constraint. - After, wrap the
SizedBox
withValueListenableBuilder<int>
and passint
argument of the handler to theSizedBox
as a height parameter. - Last, is to define arguments for
OttuCheckoutWidget
which described in the next chapter.
Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
SizedBox(height: 46),
Text(
"Customer Application",
textAlign: TextAlign.center,
style: ts.TextStyle(fontSize: 24),
),
//Start of Merchant content
const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"Some users UI elements, Some users UI elements, Some users UI elements, Some users UI elements, Some users UI elements")),
//End of Merchant content
Padding(
padding: const EdgeInsets.all(12.0),
child: ValueListenableBuilder<int>(
builder: (BuildContext context, int height, Widget? child) {
return SizedBox(
height: height.toDouble(),
child: OttuCheckoutWidget(arguments: widget.checkoutArguments),
);
},
valueListenable: _checkoutHeight,
),
),
const SizedBox(height: 20),
//Start of Merchant content
const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"Some users UI elements, Some users UI elements, Some users UI elements, Some users UI elements, Some users UI elements,"
" Some users UI elements, Some users UI elements, Some users UI elements,"
" Some users UI elements, Some users UI elements, Some users UI elements")),
//End of Merchant content
])), // This trailing comma makes auto-formatting nicer for build methods.
);
Below you may find sample of CheckoutArguments
initialisation that requires OttuCheckoutWidget
.
You may find this sample in the home_screen_cubit.dart
at onPay
method.
final checkoutArguments = CheckoutArguments(
merchantId: state.merchantId,
apiKey: state.apiKey,
sessionId: state.sessionId ?? "",
amount: amount,
showPaymentDetails: state.showPaymentDetails,
apiTransactionDetails: state.preloadPayload == true ? _apiTransactionDetails : null,
formsOfPayment: formOfPayments?.isNotEmpty == true ? formOfPayments : null,
theme: _theme);
Please note that the callbacks are native (Android/iOS). They can be found in the following files:
- Android:
https://github.com/ottuco/ottu-flutter/blob/main/android/src/main/kotlin/com/ottu/flutter/checkout/CheckoutView.kt
- iOS:
https://github.com/ottuco/ottu-flutter/blob/main/ios/ottu_flutter_checkout/Sources/ottu_flutter_checkout/CheckoutPlatformView.swift