tata_rewards 0.0.5 copy "tata_rewards: ^0.0.5" to clipboard
tata_rewards: ^0.0.5 copied to clipboard

tata rewards package

Tata Rewards #

Tata Rewards package lets you add a widget that supports stuffs to rewards to your Flutter app.

Installation #

  1. Add the latest version of package to your pubspec.yaml (and runflutter pub get):
dependencies:
  tata_rewards: ^0.0.5
  1. Import the package and use it in your Flutter App. flutter pub add tata_rewards

Example #

There are a number of properties that you can modify:

https://docs.google.com/spreadsheets/d/1XLEHj1LGox_S-whE9bJ5HoMCyNYrhE37eOzf-Ci0qXc/edit?usp=sharing ( but for this need to get verify from ESMAGICO)



import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:http/http.dart' as http;
import 'package:your_package_name/my_rewards_sdk.dart';

void main() async {
  // Ensure that Flutter bindings are initialized before making SDK calls
  WidgetsFlutterBinding.ensureInitialized();

  // Firebase configuration options
  FirebaseOptions firebaseOptions = FirebaseOptions(
    apiKey: 'YOUR_API_KEY',
    appId: 'YOUR_APP_ID',
    messagingSenderId: 'YOUR_MESSAGING_SENDER_ID',
    projectId: 'YOUR_PROJECT_ID',
  );

  // Initialize the SDK
  await MyRewardsSdk.initialize(
    firebaseOptions: firebaseOptions,
    httpClient: http.Client(),
    debug: true, // Enable debug mode for detailed logging
    ignoreSsl: false, // Do not ignore SSL errors (production-safe)
  );

  runApp(MyRewardsPage(
    appBarTitle: Text('My Rewards'),
    appBackIcon: Icon(Icons.arrow_back),
    gap: SizedBox(height: 10),
    title: "Rewards Dashboard",
    titleFontSize: 20,
    fontWeight: FontWeight.bold,
    isNavigateToBack: true,
    myRewardsPadding: 16.0,
    onPageEntrance: () {
      print("Page Entrance Triggered");
    },
    onAwardClick: (awardId, awardPoints) {
      print("Award clicked: $awardId with $awardPoints points");
    },
    onScratchCardClick: (scratchCardId, scratchCardPoints, status) {
      print("Scratch card clicked: $scratchCardId with $scratchCardPoints points, status: $status");
    },
    onCardScratched: (scratchCardId, scratchCardPoints, status) {
      print("Card scratched: $scratchCardId with $scratchCardPoints points, status: $status");
    },
    onScratchDialogOpen: () {
      print("Scratch dialog opened");
    },
    onDealOfTheDayProductClick: (productId, productName) {
      print("Deal of the day product clicked: $productId - $productName");
    },
    onDealOfTheDayBannerClick: (bannerId) {
      print("Deal of the day banner clicked: $bannerId");
    },
    onReferAndEarnClick: (bannerId) {
      print("Refer and Earn clicked: $bannerId");
    },
    onChanged: () {
      print("Something changed on the rewards page");
    },
  ));
}


import 'package:flutter/material.dart';
import 'package:tata_rewards/src/commons/rewards_assets.dart';
import 'package:tata_rewards/src/commons/tata_image_widget.dart';
import 'package:tata_rewards/src/repo/my_rewards_repo.dart';
import 'package:tata_rewards/src/screens/scratch_card_helper_class.dart';

import 'data/model/customer_response_model.dart';
import 'data/model/product_response.dart';
import 'data/model/scratch_card_response_model.dart';

class MyRewardsPage extends StatefulWidget {
  final Widget? appBarTitle;
  final Widget? appBackIcon;
  final Widget? gap;
  final void Function(String? awardId, String? awardPoints)? onAwardClick;
  final void Function()? onPageEntrance;
  final Function(
          String? scratchCardId, String? scratchCardPonts, String? status)?
  onScratchCardClick;
  final void Function(String? productId, String? productName)?
  onDealOfTheDayProductClick;
  final void Function(String? bannerId)? onDealOfTheDayBannerClick;
  final void Function(String? bannerId)? onReferAndEarnClick;
  final Function(
          String? scratchCardId, String? scratchCardPonts, String? status)?
  onCardScratched;
  final void Function()? onScratchDialogOpen;
  final void Function()? onChanged;
  final double? titleFontSize;
  final String? title;
  final bool isNavigateToBack;
  final double? myRewardsPadding;
  final FontWeight? fontWeight;

