2021-07-28 18:06:30 +00:00
|
|
|
import 'dart:async';
|
2021-07-28 15:29:21 +00:00
|
|
|
|
2021-07-28 14:08:27 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-06-09 09:53:03 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2021-07-28 18:06:30 +00:00
|
|
|
import 'package:photos/core/event_bus.dart';
|
2022-05-30 11:05:00 +00:00
|
|
|
import 'package:photos/events/tab_changed_event.dart';
|
2021-09-15 20:56:05 +00:00
|
|
|
import 'package:photos/events/user_details_changed_event.dart';
|
2021-07-28 14:08:27 +00:00
|
|
|
import 'package:photos/models/user_details.dart';
|
|
|
|
import 'package:photos/services/user_service.dart';
|
|
|
|
import 'package:photos/ui/loading_widget.dart';
|
2022-05-30 04:37:54 +00:00
|
|
|
import 'package:photos/ui/payment/subscription.dart';
|
2021-07-28 14:08:27 +00:00
|
|
|
import 'package:photos/utils/data_util.dart';
|
|
|
|
|
|
|
|
class DetailsSectionWidget extends StatefulWidget {
|
|
|
|
DetailsSectionWidget({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_DetailsSectionWidgetState createState() => _DetailsSectionWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
|
|
|
|
UserDetails _userDetails;
|
2021-09-15 20:56:05 +00:00
|
|
|
StreamSubscription<UserDetailsChangedEvent> _userDetailsChangedEvent;
|
2022-05-30 11:05:00 +00:00
|
|
|
StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
|
2021-07-28 14:08:27 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-07-28 18:06:30 +00:00
|
|
|
_fetchUserDetails();
|
2022-03-05 20:52:00 +00:00
|
|
|
_userDetailsChangedEvent =
|
|
|
|
Bus.instance.on<UserDetailsChangedEvent>().listen((event) {
|
2021-07-28 18:06:30 +00:00
|
|
|
_fetchUserDetails();
|
|
|
|
});
|
2022-05-30 11:05:00 +00:00
|
|
|
_tabChangedEventSubscription =
|
|
|
|
Bus.instance.on<TabChangedEvent>().listen((event) {
|
|
|
|
if (event.selectedIndex == 3) {
|
|
|
|
_fetchUserDetails();
|
|
|
|
}
|
|
|
|
});
|
2021-07-28 18:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _fetchUserDetails() {
|
2022-05-30 09:23:55 +00:00
|
|
|
UserService.instance.getUserDetailsV2(memoryCount: true).then((details) {
|
2022-05-30 11:05:00 +00:00
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
_userDetails = details;
|
|
|
|
});
|
|
|
|
}
|
2021-07-28 14:08:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-28 18:06:30 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2021-09-15 20:56:05 +00:00
|
|
|
_userDetailsChangedEvent.cancel();
|
2022-05-30 11:05:00 +00:00
|
|
|
_tabChangedEventSubscription.cancel();
|
2021-07-28 18:06:30 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2021-07-28 14:08:27 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-05-30 04:37:54 +00:00
|
|
|
return GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () async {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return getSubscriptionPage();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2022-06-14 04:48:22 +00:00
|
|
|
child: _userDetails == null ? loadWidget : getContainer(),
|
2021-07-28 14:35:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-14 04:48:22 +00:00
|
|
|
Widget getContainer() {
|
|
|
|
return SizedBox(
|
|
|
|
width: 350,
|
|
|
|
height: 175,
|
2022-06-13 15:14:49 +00:00
|
|
|
// constraints: BoxConstraints(maxWidth: 390, maxHeight: 195),
|
2022-06-14 04:48:22 +00:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 2 / 1,
|
|
|
|
child: Image(
|
|
|
|
image: AssetImage("assets/card_background.png"),
|
|
|
|
fit: BoxFit.fill, // use this
|
2022-06-09 15:30:45 +00:00
|
|
|
),
|
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 20, bottom: 20, left: 16, right: 16),
|
|
|
|
child: Container(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Storage",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.subtitle2
|
|
|
|
.copyWith(color: Colors.white.withOpacity(0.7)),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${convertBytesToReadableFormat(_userDetails.getFreeStorage())} of ${convertBytesToReadableFormat(_userDetails.getTotalStorage())} free",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headline5
|
|
|
|
.copyWith(color: Colors.white),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-06-09 15:30:45 +00:00
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
children: <Widget>[
|
2022-06-10 06:53:47 +00:00
|
|
|
Container(
|
2022-06-14 04:48:22 +00:00
|
|
|
color: Colors.white.withOpacity(0.2),
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 4,
|
2022-06-10 06:53:47 +00:00
|
|
|
),
|
|
|
|
Container(
|
2022-06-14 04:48:22 +00:00
|
|
|
color: Colors.white.withOpacity(0.75),
|
|
|
|
width: MediaQuery.of(context).size.width *
|
|
|
|
((_userDetails.getFamilyOrPersonalUsage()) /
|
|
|
|
_userDetails.getTotalStorage()),
|
|
|
|
height: 4,
|
2022-06-10 06:53:47 +00:00
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
Container(
|
|
|
|
color: Colors.white,
|
|
|
|
width: MediaQuery.of(context).size.width *
|
|
|
|
(_userDetails.usage /
|
|
|
|
_userDetails.getTotalStorage()),
|
|
|
|
height: 4,
|
2022-06-10 06:53:47 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
Padding(padding: EdgeInsets.symmetric(vertical: 8)),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
_userDetails.isPartOfFamily()
|
|
|
|
? Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 8.71,
|
|
|
|
height: 8.99,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(right: 4)),
|
|
|
|
Text(
|
|
|
|
"You",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(right: 12)),
|
|
|
|
Container(
|
|
|
|
width: 8.71,
|
|
|
|
height: 8.99,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: Colors.white.withOpacity(0.75),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(right: 4)),
|
|
|
|
Text(
|
|
|
|
"Family",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(
|
|
|
|
"${convertBytesToReadableFormat(_userDetails.getFamilyOrPersonalUsage())} used",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
|
|
|
color: Colors.white, fontSize: 12),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 16.0),
|
|
|
|
child: Text(
|
|
|
|
"${NumberFormat().format(_userDetails.fileCount)} Memories",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(color: Colors.white, fontSize: 12),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-06-10 06:53:47 +00:00
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Icon(
|
|
|
|
Icons.chevron_right,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-07-28 14:08:27 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|