singularity_flutter 1.5.0 singularity_flutter: ^1.5.0 copied to clipboard
A Flutter plugin for Singularity. It provide easy integration of login and wallet connection.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:singularity_flutter/SingularityFlutter.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> implements SigularitySDKProtocol {
/// take variable of SingularityFlutter
late SingularityFlutter _gamepay;
late TextEditingController _environmentController;
late TextEditingController _keyController;
late TextEditingController _versionController;
// _MyAppState(){
// _controller = TextEditingController();
// _controller.text = "0";
// }
@override
void initState() {
super.initState();
_environmentController = TextEditingController();
_keyController = TextEditingController();
_versionController = TextEditingController();
_environmentController.text = "0";
_keyController.text = "neobrix";
/// initalize variable of SingularityFlutter
_gamepay = SingularityFlutter(this);
}
@override
void dispose() {
_environmentController.dispose();
_keyController.dispose();
_versionController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Neobrix'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("0 -> Sandbox, 1-> Production, 2->QAL"),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Choose Environment: ", style: TextStyle(fontSize: 16),),
],
),
TextField(
controller: _environmentController,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Key: ", style: TextStyle(fontSize: 16),),
],
),
TextField(
controller: _keyController,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Version (optional): ", style: TextStyle(fontSize: 16),),
],
),
TextField(
controller: _versionController,
decoration: InputDecoration(
border: OutlineInputBorder(),
),
),
ElevatedButton(onPressed: () async {
// call SingularityFlutter openLoginScreen to start login flow or open profile page
var environment = _environmentController.text;
var key = _keyController.text;
var version = _versionController.text;
try{
var env = int.parse(environment);
if(env!= 0 && env!= 1 && env!=2){
Fluttertoast.showToast(
msg: "Invalid Environment",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0
);
return;
}
var version = int.parse(environment);
if(key.isEmpty){
Fluttertoast.showToast(
msg: "Invalid Key",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0
);
return;
}
_gamepay.openLoginScreen(
key: key, singularityConfig: {
'environment': env,
'version': version
}
);
}
catch(e){
Fluttertoast.showToast(
msg: "Invalid Input",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0
);
}
}, child: Text("Launch SDK")),
ElevatedButton(onPressed: () async {
_gamepay.getUserInfo();
}, child: Text("Get Logged in user Info"))
],
)
),
);
}
showAlertDialog(BuildContext context, String title, String content) {
Widget okButton = TextButton(
child: const Text("OK"),
onPressed: () {
Navigator.pop(context);
},
);
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(content),
),
actions: [okButton],
);
});
}
/// Sigularity delegate method after login success
@override
onGetSingularityUserInfo(Map user) {
showAlertDialog(context, "onGetSingularityUserInfo", user.toString());
}
///Sigularity delegate method when user click on close or back button
@override
onSingularityClose() {
showAlertDialog(context, "onSigularityClose", "Back Pressed");
}
/// Sigularity delegate method after logout success
@override
onSingularityLogout() {
showAlertDialog(context, "onSigularityLogout", "logout");
}
/// Sigularity delegate method when any error occured
@override
onSingularityError(String message) {
showAlertDialog(context, "onSigularityLogout", message);
}
}