  const MyRewardsPage({
    super.key,
    this.appBarTitle,
    this.appBackIcon,
    this.onAwardClick,
    this.onCardScratched,
    this.onScratchDialogOpen,
    this.onScratchCardClick,
    this.onPageEntrance,
    this.onDealOfTheDayProductClick,
    this.onDealOfTheDayBannerClick,
    this.onReferAndEarnClick,
    this.onChanged,
    this.isNavigateToBack = true,
    this.myRewardsPadding,
    this.titleFontSize,
    this.fontWeight,
    this.title,
    this.gap,
  });

  @override
  State<MyRewardsPage> createState() => _MyRewardsPageState();
}

class _MyRewardsPageState extends State<MyRewardsPage> {
  List<CustomerRewards>? customerRewards;
  List<ScratchCard>? scratchCards;
  List<Product>? products;

  @override
  void initState() {
    super.initState();
    if (widget.onPageEntrance != null) {
      widget.onPageEntrance;
    }
    _refreshData();
  }

  Future<void> _refreshData() async {
    MyRewardsRepo.instance
            .getCustomerRewards()
            .then((value) => {customerRewards = value, setState(() {})});

    MyRewardsRepo.instance
            .getAllProducts()
            .then((value) => {products = value, setState(() {})});
    MyRewardsRepo.instance
            .getAllScratchCard(addOns: "games=scratch_card")
            .then((value) => {scratchCards = value, setState(() {})});
  }

  Widget _backIcon() =>
          InkWell(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: const Icon(
              Icons.arrow_back_ios,
              size: 24,
            ),
          );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  widget.isNavigateToBack ? _backIcon() : SizedBox(),
                  Expanded(
                    child: Center(
                      child: Text(
                        widget.title ?? "",
                        style: TextStyle(
                          fontSize: widget.titleFontSize ?? 24,
                          fontWeight: widget.fontWeight ?? FontWeight.w600,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              child: RefreshIndicator(
                onRefresh: _refreshData,
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      // Top section with an image and some content
                      Container(
                        height: customerRewards != null
                                ? customerRewards!.length > 2
                                ? 200
                                : 150
                                : 0,
                        decoration: const BoxDecoration(
                          borderRadius: BorderRadius.only(
                            bottomRight: Radius.circular(12),
                            bottomLeft: Radius.circular(12),
                          ),
                          image: DecorationImage(
                            image: AssetImage(
                                    TataRewardsAssets.titleBackGroundImage),
                            fit: BoxFit.fill,
                          ),
                        ),
                        child: Padding(
                          padding: EdgeInsets.symmetric(
                                  horizontal: widget.myRewardsPadding ?? 0)
                                  .copyWith(top: widget.myRewardsPadding ?? 0),
                          child: Center(
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                widget.gap ?? const SizedBox(),
                                customerRewards != null &&
                                        customerRewards!.isNotEmpty
                                        ? AllAwardsSection(
                                  awards: customerRewards!,
                                  gap: widget.gap,
                                  onCardClicked: widget.onAwardClick,
                                )
                                        : const SizedBox(),
                              ],
                            ),
                          ),
                        ),
                      ),
                      widget.gap ?? const SizedBox(),
                      Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: [
                            if (scratchCards != null &&
                                scratchCards!.isNotEmpty) ...[
                              const TataImageAsset(
                                  image: TataRewardsAssets.scratchTitleBanner),
                              widget.gap ?? const SizedBox(),
                              ScratchCardSections(
                                scratchData: scratchCards!,
                                onScratchCardClick: widget.onScratchCardClick,
                                onScratchDialogOpen: widget.onScratchDialogOpen,
                                onCardScratched: widget.onCardScratched,
                                totalScratchCardData:
                                MyRewardsRepo.instance.totalScratchCard,
                              ),
                            ],
                            if (products != null && products!.isNotEmpty) ...[
                              widget.gap ?? const SizedBox(),
                              const TataImageAsset(
                                  image: TataRewardsAssets.dealOfTheDayBanner),
                              widget.gap ?? const SizedBox(),
                              DealOfTheDaySection(
                                products: products!,
                                onCategorySelected:
                                widget.onDealOfTheDayProductClick,
                                onDealOfTheDayClick:
                                widget.onDealOfTheDayBannerClick,
                              ),
                            ],
                            widget.gap ?? const SizedBox(),
                            ReferAndEarnSection(
                              onReferAndBannerClick: widget.onReferAndEarnClick,
                            ),
                            widget.gap ?? const SizedBox(),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            // SingleChildScrollView for the main content
          ],
        ),
      ),
    );
  }
}





Next Goals #

  • To Add one more game with scratch card and to introduce newer one with spin the wheel Now, you can use two type of game service in the code

  • Might to going add games based on AI rewards related games on is one of the trending item to get known off