I've used health-3.0.3 in my flutter application to get the Google fit data. I'm able to get every data other than STEP-data which shows zero always.
You can refer to the health package here
Health 3.0.3 Flutter
This is the code block to access the STEP datatype in my application
List<HealthDataType> types = [
HealthDataType.STEPS,
HealthDataType.WEIGHT,
//HealthDataType.HEIGHT,
];
setState(() => _state = AppState.FETCHING_DATA);
/// You MUST request access to the data types before reading them
bool accessWasGranted = await health.requestAuthorization(types);
double steps = 0;
if (accessWasGranted) {
try {
/// Fetch new data
List<HealthDataPoint> healthData =
await health.getHealthDataFromTypes(startDate, endDate, types);
/// Save all the new data points
_healthDataList.addAll(healthData);
} catch (e) {
print("Caught exception in getHealthDataFromTypes: $e");
}
/// Filter out duplicates
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);
/// Print the results
_healthDataList.forEach((x) {
print("Data point: $x");
steps += (x.value as double);
});
print("Steps: $steps");
You can refer to the full code under the examples tab in the given link. Does anyone know what's wrong here?
health: 3.0.4 is more stable, when I'm writing this answer.
From Android 10. you have to add ACTIVITY_RECOGNITION for getting STEP Count permission in AndroidManifest.xml.
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
And then using permission_handler ask for permission.
if (Platform.isAndroid) {
final permissionStatus = Permission.activityRecognition.request();
if (await permissionStatus.isDenied ||
await permissionStatus.isPermanentlyDenied) {
showToast(
'activityRecognition permission required to fetch your steps count');
return;
}
}
Related
When we have a higher version available on the play store. This feature redirects users to the app store to install updates. But it is not working on a few devices. The user still using the older version. If the user clears the storage then an alert is displayed. We can not ask our users to clear storage. Any help would be greatly appreciated.
#override
void initState() {
super.initState();
try {
versionCheck(context);
} catch (e) {
print(e);
}
}
versionCheck(context) async {
//Get Current installed version of app
final PackageInfo info = await PackageInfo.fromPlatform();
double currentVersion =
double.parse(info.version.trim().replaceAll(".", ""));
//Get Latest version info from firebase config
final FirebaseRemoteConfig remoteConfig =
await FirebaseRemoteConfig.instance;
try {
// Using default duration to force fetching from remote server.
await remoteConfig.fetch();
await remoteConfig.fetchAndActivate();
remoteConfig.getString('force_update_current_version');
double newVersion = double.parse(remoteConfig
.getString('force_update_current_version')
.trim()
.replaceAll(".", ""));
if (newVersion > currentVersion) {
_showVersionDialog(context);
}
} on Exception catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print('Unable to fetch remote config. Cached or default values will be '
'used');
}
}
When I tried to print the values I am getting the same values new:160.0 current:160.0, clearing the storage of the app from the setting displays the alert.
I think your code in general looks right to me. Though there is a redundant line:
remoteConfig.getString('force_update_current_version');
But this should be fine.
What I am concerned about is that you replace all your . with empty and convert the version to a number. This can result in a bug if there are two versions like:
1.21.4 vs 1.2.15. The first one is supposed to be newer, but the code will get 1214 > 1215 is false
I'm new to Flutter and I've been following this tutorial but it's from 2020 and I know a lot of things have changed.
I want to save a file on my local phone and apparently I need to ask permission to do so. I'm not sure if checking the platform is still needed or not.
I don't want to run the --no-sound-null-safety command.
This is the only part that I wasn't able to update by myself.
_save() async {
if (Platform.isAndroid) {
await _askPermission();
}
var response = await Dio().get(widget.imgUrl!,
options: Options(responseType: ResponseType.bytes));
final result =
await ImageGallerySaver.saveImage(Uint8List.fromList(response.data));
print(result);
Navigator.pop(context);
}
_askPermission() async {
if (Platform.isIOS) {
await PermissionHandler().requestPermissions([PermissionGroup.photos]);
} else {
await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
}
}
The _save method seems alright but I wonder if there's something to update there as well.
The _askPermission method is the one that I need help with.
I'm using the official in_app_purchase plugin, version ^1.0.4, and I'm following the official guide from Google insert my first iap (https://codelabs.developers.google.com/codelabs/flutter-in-app-purchases#0).
My consumable iap product is active on Play console with name "pacchetto_25", I've already submitted to the alpha channel my app and is accepted, the tester email is correctly configured in the Tester Group and in Licence Testing.
Now I'm trying to load the iap products in my app, the code is the same of the guide:
Future<void> loadPurchases() async {
final available = await _iap.isAvailable();
if (!available) {
print("STORE NOT AVAILABLE");
return;
} else {
print("STORE AVAILABLE");
const ids = <String>{
"pacchetto_25",
};
final response = await _iap.queryProductDetails(ids);
response.notFoundIDs.forEach((element) {
print('Purchase $element not found');
});
response.productDetails.forEach((element) {
print("Purchase $element found");
});
// products =
// response.productDetails.map((e) => PurchasableProduct(e)).toList();
}
}
In my console I have the "STORE AVAILABLE" message, but then nothing else. If I put same debug point it does not stops on them, this problem appear after this line:
final response = await _iap.queryProductDetails(ids);
Do someone know what's happening? I've no errors in my console and the code after loadPurchases() is not executed, it's like is waiting forever... Any ideas?
Solved! If you have the same issue DON'T put
implementation("com.android.billingclient:billing:4.0.0")
in your build.gradle
i am uploading images from gallery to app, my app ask for permission automatically but dont know what happen now it is not asking for the permission and getting error "permission denied " when i try to open gallery in the app
loadGallery() async {
List<Asset> resultImages = List<Asset>();
try {
resultImages = await MultiImagePicker.pickImages(
maxImages: 10,
selectedAssets: images,
);
} catch (e) {
print("error is : $e");
}
setState(() {
images = resultImages;
});
}
In your AndroidManifest.xml file located in android/app/src/main, include these lines,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
under the "<manifest.." tag.
There can be many scenarios that can be in the picture.
1) Maybe you have clicked on the permission for never option, where it does not asks permission later.
you have to check if you have the permission for accessing I have written the code check it just wrote an example, modify accordingly
check out the below Code for asking the permission
Future<bool> checkAndRequestCameraPermissions() async {
PermissionStatus permission =
await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler().requestPermissions([PermissionGroup.camera]);
return permissions[PermissionGroup.camera] == PermissionStatus.granted;
} else {
return true;
}
}
later only check if you have permission then do the required process.
if (await checkAndRequestCameraPermissions()) {
File image = await ImagePicker.pickImage(source: ImageSource.camera);
// continue with the image ...
}
for time being i have used the image_picker you can use Multi Image Picker.
check out the code and let me know.
Thanks.
Try to change the version of multi image picker it will work.. if you are using latest version and still received same problem then change it to old version.
I am trying to create an application that can handle In App Purchases Using Flutter.I am using the in_app_purchase 0.2.1 plugin .I have managed to setup my product on google play developer console as required but however when try to retrieve it from the application i am able to connect to the store successfully but i am not able to retrieve my product ,it always shows up as product not found.
I have followed a this tutorial https://joebirch.co/2019/05/31/adding-in-app-purchases-to-flutter-apps/ and also looked at the package documentation https://pub.dev/packages/in_app_purchase.
My google play setup for the product is shown below
google play console setup
google play console setup2
The function i am using is shown below.
Future<List<ProductDetails>> retrieveProducts() async {
final bool available = await InAppPurchaseConnection.instance.isAvailable();
if (!available) {
// Handle store not available
print("Store Temporarily Unavailable");
return null;
} else {
print("Store Temporarily Available");
const Set<String> _kIds = {'airtime123'};
final ProductDetailsResponse response =
await InAppPurchaseConnection.instance.queryProductDetails(_kIds);
if (response.notFoundIDs.isNotEmpty) {
print("product not found");
print(response.notFoundIDs[0]);
return null;
}
print("product found");
return response.productDetails;
}
}
This is the result i get
I/flutter ( 7254): Store Temporarily Available
I/flutter ( 7254): product not found
I/flutter ( 7254): airtime123
You need to use a reserved SKU for the test: android.test.purchased
const Set<String> _kIds = {'android.test.purchased'};
final ProductDetailsResponse response =
await InAppPurchaseConnection.instance.queryProductDetails(_kIds);