singularity_flutter 1.5.1 singularity_flutter: ^1.5.1 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, SingularityInitCallback {
/// take variable of SingularityFlutter
late SingularityFlutter _gamepay;
late TextEditingController _controller;
// _MyAppState(){
// _controller = TextEditingController();
// _controller.text = "0";
// }
@override
void initState() {
super.initState();
_controller = TextEditingController();
_controller.text = "2";
/// initalize variable of SingularityFlutter
_gamepay = SingularityFlutter(this);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Neobrix'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Enter api key ", style: TextStyle(fontSize: 16),),
],
),
TextField(
controller: _controller,
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
),
ElevatedButton(onPressed: () async {
// call SingularityFlutter openLoginScreen to start login flow or open profile page
var apiKey = _controller.text;
try{
_gamepay.initializeSingularity(apiKey, this);
}
catch(e){
Fluttertoast.showToast(
msg: "Invalid Input",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 16.0
);
}
}, child: Text("Inittialize Sigularity")),
ElevatedButton(onPressed: () async {
_gamepay.openDrawer();
}, child: Text("Open Drawer")),
ElevatedButton(onPressed: () async {
_gamepay.closeDrawer();
}, child: Text("Close Drawer")),
ElevatedButton(onPressed: () async {
_gamepay.logoutUser();
}, child: Text("Logout User")),
ElevatedButton(onPressed: () async {
var userInfo = await _gamepay.getUserInfo();
showAlertDialog(context, "onGetSingularityUserInfo", userInfo.toString());
}, child: Text("Get 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, "Alert", "Drawer Closed");
}
/// Sigularity delegate method after logout success
@override
onSingularityLogout() {
showAlertDialog(context, "Alert", "User logged out");
}
@override
onSingularityInitialized() {
showAlertDialog(context, "Alert", "Singularity Initialized");
}
@override
onSingularityError(String message) {
}
}