Bläddra i källkod

display file count on settings title bar + move it to separate file

ashilkn 2 år sedan
förälder
incheckning
e79174c9ef

+ 1 - 1
lib/ui/settings/details_section_widget.dart

@@ -8,7 +8,7 @@ import 'package:photos/ui/payment/subscription.dart';
 import 'package:photos/utils/data_util.dart';
 
 class DetailsSectionWidget extends StatefulWidget {
-  const DetailsSectionWidget({required Key key}) : super(key: key);
+  const DetailsSectionWidget({Key? key}) : super(key: key);
 
   @override
   State<DetailsSectionWidget> createState() => _DetailsSectionWidgetState();

+ 64 - 0
lib/ui/settings/settings_title_bar_widget.dart

@@ -0,0 +1,64 @@
+import 'package:flutter/material.dart';
+import 'package:intl/intl.dart';
+import 'package:logging/logging.dart';
+import 'package:photos/models/user_details.dart';
+import 'package:photos/states/user_details_state.dart';
+import 'package:photos/theme/ente_theme.dart';
+import 'package:photos/ui/common/loading_widget.dart';
+
+class SettingsTitleBarWidget extends StatefulWidget {
+  const SettingsTitleBarWidget({Key? key}) : super(key: key);
+
+  @override
+  State<SettingsTitleBarWidget> createState() => _SettingsTitleBarWidgetState();
+}
+
+class _SettingsTitleBarWidgetState extends State<SettingsTitleBarWidget> {
+  @override
+  Widget build(BuildContext context) {
+    final logger = Logger((_SettingsTitleBarWidgetState).toString());
+    return Container(
+      padding: const EdgeInsets.symmetric(vertical: 4),
+      child: Padding(
+        padding: const EdgeInsets.fromLTRB(12, 0, 20, 0),
+        child: Row(
+          mainAxisAlignment: MainAxisAlignment.spaceBetween,
+          children: [
+            IconButton(
+              visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
+              onPressed: () {},
+              icon: const Icon(Icons.keyboard_double_arrow_left_outlined),
+            ),
+            FutureBuilder(
+              future: InheritedUserDetails.of(context)?.userDetails,
+              builder: (context, snapshot) {
+                if (InheritedUserDetails.of(context) == null) {
+                  logger.severe(
+                    (InheritedUserDetails).toString() +
+                        'not found before ' +
+                        (_SettingsTitleBarWidgetState).toString() +
+                        ' on tree',
+                  );
+                  return const SizedBox.shrink();
+                }
+                if (snapshot.hasData) {
+                  final userDetails = snapshot.data as UserDetails;
+                  return Text(
+                    "${NumberFormat().format(userDetails.fileCount)} Memories",
+                    style: getEnteTextTheme(context).largeBold,
+                  );
+                }
+                if (snapshot.hasError) {
+                  logger.severe('failed to load user details');
+                  return const SizedBox.shrink();
+                } else {
+                  return const EnteLoadingWidget();
+                }
+              },
+            )
+          ],
+        ),
+      ),
+    );
+  }
+}

+ 16 - 40
lib/ui/settings_page.dart

@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/services/feature_flag_service.dart';
+import 'package:photos/states/user_details_state.dart';
 import 'package:photos/theme/colors.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/settings/about_section_widget.dart';
@@ -16,6 +17,7 @@ import 'package:photos/ui/settings/danger_section_widget.dart';
 import 'package:photos/ui/settings/debug_section_widget.dart';
 import 'package:photos/ui/settings/details_section_widget.dart';
 import 'package:photos/ui/settings/security_section_widget.dart';
+import 'package:photos/ui/settings/settings_title_bar_widget.dart';
 import 'package:photos/ui/settings/social_section_widget.dart';
 import 'package:photos/ui/settings/support_section_widget.dart';
 import 'package:photos/ui/settings/theme_switch_widget.dart';
@@ -109,49 +111,23 @@ class SettingsPage extends StatelessWidget {
       ),
     );
 
-    return SingleChildScrollView(
-      child: Column(
-        mainAxisSize: MainAxisSize.min,
-        children: [
-          TitleBarWidget(),
-          Padding(
-            padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
-            child: Center(
-              child: ConstrainedBox(
-                constraints: const BoxConstraints(maxWidth: 428),
-                child: Column(
-                  children: contents,
+    return UserDetailsStateWidget(
+      child: SingleChildScrollView(
+        child: Column(
+          mainAxisSize: MainAxisSize.min,
+          children: [
+            const SettingsTitleBarWidget(),
+            Padding(
+              padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
+              child: Center(
+                child: ConstrainedBox(
+                  constraints: const BoxConstraints(maxWidth: 428),
+                  child: Column(
+                    children: contents,
+                  ),
                 ),
               ),
             ),
-          ),
-        ],
-      ),
-    );
-  }
-}
-
-class TitleBarWidget extends StatelessWidget {
-  const TitleBarWidget({Key key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return Container(
-      padding: const EdgeInsets.symmetric(vertical: 4),
-      child: Padding(
-        padding: const EdgeInsets.fromLTRB(12, 0, 20, 0),
-        child: Row(
-          mainAxisAlignment: MainAxisAlignment.spaceBetween,
-          children: [
-            IconButton(
-              visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
-              onPressed: () {},
-              icon: const Icon(Icons.keyboard_double_arrow_left_outlined),
-            ),
-            Text(
-              '2,532 memories',
-              style: getEnteTextTheme(context).largeBold,
-            ),
           ],
         ),
       ),