tijorat_id 0.0.6
tijorat_id: ^0.0.6 copied to clipboard
A complete authentication and OAuth package for Tijorat ID API.
import 'package:example/snackbar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tijorat_id/tijorat_id.dart' as tid;
void main()async{
WidgetsFlutterBinding.ensureInitialized();
tid.clientConfig("AiRZtvCY4LoGEailTRWVjPBfgZWWtd9n8jJ8dvH6", "pQiNM78OlLILM14K7zotpYoUaP8XjB4Ayhlmp8HuR2FhaF3pYhPtsMwvlJ41LhTQGjTmVgDJyLjt4G9jUFkNIfdHhUqYQVRiMSpXQosCKoI0osQY1XcPZuYE0mQXpVRt");
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Tijorat ID',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({ super.key });
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController phoneController = TextEditingController();
TextEditingController tijoratIDController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController firstNameController = TextEditingController();
TextEditingController otpController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar( title: const Text("Tijorat ID") ),
body: ListView(
children: [
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
ElevatedButton(onPressed: ()async {
String res = await tid.checkPhone(phoneController.text);
snackBar(res);
}, child: const Text("Check phone"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: tijoratIDController, decoration: const InputDecoration( hintText: "Tijorat ID" ) ),
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
TextField( controller: passwordController, decoration: const InputDecoration( hintText: "Password" ) ),
TextField( controller: firstNameController, decoration: const InputDecoration( hintText: "First name" ) ),
ElevatedButton(onPressed: () async{
Map res = await tid.register(tijoratIDController.text, phoneController.text, passwordController.text, firstNameController.text);
snackBar(res.toString());
}, child: const Text("Register User"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
ElevatedButton(onPressed: ()async{
String res = await tid.sendOTP(phoneController.text);
snackBar(res);
}, child: const Text("Send OTP"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
TextField( controller: otpController, decoration: const InputDecoration( hintText: "Code" ) ),
ElevatedButton(onPressed: ()async{
String res = await tid.verifyOTP(phoneController.text, otpController.text);
snackBar(res);
}, child: const Text("Verify OTP"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
TextField( controller: otpController, decoration: const InputDecoration( hintText: "Code" ) ),
TextField( controller: passwordController, decoration: const InputDecoration( hintText: "New Password" ) ),
ElevatedButton(onPressed: ()async{
String res = await tid.verifyPassResetOTP(phoneController.text, otpController.text, passwordController.text);
snackBar(res);
}, child: const Text("Verify Pass Reset OTP"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: phoneController, decoration: const InputDecoration( hintText: "phone number" ) ),
ElevatedButton(onPressed: ()async{
String res = await tid.sendPassResetOTP(phoneController.text);
snackBar(res);
}, child: const Text("Send Pass Reset OTP"))
],
),
),
Container(
padding: const EdgeInsets.all(10), margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black12),
child: Column(
children: [
TextField( controller: tijoratIDController, decoration: const InputDecoration( hintText: "Tijorat ID" ) ),
TextField( controller: passwordController, decoration: const InputDecoration( hintText: "Password" ) ),
ElevatedButton(onPressed: ()async{
dynamic res = await tid.loginUsingTijoratId(tijoratIDController.text, passwordController.text);
snackBar(res.toString());
}, child: const Text("Login Using Tijorat ID"))
],
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
Map result = await tid.getUserData();
debugPrint(result.toString());
},
child: const Icon(Icons.phone),
),
);
}
}