Flutter : How to Allow any device to create a single account only - flutter

i am working in flutter app,
I want each user to create only one account through his device
That is, banning the device from creating other accounts for two days
After two days, the user can create another account only, and so on,
in my case : save device id or token and date Time in firebase and before create account app check if this device was registered or not if registered check time , this way is right ?
and how can i get device id or any constant number from device ?
thanks

I'm sorry, I think I may not have fully grasped your question, here's my guess about what you are asking based on the agglomeration of English words you've put:
You are using Flutter to develop the front-end of an application while using Firebase for the back-end. You want to make sure that each device could only create one account every 48 hours. Please correct me if my understanding is wrong.
There's never a unique solution to those kind of questions, and I think your approach (timestamp + some ID that tells devices apart) is a decent one.
To get the device ID, it looks like you can use the device_info_plus plugin according to here: How to get unique device id in flutter?

You need to find and store unique device ID in the database.
You can find unique device using this plugin
dependencies:
device_info_plus: ^3.2.3
Create a method:
Future<String?> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) { // import 'dart:io'
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else if(Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}

Related

User issue with Flutter Revenuecat providing free trial with promo code

I am using revenucat to manage subscriptions in my app. But I noticed a problem. I have promo codes that I created on google play for my user. With this code, the user can use 3 months free of charge. When the user logs in on another device, I can't get the information that the user is in the trial period. Therefore, the purchase screen appears again. how can i solve this. I understand from the code below that the user is a premium member.
Future updatePurchaseStatus() async {
final purchaserInfo = await Purchases.getCustomerInfo();
final entitlements = purchaserInfo.entitlements.active.values.toList();
_entitlement =
entitlements.isEmpty ? Entitlement.free : Entitlement.premium;
if (entitlements.isNotEmpty) {
_entitlementInfo = purchaserInfo.entitlements.active.values.last;
}
notifyListeners();
}

Flutter Web UUID Unique Identifier

How can I get UUID in Flutter Web.
I need some unique identifier in order to keep record of devices useb by customer,my testing device,develeper device.
In android, I'm using device_info_plugin.
How can I get Unique identifier in Web?
Thanks in Advance
You can use platform_device_id to get the browser details.
For browser info, you can use it as
import 'package:platform_device_id/platform_device_id.dart';
String? deviceId = await PlatformDeviceId.getDeviceId;
print($deviceId);
OR
hare is the Answer to the approach to set a custom uuid for flutter web

How to update a cloud firestore document at a particular time in the future in my flutter app

I am new to programming, and flutter is my first attempt at making mobile apps. I app working on an app and i would like it to have a function where i can update user documents on firestore at a particular time in the future. For instance, change their account status from "ACTIVE" to "INACTIVE" in exactly "One year" from the time they registered their accounts. I have a sample code which i will paste below to show an example of what i already have. Any ideas as to how to achieve this would be highly appreciated. Thank You.
await _firestore
.collection('users')
.doc(_firebaseAuth.currentUser.uid)
.set({
'email': _email,
'timeOfCreation': FieldValue.serverTimestamp(),
'accountStatus': 'ACTIVE'
});
This is not something you want to do on the client side. You would want to write a Google Cloud Function that checks the creation date and sets the status to inactive if it's been a year, or whatever specified time frame. Otherwise, it could only update if they keep the app installed and device connected to the internet.

Flutter. How to check that autorenewal subscription is still valid

My app has a 1 month autorenewal subscription. When the user clicks on a "Buy a subscription" button I am saving date of purchase to shared preferences.
Then, after 1 month, I need to check is this subscription is still valid.
So how can I implement it?
==== UPDATE from 11.03.2020
Hi, I can see this post still reading by people who looking for a method of how to work with subscription in Flutter.
During 2019 I made two apps with thousands installs where users can buy a renewable subscription on the 2 platforms.
Until February 2020 I used for this package from Flutter team https://pub.dev/packages/in_app_purchase, BUT - there is no way to get info about the user to unsubscribe in iOS. This is not the plugin issue, but the iOS approach for the process. We should implement our own backend for security reasons (by the way Google also recommends to do the same, but still left the way to check state directly from the app).
So, after some researches, I found guys who made backend and plugin and it is free until you have less than 10 000 USD revenue for the month.
https://www.revenuecat.com/
https://pub.dev/packages/purchases_flutter
I've implemented this plugin in my apps and it works like a charm. There is some good approaches that allow you to get a subscription state at any point in the app. I'm going to make an example and article, but not sure about the timing.
====
UPDATE from 15.07.2019. Just to save time. The answer below was given for an outdated plugin for payments. After that Flutter team made plugin
https://pub.dev/packages/in_app_purchase
and I recommend using it.
=====
The best way is to use a secure backend server for receiving Real-time Developer Notifications.
But, it is possible to check status directly in the application.
So, when user tries to get access to some paid functionality you can check whether his subscription is active or not. Below is the example:
Create somewhere the file with the class
import 'dart:io' show Platform;
import 'package:flutter/services.dart';
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
import 'dart:async';
class SubcsriptionStatus {
static Future<bool> subscriptionStatus(
String sku,
[Duration duration = const Duration(days: 30),
Duration grace = const Duration(days: 0)]) async {
if (Platform.isIOS) {
var history = await FlutterInappPurchase.getPurchaseHistory();
for (var purchase in history) {
Duration difference =
DateTime.now().difference(purchase.transactionDate);
if (difference.inMinutes <= (duration + grace).inMinutes &&
purchase.productId == sku) return true;
}
return false;
} else if (Platform.isAndroid) {
var purchases = await FlutterInappPurchase.getAvailablePurchases();
for (var purchase in purchases) {
if (purchase.productId == sku) return true;
}
return false;
}
throw PlatformException(
code: Platform.operatingSystem, message: "platform not supported");
}
}
Import it where you need to check subscription status and use in Constructor. For example:
class _SubscriptionState extends State<Subscription> {
bool userSubscribed;
_SubscriptionState() {
SubcsriptionStatus.subscriptionStatus(iapId, const Duration(days: 30), const
Duration(days: 0)).then((val) => setState(() {
userSubscribed = val;
}));
}
}
In variable userSubscribed will be the state - true or false.
(Please note you have to add flutter_inapp_purchase to your project).
There's a few ways of doing this, but I would not do this on the mobile device.
On Device like you asked for
Install Flutter Cache Manager, on start set a cache key value 'Subscription' to true with maxAgeCacheObject: Duration (days: 30). On every start check if that key still exists in the cache. If it does then it's still valid otherwise it has expired.
Suggested solution using FirebaseFunction
I would suggest setting up a backend to manage all this. This is not a task for the mobile device. You can have a Cloud Function from firebase where you pass a unique device id and it'll return whether the subscription is still valid or not. A serverless function should work for that. Pseudo steps:
(On Device)When the app starts up generate a guid and make an http post request with your guid.
(Server)In your serverless function save the date the request is made to your db along with the uniqueId that you sent. If your id is already in the DB then check if it's expired (date added - current date) < 30days. Return true or false from the function. True if still valid, false if not valid.
(On Device) When you receive true from your function then save the generated id locally on disk and continue with what you want to do. If it's false then lock the user out or show the subscription that you want to take care of.
Yeah, as to the vulnerabilities, there is one way to take the issue of users changing their time manually just to deceive the app, the solution I thought of is letting the DateTime come from the server this way, whether users change the Date and Time or not you end up with the correct time frame. I hope this helps.
As to checking whether subscription has expired, just follow the step #awaik gave and in addition, you can make request to your api to store the dateTime when the subscription was purchased and when you expect the subscription to expire. I suggest you save the purchase date and expected date in your server rather than on user device as clearing the cache or data directory of the app will lead to loss of the saved data. Goodluck.

Which of the MobileAdTargetingInfo properties of Flutter Firebase AdMob package do I need for release?

I want to know when using firebase_admob, do I need this code?
If so, when releasing an app, what should I write for keywords, contentUrl, and testDevices?
I mean, when releasing an app, testDevices is even necessary?
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
birthday: DateTime.now(),
childDirected: false,
designedForFamilies: false,
gender: MobileAdGender.male, // or MobileAdGender.female, MobileAdGender.unknown
testDevices: <String>[], // Android emulators are considered test devices
);
this information is used to show ad to users.
You should use keywords related to your application. Ex: if Your application is related to hospital then you can use medicine as your key words.
you can add you web site url if you develop any web site for particular application as contentUrl .
testDevices is a Id of you device in which you are tested. if you want to test your application in real device then you must add test device id because it help you to avoid ad mob bane.
MobileAdTargetingInfo class properties mirror the native AdRequest API.
You will find more information about those properties in the documentation for AdRequest.Builder and RequestConfiguration.Builder.
AdRequest.Builder
public AdRequest.Builder addKeyword (String keyword)
Add a keyword for targeting purposes.
public AdRequest.Builder setContentUrl (String contentUrl)
Sets the content URL for a web site whose content matches the app's primary content. This web site content is used for targeting and brand safety purposes.
At the time of writing some parameters from the question have been deprecated with no alternative, some like the one below replaced with a different approach, while some other moved to RequestConfiguration.Builder.
public AdRequest.Builder setIsDesignedForFamilies (boolean isDesignedForFamilies)
Deprecated. Use Ad Content Filtering.
RequestConfiguration.Builder
public RequestConfiguration.Builder setTagForChildDirectedTreatment (int tagForChildDirectedTreatment)
This method allows you to specify whether you would like your app to be treated as child-directed for purposes of the Children’s Online Privacy Protection Act (COPPA)
public RequestConfiguration.Builder setTestDeviceIds (List testDeviceIds)
Sets a list of test device IDs corresponding to test devices which will always request test ads. The test device ID for the current device is logged in logcat when the first ad request is made.