Skip to content

Instantly share code, notes, and snippets.

View PatilShreyas's full-sized avatar
👨‍💻
Might be writing code at the moment

Shreyas Patil PatilShreyas

👨‍💻
Might be writing code at the moment
View GitHub Profile
import 'package:flutter/material.dart';
import 'controller/form_controller.dart';
import 'model/form.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;
import '../model/form.dart';
/// FormController is a class which does work of saving FeedbackForm in Google Sheets using
/// HTTP GET request on Google App Script Web URL and parses response and sends result callback.
class FormController {
// Google App Script Web URL.
static const String URL = "https://script.google.com/macros/s/AKfycbyAaNh-1JK5pSrUnJ34Scp3889mTMuFI86DkDp42EkWiSOOycE/exec";
/// FeedbackForm is a data class which stores data fields of Feedback.
class FeedbackForm {
String name;
String email;
String mobileNo;
String feedback;
FeedbackForm(this.name, this.email, this.mobileNo, this.feedback);
factory FeedbackForm.fromJson(dynamic json) {
function doPost(request){
// Open Google Sheet using ID
var sheet = SpreadsheetApp.openById("1OOArrqjOqmD4GiJOWlluZ4woTMH_qaV6RKv4JXnT3Hk");
var result = {"status": "SUCCESS"};
try{
// Get all Parameters
var name = request.parameter.name;
var email = request.parameter.email;
var mobileNo = request.parameter.mobileNo;
var feedback = request.parameter.feedback;
FirebaseMessaging.getInstance().subscribeToTopic("discount-offers")
.addOnCompleteListener { task ->
showToast("Subscribed! You will get all discount offers notifications")
if (!task.isSuccessful) {
showToast("Failed! Try again.")
}
}
class ScheduledWorker(appContext: Context, workerParams: WorkerParameters) :
Worker(appContext, workerParams) {
override fun doWork(): Result {
Log.d(TAG, "Work START")
// Get Notification Data
val title = inputData.getString(NOTIFICATION_TITLE)
val message = inputData.getString(NOTIFICATION_MESSAGE)
class NotificationBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
val title = it.getStringExtra(NOTIFICATION_TITLE)
val message = it.getStringExtra(NOTIFICATION_MESSAGE)
// Create Notification Data
val notificationData = Data.Builder()
.putString(NOTIFICATION_TITLE, title)
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// Check if message contains a data payload.
remoteMessage.data.isNotEmpty().let {
Log.d(TAG, "Message data payload: ${remoteMessage.data}")
// Get Message details
val title = remoteMessage.data["title"]
val message = remoteMessage.data["message"]
private fun scheduleAlarm(
scheduledTimeString: String?,
title: String?,
message: String?
) {
val alarmMgr = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val alarmIntent =
Intent(applicationContext, NotificationBroadcastReceiver::class.java).let { intent ->
intent.putExtra(NOTIFICATION_TITLE, title)
intent.putExtra(NOTIFICATION_MESSAGE, message)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView = findViewById(R.id.nav_view)
navView.setItemStyle(MaterialNavigationView.ITEM_STYLE_ROUND_RIGHT)
navView.setItemStyle(MaterialNavigationView.ITEM_STYLE_ROUND_RECTANGLE)
}