Moved the AccountName widgets to pull providers from context
This commit is contained in:
@@ -1,18 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'package:pweb/providers/account_name.dart';
|
import 'package:pweb/providers/account_name.dart';
|
||||||
|
|
||||||
|
|
||||||
class AccountNameActions extends StatelessWidget {
|
class AccountNameActions extends StatelessWidget {
|
||||||
const AccountNameActions({
|
const AccountNameActions({super.key});
|
||||||
super.key,
|
|
||||||
required this.state,
|
|
||||||
});
|
|
||||||
|
|
||||||
final AccountNameState state;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final state = context.watch<AccountNameState>();
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
if (state.isEditing) {
|
if (state.isEditing) {
|
||||||
|
|||||||
@@ -54,40 +54,37 @@ class _AccountNameBody extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final state = context.watch<AccountNameState>();
|
||||||
|
final provider = context.watch<AccountProvider>();
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return Consumer2<AccountNameState, AccountProvider>(
|
final currentName = provider.account?.name ?? state.initialName;
|
||||||
builder: (context, state, provider, _) {
|
state.syncName(currentName);
|
||||||
final currentName = provider.account?.name ?? state.initialName;
|
|
||||||
state.syncName(currentName);
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
AccountNameText(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
hintText: hintText,
|
||||||
children: [
|
inputWidth: _AccountNameConstants.inputWidth,
|
||||||
AccountNameText(
|
borderWidth: _AccountNameConstants.borderWidth,
|
||||||
state: state,
|
|
||||||
hintText: hintText,
|
|
||||||
inputWidth: _AccountNameConstants.inputWidth,
|
|
||||||
borderWidth: _AccountNameConstants.borderWidth,
|
|
||||||
),
|
|
||||||
const SizedBox(width: _AccountNameConstants.spacing),
|
|
||||||
AccountNameActions(state: state),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: _AccountNameConstants.errorSpacing),
|
const SizedBox(width: _AccountNameConstants.spacing),
|
||||||
if (state.errorText.isNotEmpty)
|
const AccountNameActions(),
|
||||||
Text(
|
|
||||||
state.errorText,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.error,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
const SizedBox(height: _AccountNameConstants.errorSpacing),
|
||||||
|
if (state.errorText.isNotEmpty)
|
||||||
|
Text(
|
||||||
|
state.errorText,
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.error,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'package:pweb/providers/account_name.dart';
|
import 'package:pweb/providers/account_name.dart';
|
||||||
|
|
||||||
|
|
||||||
class AccountNameText extends StatelessWidget {
|
class AccountNameText extends StatelessWidget {
|
||||||
const AccountNameText({
|
const AccountNameText({
|
||||||
super.key,
|
super.key,
|
||||||
required this.state,
|
|
||||||
required this.hintText,
|
required this.hintText,
|
||||||
required this.inputWidth,
|
required this.inputWidth,
|
||||||
required this.borderWidth,
|
required this.borderWidth,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AccountNameState state;
|
|
||||||
final String hintText;
|
final String hintText;
|
||||||
final double inputWidth;
|
final double inputWidth;
|
||||||
final double borderWidth;
|
final double borderWidth;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final state = context.watch<AccountNameState>();
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
if (state.isEditing) {
|
if (state.isEditing) {
|
||||||
|
|||||||
Reference in New Issue
Block a user