Код: Выделить всё
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart';
import '/flutter_flow/custom_functions.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Future updateBalanceAndPointPremium(String documentId) async {
try {
final DocumentReference userDocRef =
FirebaseFirestore.instance.collection('users').doc(documentId);
final DocumentSnapshot snapshot = await userDocRef.get();
if (snapshot.exists) {
final data = snapshot.data() as Map;
final double point = data['Point'] ?? 0.0;
final double balance = data['Balance'] ?? 0.0;
final int balanceTimes = data['balanceConvertTimes'] ?? 0;
double updatedBalance = balance;
int updatedBalanceTimes = balanceTimes;
// Calculate the number of times the balance should be increased by 15
int increaseCount = ((point ~/ 50) - balanceTimes);
if (increaseCount > 0) {
updatedBalance += increaseCount * 15;
updatedBalanceTimes += increaseCount;
}
final updateData = {
'Balance': updatedBalance,
'balanceConvertTimes': updatedBalanceTimes
};
await userDocRef.update(updateData);
print('Balance field updated successfully!');
}
} catch (e) {
print('Error updating balance field: $e');
}
}
Код хорошо работает в тестовом режиме (я использую Flutterflow — приложение для создания приложений с использованием Dart), но когда я отправляю приложение через Codemagic в App Store и Google Play, оно не работает (данные баланса были добавлены автоматически 15 как и ожидалось) на сборках, работающих на Testflight и одобренном приложении App Store.
Поэтому я действительно не знаю, почему это происходит.
Пожалуйста, помогите. Большое спасибо.
Я пытался поместить эту функцию в другую функцию, которая хорошо работает как в тестовом режиме, так и в реальных сборках.
Комбинированная функция в новой сборке все еще не работала. работает (хотя он все еще работает в тестовом режиме).
Новый код можно увидеть ниже:
Код: Выделить всё
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Future addPointandBalancePremium(
String documentId, double amountToAdd) async {
try {
final DocumentReference userDocRef =
FirebaseFirestore.instance.collection('users').doc(documentId);
await FirebaseFirestore.instance.runTransaction((transaction) async {
final DocumentSnapshot snapshot = await transaction.get(userDocRef);
if (snapshot.exists) {
final data = snapshot.data() as Map;
final currentAmount = data['Point'] ?? 0.0;
final double balance = data['Balance'] ?? 0.0;
final int balanceTimes = data['balanceConvertTimes'] ?? 0;
double updatedBalance = balance;
int updatedBalanceTimes = balanceTimes;
var currentDist = data['pointToNextReward'] ?? 0.0;
var currentDistFree = data['pointToNextRewardFree'] ?? 0.0;
final newAmount = currentAmount + (0.2 * amountToAdd / 100);
var newDist = 50 - (0.2 * amountToAdd / 100 - currentDist);
var newDistFree = 100 - (0.2 * amountToAdd / 100 - currentDistFree);
int increaseCount = ((newAmount ~/ 50) - balanceTimes);
if (increaseCount > 0) {
updatedBalance += increaseCount * 15;
updatedBalanceTimes += increaseCount;
}
currentDist = newDist;
if (newDist >= 50) {
currentDist = newDist - 50;
}
;
currentDistFree = newDistFree;
if (newDistFree >= 100) {
currentDistFree = newDistFree - 100;
}
;
transaction.update(userDocRef, {
'Point': newAmount,
'pointToNextReward': currentDist,
'pointToNextRewardFree': currentDistFree,
'Balance': updatedBalance,
'balanceConvertTimes': updatedBalanceTimes
});
}
});
print('Point and Balance fields updated successfully!');
} catch (e) {
print('Error updating Point field: $e');
}
}
Это меня очень смущает и застревает.
Подробнее здесь: https://stackoverflow.com/questions/766 ... ot-working