parseRequest
The parseRequest API is called by the super app to handle data communication between the IAPMiniProgram SDK and Flutter pages (created with Widget
) during Native SPI calls. If you direct users to a Flutter page as part of handling Native SPI requests, the SDK passes the request data to the Flutter page as a string. Calling this API interprets the string data and converts it into a more manageable object for easier processing. Furthermore, this object includes a callback that sends the request result back to the SDK.
Note: To enable the parseRequest API to handle data properly, you must implement the Flutter page by mixing in the following abstract classes within the page's state class according to the specific method that triggers the page:
SPI | Method | Abstract class |
getAuthCode | IGetAuthCode | |
showAuthPage | IShowAuthPage | |
getAuthorizedScopes | IGetAuthorizedScopes | |
getMemberInfo | IGetMemberInfo | |
pay | IPay | |
scan | IScan |
Method signature
Future<void> parseRequest<T>(String data, T callback);
Request parameters
Field | Data type | Required | Description |
data | String | Yes | The data that the SDK passes to the Flutter page. |
callback | T | Yes | The callback that is executed when the processing of Native SPI method is completed. The callback corresponds to the abstract class that you mix into the page's state class. |
Response parameters
The response parameters correspond to the request parameters of the method that triggers the Flutter page. For more information, refer to the Request parameters sections under the SPI specifications.
Error codes
N/A
Sample
import 'package:flutter/material.dart';
import 'package:iap_mini_program/iap_mini_program.dart';
import 'package:iap_mini_program_example/utils/log_util.dart';
class AuthPage extends StatefulWidget {
final String? data;
const AuthPage({super.key, this.data});
@override
State<> createState() => _AuthPageState();
}
class _AuthPageState extends State<AuthPage> with IShowAuthPage {
late ShowAuthPageCallBack showAuthPageCallBack;
@override
void initState() {
super.initState();
IAPMiniProgram.instance.parseRequest<IShowAuthPage>(widget.data ?? '', this);
}
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: const Text('Auth'),
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
//Banner 681148
Container(
height: 20,
),
InkWell(
onTap: () async {
OAuthPageConfirmResult result = OAuthPageConfirmResult();
showAuthPageCallBack(result);
},
child: const Text(
'Agree Auth',
style: TextStyle(fontSize: 20),
),
),
],
),
));
}
@override
void showAuthPage(
String clientId,
String name,
String logo,
List<String> scopes,
APIContext apiContext,
ShowAuthPageCallBack resultCallBack,
{Map<String, String>? extendedInfo}) {
showAuthPageCallBack = resultCallBack;
}
}