import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:tata_rewards/tata_rewards.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
http.Client httpClient = http.Client();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
// Initialize the SDK
await MyRewardsSdk.instance.initialize(
httpClient: http.Client(),
tdlToken: '',
tplToken: '',
debug: true,
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
@override
void dispose() {
//Cleans up resources by canceling active subscriptions and closing the HTTP client. Should be called when the SDK is no longer needed, typically when the app is terminating.
MyRewardsSdk.instance.dispose();
// TODO: implement dispose
super.dispose();
}
@override
void initState() {
// TODO: implement initState
super.initState();
MyRewardsSdk.instance.registerOnLoginCallback(() {
// Handle post-login actions here
});
MyRewardsSdk.instance.registerOnLogoutCallback(() {
// Handle post-logout actions here
});
// After a successful login
MyRewardsSdk.instance.notifyLogin();
// After a successful logout
MyRewardsSdk.instance.notifyLogout();
performOperationWithCountVariable();
MyRewardsSdk.instance.cancelActiveCardCountSubscription();
}
Future<void> performOperationWithCountVariable() async {
await MyRewardsSdk.instance.subscribeToActiveCardCount(
userId: '6079545422',
onCountChanged: (int? activeCount) {
if (activeCount != null) {
// Handle the update, e.g., show a dialog or update UI
}
},
onError: (String error) {
// Handle the error, e.g., show a message to the user
},
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: MyRewardsPage(
title: "My Rewards",
myRewardsPadding: 16,
onScratchCardClick: (id, point, status) {
},
gap: const SizedBox(
height: 20,
),
),
);
}
}
|
|