2022-09-07 08:30:09 +00:00
|
|
|
// @dart=2.9
|
|
|
|
|
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';
|
2022-10-10 05:07:51 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2021-07-28 14:08:27 +00:00
|
|
|
import 'package:photos/models/user_details.dart';
|
2022-10-10 05:07:51 +00:00
|
|
|
import 'package:photos/states/user_details_state.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/common/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 {
|
2022-07-04 08:43:01 +00:00
|
|
|
const DetailsSectionWidget({Key key}) : super(key: key);
|
2021-07-28 14:08:27 +00:00
|
|
|
|
|
|
|
@override
|
2022-07-03 09:45:00 +00:00
|
|
|
State<DetailsSectionWidget> createState() => _DetailsSectionWidgetState();
|
2021-07-28 14:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
|
2022-10-10 05:07:51 +00:00
|
|
|
// StreamSubscription<UserDetailsChangedEvent> userDetailsChangedEvent;
|
|
|
|
// StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
|
2022-06-19 11:26:07 +00:00
|
|
|
Image _background;
|
2021-07-28 14:08:27 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-07-04 06:02:17 +00:00
|
|
|
_background = const Image(
|
2022-06-24 15:29:24 +00:00
|
|
|
image: AssetImage("assets/storage_card_background.png"),
|
2022-06-19 11:26:07 +00:00
|
|
|
fit: BoxFit.fill,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
// precache background image to avoid flicker
|
|
|
|
// https://stackoverflow.com/questions/51343735/flutter-image-preload
|
|
|
|
precacheImage(_background.image, context);
|
2021-07-28 18:06:30 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:08:27 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-10 05:07:51 +00:00
|
|
|
final logger = Logger((_DetailsSectionWidgetState).toString());
|
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-10-10 05:07:51 +00:00
|
|
|
// child: getContainer(),
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: InheritedUserDetails.of(context).userDetails,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return getContainer(snapshot.data);
|
|
|
|
}
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
logger.severe('failed to load user details', snapshot.error);
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
return const EnteLoadingWidget();
|
|
|
|
},
|
|
|
|
),
|
2021-07-28 14:35:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-10 05:07:51 +00:00
|
|
|
Widget getContainer(UserDetails userDetails) {
|
2022-10-05 12:37:43 +00:00
|
|
|
return ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 428, maxHeight: 175),
|
2022-06-14 04:48:22 +00:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 2 / 1,
|
2022-06-19 11:26:07 +00:00
|
|
|
child: _background,
|
2022-06-09 15:30:45 +00:00
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
),
|
2022-10-10 05:07:51 +00:00
|
|
|
userDetails == null
|
2022-07-03 06:04:42 +00:00
|
|
|
? const EnteLoadingWidget()
|
2022-06-19 11:34:41 +00:00
|
|
|
: Padding(
|
2022-07-04 06:02:17 +00:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 20,
|
|
|
|
bottom: 20,
|
|
|
|
left: 16,
|
|
|
|
right: 16,
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
child: Container(
|
|
|
|
color: Colors.transparent,
|
2022-06-14 04:48:22 +00:00
|
|
|
child: Column(
|
2022-06-19 11:34:41 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-06-14 04:48:22 +00:00
|
|
|
children: [
|
2022-06-19 11:34:41 +00:00
|
|
|
Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Storage",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.subtitle2
|
2022-07-03 09:49:33 +00:00
|
|
|
.copyWith(
|
2022-07-03 10:09:01 +00:00
|
|
|
color: Colors.white.withOpacity(0.7),
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
|
|
|
Text(
|
2022-10-10 05:07:51 +00:00
|
|
|
"${convertBytesToReadableFormat(userDetails.getFreeStorage())} of ${convertBytesToReadableFormat(userDetails.getTotalStorage())} free",
|
2022-06-19 11:34:41 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headline5
|
|
|
|
.copyWith(color: Colors.white),
|
|
|
|
),
|
|
|
|
],
|
2022-06-10 06:53:47 +00:00
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
color: Colors.white.withOpacity(0.2),
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
color: Colors.white.withOpacity(0.75),
|
|
|
|
width: MediaQuery.of(context).size.width *
|
2022-10-10 05:07:51 +00:00
|
|
|
((userDetails
|
2022-07-03 09:49:33 +00:00
|
|
|
.getFamilyOrPersonalUsage()) /
|
2022-10-10 05:07:51 +00:00
|
|
|
userDetails.getTotalStorage()),
|
2022-06-19 11:34:41 +00:00
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
color: Colors.white,
|
|
|
|
width: MediaQuery.of(context).size.width *
|
2022-10-10 05:07:51 +00:00
|
|
|
(userDetails.usage /
|
|
|
|
userDetails.getTotalStorage()),
|
2022-06-19 11:34:41 +00:00
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2022-10-10 05:07:51 +00:00
|
|
|
userDetails.isPartOfFamily()
|
2022-06-19 11:34:41 +00:00
|
|
|
? Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 8.71,
|
|
|
|
height: 8.99,
|
2022-07-04 06:02:17 +00:00
|
|
|
decoration: const BoxDecoration(
|
2022-06-19 11:34:41 +00:00
|
|
|
shape: BoxShape.circle,
|
2022-06-14 04:48:22 +00:00
|
|
|
color: Colors.white,
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(
|
2022-07-03 10:09:01 +00:00
|
|
|
padding: EdgeInsets.only(right: 4),
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
Text(
|
|
|
|
"You",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
2022-07-03 09:49:33 +00:00
|
|
|
.copyWith(
|
2022-07-03 10:09:01 +00:00
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(
|
2022-07-03 10:09:01 +00:00
|
|
|
padding: EdgeInsets.only(right: 12),
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
Container(
|
|
|
|
width: 8.71,
|
|
|
|
height: 8.99,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
2022-07-03 09:49:33 +00:00
|
|
|
color: Colors.white
|
|
|
|
.withOpacity(0.75),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(
|
2022-07-03 10:09:01 +00:00
|
|
|
padding: EdgeInsets.only(right: 4),
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
Text(
|
|
|
|
"Family",
|
2022-07-03 09:49:33 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(
|
2022-07-03 06:56:43 +00:00
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(
|
2022-10-10 05:07:51 +00:00
|
|
|
"${convertBytesToReadableFormat(userDetails.getFamilyOrPersonalUsage())} used",
|
2022-06-19 11:34:41 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
2022-07-03 09:49:33 +00:00
|
|
|
.copyWith(
|
2022-07-03 10:09:01 +00:00
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 16.0),
|
|
|
|
child: Text(
|
2022-10-10 05:07:51 +00:00
|
|
|
"${NumberFormat().format(userDetails.fileCount)} Memories",
|
2022-06-19 11:34:41 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
2022-07-03 09:49:33 +00:00
|
|
|
.copyWith(
|
2022-07-03 10:09:01 +00:00
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
),
|
2022-06-14 04:48:22 +00:00
|
|
|
)
|
2022-06-19 11:34:41 +00:00
|
|
|
],
|
2022-06-14 04:48:22 +00:00
|
|
|
),
|
2022-06-19 11:34:41 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Align(
|
2022-06-14 04:48:22 +00:00
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Icon(
|
|
|
|
Icons.chevron_right,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-07-28 14:08:27 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|