prizorsdk_flutter 0.0.6 prizorsdk_flutter: ^0.0.6 copied to clipboard
Prizor SDK Flutter, plugin for seamless integration with PrizorSDK, empowering your mobile apps. Docs for integrating and utilizing PrizorSDK in Flutter projects.
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:prizorsdk_flutter/prizorsdk_flutter.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
String title = 'PrizorSDK Example';
return MaterialApp(
title: title,
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.blue),
home: const NavigationPage(),
);
}
}
class NavigationPage extends StatelessWidget {
const NavigationPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("PrizorSDK Example"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Root Page Example"),
onPressed: () async {
if (context.mounted) {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const MyRootHomePage(
title: "PrizorSDK Example",
),
),
);
}
},
),
ElevatedButton(
child: const Text("Navigation Page Example"),
onPressed: () async {
if (context.mounted) {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const MyHomePage(
title: "PrizorSDK Example",
),
),
);
}
},
),
],
),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({required this.title, super.key});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController cpfController = TextEditingController(text: "");
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: TextField(
controller: cpfController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'CPF',
),
),
),
Container(height: 20),
ElevatedButton(
child: const Text("Open PrizorSDK"),
onPressed: () async {
if (cpfController.text != "" && cpfController.text.length == 11) {
await Permission.location.request();
await Permission.camera.request();
await Permission.microphone.request();
if (context.mounted) {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => PrizorSdkPage(
cpf: cpfController.text.replaceAll(RegExp("[\\D]"), ""),
),
),
);
}
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('SDK Initialization error.'),
));
}
},
),
],
),
),
);
}
}
class MyRootHomePage extends StatefulWidget {
const MyRootHomePage({required this.title, super.key});
final String title;
@override
State<MyRootHomePage> createState() => _MyRootHomePageState();
}
class _MyRootHomePageState extends State<MyRootHomePage> {
final String DOCUMENT_FAKER = "40583583946";
late final List<Widget> _children = [
const MyHomePage(title: "HOME"),
PrizorSdkPage(
cpf: DOCUMENT_FAKER,
isRootRoute: true,
titleRoute: 'Benefícios',
),
];
int _currentIndex = 0;
void _setIndex(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (int index) {
_setIndex(index);
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.app_shortcut_outlined),
label: "PrizorSDK",
),
],
),
);
}
}
class PrizorSdkPage extends StatefulWidget {
const PrizorSdkPage({
super.key,
required this.cpf,
this.isRootRoute = false,
this.titleRoute = "",
});
final String cpf;
final String titleRoute;
final bool isRootRoute;
@override
State<PrizorSdkPage> createState() => _PrizorSdkPageState();
}
class _PrizorSdkPageState extends State<PrizorSdkPage> {
@override
Widget build(BuildContext context) {
return PrizorSdkWidget(
androidAPIErrorCallback: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Android Version Error.")),
),
params: PrizorSdkParams(
environment: Environment.production,
appId: "***",
secret: "***",
appName: "PrizorSDK Example",
isRootRoute: widget.isRootRoute,
titleRoute: widget.titleRoute,
accentColor: const Color(0xFF000000),
accentForegroundColor: Colors.white,
user: const User(
documentNumber: "40583583946",
cellphone: "+5512345678901",
name: "John Doe",
),
),
);
}
}