diff --git a/lib/services/billing_service.dart b/lib/services/billing_service.dart index 32229b296..0b5c99e84 100644 --- a/lib/services/billing_service.dart +++ b/lib/services/billing_service.dart @@ -9,6 +9,7 @@ import 'package:photos/core/configuration.dart'; import 'package:photos/core/network.dart'; import 'package:photos/models/billing_plan.dart'; import 'package:photos/models/subscription.dart'; +import 'package:photos/utils/data_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; class BillingService { @@ -130,9 +131,7 @@ class BillingService { }, ), ); - final usageInBytes = response.data["usage"]; - return double.parse( - (usageInBytes / (1024 * 1024 * 1024)).toStringAsFixed(2)); + return convertBytesToGBs(response.data["usage"]); } catch (e) { throw e; } diff --git a/lib/ui/email_entry_page.dart b/lib/ui/email_entry_page.dart index 1b0cf2573..9d59a03db 100644 --- a/lib/ui/email_entry_page.dart +++ b/lib/ui/email_entry_page.dart @@ -9,6 +9,7 @@ import 'package:photos/services/user_service.dart'; import 'package:photos/ui/common_elements.dart'; import 'package:photos/ui/loading_widget.dart'; import 'package:photos/ui/web_page.dart'; +import 'package:photos/utils/data_util.dart'; import 'package:photos/utils/dialog_util.dart'; import 'package:photos/utils/email_util.dart'; @@ -306,7 +307,7 @@ class BillingPlanWidget extends StatelessWidget { child: Column( children: [ Text( - (plan.storage / (1024 * 1024 * 1024)).round().toString() + " GB", + convertBytesToGBs(plan.storage, precision: 0).toString() + " GB", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16, diff --git a/lib/utils/data_util.dart b/lib/utils/data_util.dart new file mode 100644 index 000000000..105aead40 --- /dev/null +++ b/lib/utils/data_util.dart @@ -0,0 +1,4 @@ +double convertBytesToGBs(final int bytes, {int precision = 2}) { + return double.parse( + (bytes / (1024 * 1024 * 1024)).toStringAsFixed(precision)); +}