From d26ba840948e7ea86ecd3f07b5c1c7508a24e7d9 Mon Sep 17 00:00:00 2001 From: Arseni Date: Mon, 22 Dec 2025 21:38:26 +0300 Subject: [PATCH] Moved the AccountName widgets to pull providers from context --- .../profile/account/name/actions.dart | 10 ++-- .../settings/profile/account/name/name.dart | 53 +++++++++---------- .../settings/profile/account/name/text.dart | 5 +- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/frontend/pweb/lib/pages/settings/profile/account/name/actions.dart b/frontend/pweb/lib/pages/settings/profile/account/name/actions.dart index 8b102e7..68e6dc5 100644 --- a/frontend/pweb/lib/pages/settings/profile/account/name/actions.dart +++ b/frontend/pweb/lib/pages/settings/profile/account/name/actions.dart @@ -1,18 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + import 'package:pweb/providers/account_name.dart'; class AccountNameActions extends StatelessWidget { - const AccountNameActions({ - super.key, - required this.state, - }); - - final AccountNameState state; + const AccountNameActions({super.key}); @override Widget build(BuildContext context) { + final state = context.watch(); final theme = Theme.of(context); if (state.isEditing) { diff --git a/frontend/pweb/lib/pages/settings/profile/account/name/name.dart b/frontend/pweb/lib/pages/settings/profile/account/name/name.dart index d233138..4539e98 100644 --- a/frontend/pweb/lib/pages/settings/profile/account/name/name.dart +++ b/frontend/pweb/lib/pages/settings/profile/account/name/name.dart @@ -54,40 +54,37 @@ class _AccountNameBody extends StatelessWidget { @override Widget build(BuildContext context) { + final state = context.watch(); + final provider = context.watch(); final theme = Theme.of(context); - return Consumer2( - builder: (context, state, provider, _) { - final currentName = provider.account?.name ?? state.initialName; - state.syncName(currentName); + final currentName = provider.account?.name ?? state.initialName; + state.syncName(currentName); - return Column( - mainAxisSize: MainAxisSize.min, + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - AccountNameText( - state: state, - hintText: hintText, - inputWidth: _AccountNameConstants.inputWidth, - borderWidth: _AccountNameConstants.borderWidth, - ), - const SizedBox(width: _AccountNameConstants.spacing), - AccountNameActions(state: state), - ], + AccountNameText( + hintText: hintText, + inputWidth: _AccountNameConstants.inputWidth, + borderWidth: _AccountNameConstants.borderWidth, ), - const SizedBox(height: _AccountNameConstants.errorSpacing), - if (state.errorText.isNotEmpty) - Text( - state.errorText, - style: theme.textTheme.bodySmall?.copyWith( - color: theme.colorScheme.error, - ), - ), + const SizedBox(width: _AccountNameConstants.spacing), + const AccountNameActions(), ], - ); - }, + ), + const SizedBox(height: _AccountNameConstants.errorSpacing), + if (state.errorText.isNotEmpty) + Text( + state.errorText, + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.error, + ), + ), + ], ); } } diff --git a/frontend/pweb/lib/pages/settings/profile/account/name/text.dart b/frontend/pweb/lib/pages/settings/profile/account/name/text.dart index 31deb4b..d077d4d 100644 --- a/frontend/pweb/lib/pages/settings/profile/account/name/text.dart +++ b/frontend/pweb/lib/pages/settings/profile/account/name/text.dart @@ -1,24 +1,25 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + import 'package:pweb/providers/account_name.dart'; class AccountNameText extends StatelessWidget { const AccountNameText({ super.key, - required this.state, required this.hintText, required this.inputWidth, required this.borderWidth, }); - final AccountNameState state; final String hintText; final double inputWidth; final double borderWidth; @override Widget build(BuildContext context) { + final state = context.watch(); final theme = Theme.of(context); if (state.isEditing) {