show state on UI when storage details could not be fetched

This commit is contained in:
ashilkn 2022-10-19 16:40:21 +05:30
parent dff657df0a
commit a511b60938
2 changed files with 193 additions and 158 deletions

View file

@ -10,6 +10,7 @@ import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/common/loading_widget.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:photos/ui/payment/subscription.dart';
import 'package:photos/ui/settings/storage_error_widget.dart';
import 'package:photos/utils/data_util.dart';
class DetailsSectionWidget extends StatefulWidget {
@ -86,23 +87,22 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
child: Stack(
children: [
_background,
Padding(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 12),
child: FutureBuilder(
FutureBuilder(
future: inheritedUserDetails.userDetails,
builder: (context, snapshot) {
if (snapshot.hasData) {
return userDetails(snapshot.data as UserDetails);
}
if (snapshot.hasError) {
if (snapshot.hasData) {
_logger.severe(
'failed to load user details', snapshot.error);
return const EnteLoadingWidget();
'failed to load user details',
snapshot.error,
);
return const StorageErrorWidget();
}
return const EnteLoadingWidget();
},
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
@ -135,7 +135,9 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
convertBytesToGBs(userDetails.getFamilyOrPersonalUsage());
final totalStorageInGB = convertBytesToGBs(userDetails.getTotalStorage());
return Column(
return Padding(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 12),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Align(
@ -277,8 +279,9 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
"${shouldShowFreeSpaceInMBs ? convertBytesToMBs(freeSpaceInBytes) : _roundedFreeSpace(totalStorageInGB, usedSpaceInGB)}",
),
TextSpan(
text:
shouldShowFreeSpaceInMBs ? " MB free" : " GB free",
text: shouldShowFreeSpaceInMBs
? " MB free"
: " GB free",
)
],
),
@ -288,6 +291,7 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
],
)
],
),
);
}

View file

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:photos/theme/colors.dart';
import 'package:photos/theme/ente_theme.dart';
class StorageErrorWidget extends StatelessWidget {
const StorageErrorWidget({super.key});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Icon(
Icons.error_outline_outlined,
color: strokeBaseDark,
),
const SizedBox(height: 8),
Text(
"Your storage details could not be fetched",
style: getEnteTextTheme(context).small.copyWith(
color: textMutedDark,
),
),
],
),
);
}
}