Преглед изворни кода

Merge pull request #349 from ente-io/fix_change_email

Fix change email
Manav пре 3 година
родитељ
комит
93f918d0c5

+ 2 - 0
lib/main.dart

@@ -29,6 +29,7 @@ import 'package:photos/services/remote_sync_service.dart';
 import 'package:photos/services/sync_service.dart';
 import 'package:photos/services/trash_sync_service.dart';
 import 'package:photos/services/update_service.dart';
+import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/app_lock.dart';
 import 'package:photos/ui/lock_screen.dart';
 import 'package:photos/utils/crypto_util.dart';
@@ -131,6 +132,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
   await NotificationService.instance.init();
   await Network.instance.init();
   await Configuration.instance.init();
+  await UserService.instance.init();
   await UpdateService.instance.init();
   await BillingService.instance.init();
   await CollectionsService.instance.init();

+ 13 - 3
lib/services/user_service.dart

@@ -33,16 +33,21 @@ class UserService {
   final _dio = Network.instance.getDio();
   final _logger = Logger((UserService).toString());
   final _config = Configuration.instance;
+  ValueNotifier<String> emailValueNotifier;
 
   UserService._privateConstructor();
-
   static final UserService instance = UserService._privateConstructor();
 
+  Future<void> init() async {
+    emailValueNotifier =
+        ValueNotifier<String>(Configuration.instance.getEmail());
+  }
+
   Future<void> getOtt(
     BuildContext context,
     String email, {
     bool isChangeEmail = false,
-    bool isCreateAccountScreen,
+    bool isCreateAccountScreen = false,
   }) async {
     final dialog = createProgressDialog(context, "Please wait...");
     await dialog.show();
@@ -266,6 +271,11 @@ class UserService {
     }
   }
 
+  Future<void> setEmail(String email) async {
+    await _config.setEmail(email);
+    emailValueNotifier.value = email ?? "";
+  }
+
   Future<void> changeEmail(
     BuildContext context,
     String email,
@@ -289,7 +299,7 @@ class UserService {
       await dialog.hide();
       if (response != null && response.statusCode == 200) {
         showToast(context, "Email changed to " + email);
-        _config.setEmail(email);
+        await setEmail(email);
         Navigator.of(context).popUntil((route) => route.isFirst);
         Bus.instance.fire(UserDetailsChangedEvent());
         return;

+ 1 - 1
lib/ui/email_entry_page.dart

@@ -108,7 +108,7 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
         buttonText: 'Create account',
         onPressedFunction: () {
           _config.setVolatilePassword(_passwordController1.text);
-          _config.setEmail(_email);
+          UserService.instance.setEmail(_email);
           UserService.instance
               .getOtt(context, _email, isCreateAccountScreen: true);
           FocusScope.of(context).unfocus();

+ 4 - 1
lib/ui/home_widget.dart

@@ -21,6 +21,7 @@ import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/events/sync_status_update_event.dart';
 import 'package:photos/events/tab_changed_event.dart';
 import 'package:photos/events/trigger_logout_event.dart';
+import 'package:photos/events/user_details_changed_event.dart';
 import 'package:photos/events/user_logged_out_event.dart';
 import 'package:photos/models/file_load_result.dart';
 import 'package:photos/models/galleryType.dart';
@@ -64,7 +65,9 @@ class HomeWidget extends StatefulWidget {
 class _HomeWidgetState extends State<HomeWidget> {
   static const _deviceFolderGalleryWidget = CollectionsGalleryWidget();
   static const _sharedCollectionGallery = SharedCollectionGallery();
-  static const _settingsPage = SettingsPage();
+  static final _settingsPage = SettingsPage(
+    emailNotifier: UserService.instance.emailValueNotifier,
+  );
   static const _headerWidget = HeaderWidget();
 
   final _logger = Logger("HomeWidgetState");

+ 1 - 1
lib/ui/login_page.dart

@@ -55,7 +55,7 @@ class _LoginPageState extends State<LoginPage> {
         isFormValid: _emailIsValid,
         buttonText: 'Log in',
         onPressedFunction: () {
-          _config.setEmail(_email);
+          UserService.instance.setEmail(_email);
           UserService.instance
               .getOtt(context, _email, isCreateAccountScreen: false);
           FocusScope.of(context).unfocus();

+ 1 - 1
lib/ui/ott_verification_page.dart

@@ -12,7 +12,7 @@ class OTTVerificationPage extends StatefulWidget {
   OTTVerificationPage(
     this.email, {
     this.isChangeEmail = false,
-    this.isCreateAccountScreen,
+    this.isCreateAccountScreen = false,
     Key key,
   }) : super(key: key);
 

+ 18 - 8
lib/ui/settings_page.dart

@@ -16,7 +16,8 @@ import 'package:photos/ui/settings/support_section_widget.dart';
 import 'package:photos/ui/settings/theme_switch_widget.dart';
 
 class SettingsPage extends StatelessWidget {
-  const SettingsPage({Key key}) : super(key: key);
+  final ValueNotifier<String> emailNotifier;
+  const SettingsPage({Key key, @required this.emailNotifier}) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
@@ -27,7 +28,6 @@ class SettingsPage extends StatelessWidget {
 
   Widget _getBody(BuildContext context) {
     final hasLoggedIn = Configuration.instance.getToken() != null;
-    final String email = Configuration.instance.getEmail();
     final List<Widget> contents = [];
     contents.add(
       Container(
@@ -36,13 +36,23 @@ class SettingsPage extends StatelessWidget {
           mainAxisAlignment: MainAxisAlignment.spaceBetween,
           crossAxisAlignment: CrossAxisAlignment.center,
           children: [
-            Text(
-              email,
-              style: Theme.of(context)
-                  .textTheme
-                  .subtitle1
-                  .copyWith(overflow: TextOverflow.ellipsis),
+            // // Thanks to the [AnimatedBuilder], only the widget displaying the
+            // // current email is rebuilt when `emailNotifier` notifies its
+            // // listeners.
+            AnimatedBuilder(
+              // [AnimatedBuilder] accepts any [Listenable] subtype.
+              animation: emailNotifier,
+              builder: (BuildContext context, Widget child) {
+                return Text(
+                  emailNotifier.value,
+                  style: Theme.of(context)
+                      .textTheme
+                      .subtitle1
+                      .copyWith(overflow: TextOverflow.ellipsis),
+                );
+              },
             ),
+
             (Platform.isAndroid)
                 ? ThemeSwitchWidget()
                 : const SizedBox.shrink(),

+ 1 - 1
pubspec.yaml

@@ -11,7 +11,7 @@ description: ente photos application
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 0.6.3+333
+version: 0.6.5+335
 
 environment:
   sdk: ">=2.10.0 <3.0.0"