Move bytes to GB conversion to a util
This commit is contained in:
parent
6fdbba8d73
commit
a7eb3d8653
3 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
4
lib/utils/data_util.dart
Normal file
4
lib/utils/data_util.dart
Normal file
|
@ -0,0 +1,4 @@
|
|||
double convertBytesToGBs(final int bytes, {int precision = 2}) {
|
||||
return double.parse(
|
||||
(bytes / (1024 * 1024 * 1024)).toStringAsFixed(precision));
|
||||
}
|
Loading…
Add table
Reference in a new issue