Flutter网络请求优化插件okhi_flutter的使用
Flutter网络请求优化插件okhi_flutter的使用
1hi Flutter
OkHi Flutter 是一个官方库,可以帮助您开始收集和验证用户的地址。
文档和API参考
示例代码
import 'package:flutter/material.dart';
import 'package:okhi_flutter/models/okhi_usage_type.dart';
import 'package:okhi_flutter/okhi_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _launch = false;
[@override](/user/override)
void initState() {
super.initState();
final config = OkHiAppConfiguration(
branchId: "<my_branch_id>",
clientKey: "<my_client_key_id>",
env: OkHiEnv.prod,
notification: OkHiAndroidNotification(
title: "Verification in progress",
text: "Verifying your address",
channelId: "okhi",
channelName: "OkHi",
channelDescription: "Verification alerts",
),
);
OkHi.initialize(config).then((value) => print("init done"));
}
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('OkHi Flutter Demo'),
),
body: _renderBody(),
),
);
}
_renderBody() {
if (!_launch) {
return Center(
child: ElevatedButton(
onPressed: () {
setState(() {
_launch = true;
});
},
child: const Text('Verify an address'),
),
);
}
return OkHiLocationManager(
user: _createOkHiUser(),
onCloseRequest: _handleOnClose,
onError: _handleOnError,
onSucess: _handleOnSuccess,
configuration: OkHiLocationManagerConfiguration(
usageTypes: [UsageType.digitalVerification],
),
);
}
OkHiUser _createOkHiUser() {
return OkHiUser(
phone: "+2547..",
firstName: "John",
lastName: "Doe",
appUserId: "abcd134",
email: "john@okhi.co",
);
}
_handleOnSuccess(OkHiLocationManagerResponse response) async {
setState(() {
_launch = false;
});
final String locationId = await response.startVerification(null);
print("started verification for $locationId");
}
_handleOnError(OkHiException exception) {
print(exception.code);
print(exception.message);
}
_handleOnClose() {
setState(() {
_launch = false;
});
}
}
更多关于Flutter网络请求优化插件okhi_flutter的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复