petro_sdk_package 0.0.2
petro_sdk_package: ^0.0.2 copied to clipboard
Petro Payment SDK
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:petro_sdk_package/petro_sdk_package.dart';
import 'package:petro_sdk_package/utils/widget_util.dart';
import 'package:responsive_sizer/responsive_sizer.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:lottie/lottie.dart';
import 'package:flutter_exit_app/flutter_exit_app.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ResponsiveSizer(
builder: (p0, p1, p2) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Petro Sdk'),
);
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
// TODO: implement initState
super.initState();
requestPermission();
checkForBluetooth();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
centerTitle: true,
title: Text(widget.title,
style: const TextStyle(
fontSize: 18,
color: Colors.white,
)),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
style: const ButtonStyle(
backgroundColor: MaterialStatePropertyAll<Color>(
Color.fromRGBO(2, 180, 3, 1))),
child: const Text('Initialise App',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Colors.white,
)),
onPressed: () {
PetroSdk.initialization(
context: context,
//APP KEY
appKey: '16588310711856',
//APP SECRET
appSecret: '54214a8f-9d71-471f-b8cc-76a5b74f6bb2',
//DEVICE ID
deviceId: '1234',
//EMAIL
email: 'okwongkenneth36@gmail.com',
//PHONE
phone: '+2348026103661',
//TOKEN
token: '10010600');
},
),
],
),
),
);
}
Future<bool> requestPermission() async {
PermissionStatus result;
PermissionStatus resultNearby;
// In Android we need to request the storage permission,
// while in iOS is the photos permission
if (Platform.isAndroid) {
result = await Permission.locationWhenInUse.request();
resultNearby = await Permission.nearbyWifiDevices.request();
} else {
result = await Permission.locationWhenInUse.request();
}
if (Platform.isIOS || result.isPermanentlyDenied) {
//imageSection = ImageSection.noStoragePermissionPermanent;
WidgetUtil().showToastError('Could Not Get Location Permission');
return false;
} else if (result.isDenied) {
//imageSection = ImageSection.noStoragePermission;
WidgetUtil().showToastError('Could Not Get Location Permission');
return false;
}
return false;
}
checkForBluetooth() {
FlutterBluePlus.isOn.then((value) async {
if (!value) {
_showAlert(context);
}
});
}
void _showAlert(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
//insetPadding: const EdgeInsets.symmetric(horizontal: 15),
actionsPadding: const EdgeInsets.only(
right: 20,
bottom: 10,
),
contentPadding: const EdgeInsets.only(
left: 20,
bottom: 10,
top: 10,
right: 10,
),
titlePadding: const EdgeInsets.only(
left: 20,
top: 20,
bottom: 10,
),
title: const Text("Turn On Bluetooth",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15)),
//buttonPadding: const EdgeInsets.only(left: 20, top: 20,),
content: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Lottie.asset('assets/animation/bluetooth.json',
height: MediaQuery.of(context).size.height * 0.10,
width: MediaQuery.of(context).size.height * 0.10,
fit: BoxFit.contain,
package: 'petro_sdk_package'),
WidgetUtil().verticalSpace(20),
const Text(
"Please Turn On Bluetooth and Restart App.",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
],
),
actions: [
MaterialButton(
color: Color.fromRGBO(2, 180, 3, 1),
onPressed: () {
FlutterExitApp.exitApp();
},
minWidth: 10,
child: const Text(
'Okay',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.white,
),
),
),
],
),
);
}
}