Flutter身份验证插件gst_verification的使用
Flutter身份验证插件gst_verification的使用
gst_verification
是一个用于在Flutter应用中验证GST号码的新插件。本文将详细介绍如何使用该插件进行GST号码验证。
获取开始
注册获取 key_secret
要使用此插件,您需要从 Appyflow Technologies 获取一个 key_secret
。请访问以下链接注册并获取您的 key_secret
:
插件功能
该插件允许您通过提供GST号码和 key_secret
来获取与该GST号码相关的详细信息。
示例代码
以下是完整的示例代码,展示了如何在Flutter应用中集成和使用 gst_verification
插件。
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:gst_verification/gst_verification.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String gstNo, keySecret, response = '';
double valueOp = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('GST Verification Example App'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
textCapitalization: TextCapitalization.words,
style: TextStyle(fontSize: 16.0, color: Colors.black),
maxLines: 1,
onChanged: (value) {
gstNo = value;
},
decoration: InputDecoration(
labelText: "GST Number *",
labelStyle: TextStyle(fontSize: 16.0, color: Colors.grey),
),
),
SizedBox(height: 20),
TextField(
textCapitalization: TextCapitalization.words,
style: TextStyle(fontSize: 16.0, color: Colors.black),
maxLines: 1,
onChanged: (value) {
keySecret = value;
},
decoration: InputDecoration(
labelText: "Key Secret *",
labelStyle: TextStyle(fontSize: 16.0, color: Colors.grey),
),
),
SizedBox(height: 20),
Text(response),
Opacity(opacity: valueOp, child: CircularProgressIndicator()),
SizedBox(height: 20),
RaisedButton(
onPressed: verifyGSTNumber,
color: Colors.blue,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Verify GST',
style: TextStyle(color: Colors.white),
),
),
)
],
),
),
),
),
);
}
void verifyGSTNumber() {
print('$gstNo , $keySecret');
valueOp = 1;
setState(() {});
GstVerification.verifyGST(gstNo: gstNo, key_secret: keySecret)
.then((result) {
JsonEncoder encoder = new JsonEncoder.withIndent(' ');
String prettyPrint = encoder.convert(result);
print(prettyPrint);
response = "JSON Response:\n\n" + prettyPrint;
print(response);
valueOp = 0;
setState(() {});
}).catchError((error) {
print(error);
valueOp = 0;
setState(() {});
});
}
}
使用方法
- 导入插件:确保在您的
pubspec.yaml
文件中添加gst_verification
依赖。dependencies: flutter: sdk: flutter gst_verification: ^latest_version
更多关于Flutter身份验证插件gst_verification的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复