Flutter, Google Wallet, and Back4App: Environmental Rewards App Tutorial

15min

Introduction

In this tutorial, we'll create a Flutter app that encourages users to take environmental actions, rewarding them with digital badges and event tickets stored in Google Wallet. We’ll integrate Back4app as the backend to manage user data and track environmental contributions. Each time a user completes a task, they receive a collectible badge or event ticket, which can be added to their Google Wallet for safekeeping.

Features

  • Users can log environmental tasks (e.g., recycling, volunteering).
  • Users earn digital badges and event passes based on their contributions.
  • Google Wallet stores and displays these digital assets.
  • Backend integration with Back4app for tracking and data management.

Prerequisites

  1. Flutter Development Environment: Follow the Flutter installation guide.
  2. Back4app Account: Sign up at Back4app.
  3. Google Wallet API Access: Set up your project by following the Google Wallet API documentation.
  4. Google Wallet API Keys: Generate and use the required API keys for accessing Google Wallet.

Step 1: Setting Up Back4app as Backend

1.1 Create a Back4app Project

  1. Sign in to Back4app and create a new project.
  2. Create a Parse Class called EnvironmentalActions with the following fields:
    • username (String): The username of the user.
    • actionType (String): Type of environmental action (e.g., Recycling, Tree planting).
    • timestamp (DateTime): The date when the user completed the action.
    • rewardIssued (Boolean): Whether a reward has been issued for the action.

1.2 Add Sample Data to Back4app

You can add some sample records for testing purposes, but the app will handle data entry later when users complete tasks.

Step 2: Initialize Parse SDK in Flutter

2.1 Create a New Flutter Project

Open your terminal and create a new Flutter project:

Bash


2.2 Add Dependencies

Open the pubspec.yaml file and add the required dependencies:

YAML


Run flutter pub get to install the packages.

2.3 Initialize Parse SDK in Main File

In lib/main.dart, initialize the Parse SDK by adding your Back4app credentials:

Dart


Replace YOUR_BACK4APP_APP_ID and YOUR_BACK4APP_CLIENT_KEY with your actual Back4app credentials.

Step 3: Build the UI for Logging Environmental Actions

We'll create a basic UI that allows users to log their environmental actions and view their digital rewards.

3.1 Create the EnvironmentalRewardsScreen Widget

Create a new widget in lib/environmental_rewards_screen.dart:

Dart


This UI allows the user to:

  • Enter their username.
  • Select an environmental action.
  • Log the action, which triggers the backend and issues a reward using the Google Wallet API.

Step 4: Integrating Google Wallet for Issuing Rewards

4.1 Set Up Google Wallet API

Follow the Google Wallet API documentation to set up the API and obtain your API keys.

4.2 Issue a Digital Badge with Google Wallet

In the _issueReward() method, you will implement the logic to create a digital badge (generic pass) and save it to the user's Google Wallet. Here's a basic structure:

Dart


Step 5: Running the App

  1. Run the app using flutter run to start logging actions and receiving rewards.
  2. When a user logs an action, it will be saved to Back4app, and a badge will be issued using the Google Wallet API.

Conclusion

This tutorial showed how to build an environmental rewards app using Flutter, Google Wallet, and Back4app. Users log environmental actions, and upon completion, they receive digital badges or event passes stored in their Google Wallet. This project could be expanded with social sharing features, leaderboards, or even location-based rewards using QR codes.

For more information, refer to: