refactor(legacy_auth): migrate link_phone to Riverpod

This commit is contained in:
2026-04-22 23:09:20 +02:00
parent 44c8949c07
commit c84287e803
7 changed files with 210 additions and 145 deletions

View File

@@ -1,46 +1,28 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/state/link_phone_view_state.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/providers/link_phone_state.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:sf_shared/sf_shared.dart';
import 'package:sf_tracking/sf_tracking.dart';
final legacyLinkPhoneViewModelProvider =
NotifierProvider.autoDispose<
LegacyLinkPhoneViewModel,
LegacyLinkPhoneViewState
>(LegacyLinkPhoneViewModel.new);
class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
late final SfTrackingRepository _tracking;
late final TextEditingController phoneNumberController;
late final TextEditingController codeController;
part 'link_phone_controller.g.dart';
@Riverpod(keepAlive: true)
class LinkPhoneController extends _$LinkPhoneController {
@override
LegacyLinkPhoneViewState build() {
_tracking = ref.read(sfTrackingProvider);
LinkPhoneState build() => const LinkPhoneState();
phoneNumberController = TextEditingController();
phoneNumberController.addListener(_onPhoneNumberChanged);
codeController = TextEditingController();
ref.onDispose(disposeControllers);
return const LegacyLinkPhoneViewState();
}
void _onPhoneNumberChanged() {
void setPhone(String value) {
if (value == state.phoneNumber) return;
state = state.copyWith(
phoneNumber: phoneNumberController.text,
phoneNumber: value,
errorMessage: '',
codeVerified: false,
);
}
void updateCountry(String isoCode) {
void setIsoCode(String isoCode) {
if (isoCode == state.isoCode) return;
state = state.copyWith(
isoCode: isoCode,
@@ -49,9 +31,12 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
);
}
void updateCode(String code) {
codeController.text = code;
state = state.copyWith(errorMessage: '', codeVerified: false);
void setCode(String code) {
state = state.copyWith(
code: code,
errorMessage: '',
codeVerified: false,
);
}
SfPhoneNumber? _parsePhone() {
@@ -89,12 +74,13 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
codeVerified: false,
);
final tracking = ref.read(sfTrackingProvider);
try {
// Stub: real call is ref.read(legacyAuthRepositoryProvider).requestPhoneCode(phone: parsed.e164)
// Stub: real call is ref.read(legacyAuthRepositoryProvider)
// .requestPhoneCode(phone: parsed.e164)
await Future<void>.delayed(const Duration(milliseconds: 500));
if (!ref.mounted) return;
unawaited(_tracking.legacyAuthLinkPhoneCodeRequested());
unawaited(tracking.legacyAuthLinkPhoneCodeRequested());
state = state.copyWith(
isLoading: false,
@@ -102,10 +88,7 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
sentTo: parsed.format(),
);
} catch (e) {
if (!ref.mounted) return;
unawaited(_tracking.legacyAuthLinkPhoneCodeRequestFailed(e.toString()));
unawaited(tracking.legacyAuthLinkPhoneCodeRequestFailed(e.toString()));
state = state.copyWith(
isLoading: false,
errorMessage: I18n.errorGeneric,
@@ -119,7 +102,7 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
final parsed = _parsePhone();
if (parsed == null) return;
final code = codeController.text.trim();
final code = state.code.trim();
if (code.isEmpty) {
state = state.copyWith(
errorMessage: I18n.errorMessageCodeIsEmpty,
@@ -134,21 +117,19 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
codeVerified: false,
);
final tracking = ref.read(sfTrackingProvider);
try {
// Stub: real call is ref.read(legacyAuthRepositoryProvider).verifyPhoneCode(phone: parsed.e164, code: code)
// Stub: real call is ref.read(legacyAuthRepositoryProvider)
// .verifyPhoneCode(phone: parsed.e164, code: code)
await Future<void>.delayed(const Duration(milliseconds: 500));
if (!ref.mounted) return;
unawaited(_tracking.legacyAuthLinkPhoneCodeVerified());
unawaited(tracking.legacyAuthLinkPhoneCodeVerified());
state = state.copyWith(isLoading: false, codeVerified: true);
} catch (e) {
if (!ref.mounted) return;
unawaited(
_tracking.legacyAuthLinkPhoneCodeVerificationFailed(e.toString()),
tracking.legacyAuthLinkPhoneCodeVerificationFailed(e.toString()),
);
state = state.copyWith(
isLoading: false,
errorMessage: I18n.errorGeneric,
@@ -156,10 +137,4 @@ class LegacyLinkPhoneViewModel extends Notifier<LegacyLinkPhoneViewState> {
);
}
}
void disposeControllers() {
phoneNumberController.removeListener(_onPhoneNumberChanged);
phoneNumberController.dispose();
codeController.dispose();
}
}

View File

@@ -0,0 +1,64 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'link_phone_controller.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(LinkPhoneController)
const linkPhoneControllerProvider = LinkPhoneControllerProvider._();
final class LinkPhoneControllerProvider
extends $NotifierProvider<LinkPhoneController, LinkPhoneState> {
const LinkPhoneControllerProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'linkPhoneControllerProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$linkPhoneControllerHash();
@$internal
@override
LinkPhoneController create() => LinkPhoneController();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(LinkPhoneState value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<LinkPhoneState>(value),
);
}
}
String _$linkPhoneControllerHash() =>
r'a405df66fc2723c4ef6271c440fdabca99625c7e';
abstract class _$LinkPhoneController extends $Notifier<LinkPhoneState> {
LinkPhoneState build();
@$mustCallSuper
@override
void runBuild() {
final created = build();
final ref = this.ref as $Ref<LinkPhoneState, LinkPhoneState>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<LinkPhoneState, LinkPhoneState>,
LinkPhoneState,
Object?,
Object?
>;
element.handleValue(ref, created);
}
}

View File

@@ -1,16 +1,17 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'link_phone_view_state.freezed.dart';
part 'link_phone_state.freezed.dart';
@freezed
abstract class LegacyLinkPhoneViewState with _$LegacyLinkPhoneViewState {
const factory LegacyLinkPhoneViewState({
abstract class LinkPhoneState with _$LinkPhoneState {
const factory LinkPhoneState({
@Default('') String phoneNumber,
@Default('ES') String isoCode,
@Default('') String code,
@Default('') String sentTo,
@Default('') String errorMessage,
@Default(false) bool isLoading,
@Default(false) bool codeRequested,
@Default(false) bool codeVerified,
}) = _LegacyLinkPhoneViewState;
}) = _LinkPhoneState;
}

View File

@@ -3,7 +3,7 @@
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'link_phone_view_state.dart';
part of 'link_phone_state.dart';
// **************************************************************************
// FreezedGenerator
@@ -12,40 +12,40 @@ part of 'link_phone_view_state.dart';
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$LegacyLinkPhoneViewState {
mixin _$LinkPhoneState {
String get phoneNumber; String get isoCode; String get sentTo; String get errorMessage; bool get isLoading; bool get codeRequested; bool get codeVerified;
/// Create a copy of LegacyLinkPhoneViewState
String get phoneNumber; String get isoCode; String get code; String get sentTo; String get errorMessage; bool get isLoading; bool get codeRequested; bool get codeVerified;
/// Create a copy of LinkPhoneState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$LegacyLinkPhoneViewStateCopyWith<LegacyLinkPhoneViewState> get copyWith => _$LegacyLinkPhoneViewStateCopyWithImpl<LegacyLinkPhoneViewState>(this as LegacyLinkPhoneViewState, _$identity);
$LinkPhoneStateCopyWith<LinkPhoneState> get copyWith => _$LinkPhoneStateCopyWithImpl<LinkPhoneState>(this as LinkPhoneState, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is LegacyLinkPhoneViewState&&(identical(other.phoneNumber, phoneNumber) || other.phoneNumber == phoneNumber)&&(identical(other.isoCode, isoCode) || other.isoCode == isoCode)&&(identical(other.sentTo, sentTo) || other.sentTo == sentTo)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.codeRequested, codeRequested) || other.codeRequested == codeRequested)&&(identical(other.codeVerified, codeVerified) || other.codeVerified == codeVerified));
return identical(this, other) || (other.runtimeType == runtimeType&&other is LinkPhoneState&&(identical(other.phoneNumber, phoneNumber) || other.phoneNumber == phoneNumber)&&(identical(other.isoCode, isoCode) || other.isoCode == isoCode)&&(identical(other.code, code) || other.code == code)&&(identical(other.sentTo, sentTo) || other.sentTo == sentTo)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.codeRequested, codeRequested) || other.codeRequested == codeRequested)&&(identical(other.codeVerified, codeVerified) || other.codeVerified == codeVerified));
}
@override
int get hashCode => Object.hash(runtimeType,phoneNumber,isoCode,sentTo,errorMessage,isLoading,codeRequested,codeVerified);
int get hashCode => Object.hash(runtimeType,phoneNumber,isoCode,code,sentTo,errorMessage,isLoading,codeRequested,codeVerified);
@override
String toString() {
return 'LegacyLinkPhoneViewState(phoneNumber: $phoneNumber, isoCode: $isoCode, sentTo: $sentTo, errorMessage: $errorMessage, isLoading: $isLoading, codeRequested: $codeRequested, codeVerified: $codeVerified)';
return 'LinkPhoneState(phoneNumber: $phoneNumber, isoCode: $isoCode, code: $code, sentTo: $sentTo, errorMessage: $errorMessage, isLoading: $isLoading, codeRequested: $codeRequested, codeVerified: $codeVerified)';
}
}
/// @nodoc
abstract mixin class $LegacyLinkPhoneViewStateCopyWith<$Res> {
factory $LegacyLinkPhoneViewStateCopyWith(LegacyLinkPhoneViewState value, $Res Function(LegacyLinkPhoneViewState) _then) = _$LegacyLinkPhoneViewStateCopyWithImpl;
abstract mixin class $LinkPhoneStateCopyWith<$Res> {
factory $LinkPhoneStateCopyWith(LinkPhoneState value, $Res Function(LinkPhoneState) _then) = _$LinkPhoneStateCopyWithImpl;
@useResult
$Res call({
String phoneNumber, String isoCode, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified
String phoneNumber, String isoCode, String code, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified
});
@@ -53,19 +53,20 @@ $Res call({
}
/// @nodoc
class _$LegacyLinkPhoneViewStateCopyWithImpl<$Res>
implements $LegacyLinkPhoneViewStateCopyWith<$Res> {
_$LegacyLinkPhoneViewStateCopyWithImpl(this._self, this._then);
class _$LinkPhoneStateCopyWithImpl<$Res>
implements $LinkPhoneStateCopyWith<$Res> {
_$LinkPhoneStateCopyWithImpl(this._self, this._then);
final LegacyLinkPhoneViewState _self;
final $Res Function(LegacyLinkPhoneViewState) _then;
final LinkPhoneState _self;
final $Res Function(LinkPhoneState) _then;
/// Create a copy of LegacyLinkPhoneViewState
/// Create a copy of LinkPhoneState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? phoneNumber = null,Object? isoCode = null,Object? sentTo = null,Object? errorMessage = null,Object? isLoading = null,Object? codeRequested = null,Object? codeVerified = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? phoneNumber = null,Object? isoCode = null,Object? code = null,Object? sentTo = null,Object? errorMessage = null,Object? isLoading = null,Object? codeRequested = null,Object? codeVerified = null,}) {
return _then(_self.copyWith(
phoneNumber: null == phoneNumber ? _self.phoneNumber : phoneNumber // ignore: cast_nullable_to_non_nullable
as String,isoCode: null == isoCode ? _self.isoCode : isoCode // ignore: cast_nullable_to_non_nullable
as String,code: null == code ? _self.code : code // ignore: cast_nullable_to_non_nullable
as String,sentTo: null == sentTo ? _self.sentTo : sentTo // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
@@ -78,8 +79,8 @@ as bool,
}
/// Adds pattern-matching-related methods to [LegacyLinkPhoneViewState].
extension LegacyLinkPhoneViewStatePatterns on LegacyLinkPhoneViewState {
/// Adds pattern-matching-related methods to [LinkPhoneState].
extension LinkPhoneStatePatterns on LinkPhoneState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
@@ -92,10 +93,10 @@ extension LegacyLinkPhoneViewStatePatterns on LegacyLinkPhoneViewState {
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _LegacyLinkPhoneViewState value)? $default,{required TResult orElse(),}){
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _LinkPhoneState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState() when $default != null:
case _LinkPhoneState() when $default != null:
return $default(_that);case _:
return orElse();
@@ -114,10 +115,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _LegacyLinkPhoneViewState value) $default,){
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _LinkPhoneState value) $default,){
final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState():
case _LinkPhoneState():
return $default(_that);case _:
throw StateError('Unexpected subclass');
@@ -135,10 +136,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _LegacyLinkPhoneViewState value)? $default,){
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _LinkPhoneState value)? $default,){
final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState() when $default != null:
case _LinkPhoneState() when $default != null:
return $default(_that);case _:
return null;
@@ -156,10 +157,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String phoneNumber, String isoCode, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String phoneNumber, String isoCode, String code, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState() when $default != null:
return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
case _LinkPhoneState() when $default != null:
return $default(_that.phoneNumber,_that.isoCode,_that.code,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
return orElse();
}
@@ -177,10 +178,10 @@ return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String phoneNumber, String isoCode, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String phoneNumber, String isoCode, String code, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified) $default,) {final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState():
return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
case _LinkPhoneState():
return $default(_that.phoneNumber,_that.isoCode,_that.code,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
throw StateError('Unexpected subclass');
}
@@ -197,10 +198,10 @@ return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String phoneNumber, String isoCode, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String phoneNumber, String isoCode, String code, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified)? $default,) {final _that = this;
switch (_that) {
case _LegacyLinkPhoneViewState() when $default != null:
return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
case _LinkPhoneState() when $default != null:
return $default(_that.phoneNumber,_that.isoCode,_that.code,_that.sentTo,_that.errorMessage,_that.isLoading,_that.codeRequested,_that.codeVerified);case _:
return null;
}
@@ -211,49 +212,50 @@ return $default(_that.phoneNumber,_that.isoCode,_that.sentTo,_that.errorMessage,
/// @nodoc
class _LegacyLinkPhoneViewState implements LegacyLinkPhoneViewState {
const _LegacyLinkPhoneViewState({this.phoneNumber = '', this.isoCode = 'ES', this.sentTo = '', this.errorMessage = '', this.isLoading = false, this.codeRequested = false, this.codeVerified = false});
class _LinkPhoneState implements LinkPhoneState {
const _LinkPhoneState({this.phoneNumber = '', this.isoCode = 'ES', this.code = '', this.sentTo = '', this.errorMessage = '', this.isLoading = false, this.codeRequested = false, this.codeVerified = false});
@override@JsonKey() final String phoneNumber;
@override@JsonKey() final String isoCode;
@override@JsonKey() final String code;
@override@JsonKey() final String sentTo;
@override@JsonKey() final String errorMessage;
@override@JsonKey() final bool isLoading;
@override@JsonKey() final bool codeRequested;
@override@JsonKey() final bool codeVerified;
/// Create a copy of LegacyLinkPhoneViewState
/// Create a copy of LinkPhoneState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$LegacyLinkPhoneViewStateCopyWith<_LegacyLinkPhoneViewState> get copyWith => __$LegacyLinkPhoneViewStateCopyWithImpl<_LegacyLinkPhoneViewState>(this, _$identity);
_$LinkPhoneStateCopyWith<_LinkPhoneState> get copyWith => __$LinkPhoneStateCopyWithImpl<_LinkPhoneState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LegacyLinkPhoneViewState&&(identical(other.phoneNumber, phoneNumber) || other.phoneNumber == phoneNumber)&&(identical(other.isoCode, isoCode) || other.isoCode == isoCode)&&(identical(other.sentTo, sentTo) || other.sentTo == sentTo)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.codeRequested, codeRequested) || other.codeRequested == codeRequested)&&(identical(other.codeVerified, codeVerified) || other.codeVerified == codeVerified));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LinkPhoneState&&(identical(other.phoneNumber, phoneNumber) || other.phoneNumber == phoneNumber)&&(identical(other.isoCode, isoCode) || other.isoCode == isoCode)&&(identical(other.code, code) || other.code == code)&&(identical(other.sentTo, sentTo) || other.sentTo == sentTo)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.codeRequested, codeRequested) || other.codeRequested == codeRequested)&&(identical(other.codeVerified, codeVerified) || other.codeVerified == codeVerified));
}
@override
int get hashCode => Object.hash(runtimeType,phoneNumber,isoCode,sentTo,errorMessage,isLoading,codeRequested,codeVerified);
int get hashCode => Object.hash(runtimeType,phoneNumber,isoCode,code,sentTo,errorMessage,isLoading,codeRequested,codeVerified);
@override
String toString() {
return 'LegacyLinkPhoneViewState(phoneNumber: $phoneNumber, isoCode: $isoCode, sentTo: $sentTo, errorMessage: $errorMessage, isLoading: $isLoading, codeRequested: $codeRequested, codeVerified: $codeVerified)';
return 'LinkPhoneState(phoneNumber: $phoneNumber, isoCode: $isoCode, code: $code, sentTo: $sentTo, errorMessage: $errorMessage, isLoading: $isLoading, codeRequested: $codeRequested, codeVerified: $codeVerified)';
}
}
/// @nodoc
abstract mixin class _$LegacyLinkPhoneViewStateCopyWith<$Res> implements $LegacyLinkPhoneViewStateCopyWith<$Res> {
factory _$LegacyLinkPhoneViewStateCopyWith(_LegacyLinkPhoneViewState value, $Res Function(_LegacyLinkPhoneViewState) _then) = __$LegacyLinkPhoneViewStateCopyWithImpl;
abstract mixin class _$LinkPhoneStateCopyWith<$Res> implements $LinkPhoneStateCopyWith<$Res> {
factory _$LinkPhoneStateCopyWith(_LinkPhoneState value, $Res Function(_LinkPhoneState) _then) = __$LinkPhoneStateCopyWithImpl;
@override @useResult
$Res call({
String phoneNumber, String isoCode, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified
String phoneNumber, String isoCode, String code, String sentTo, String errorMessage, bool isLoading, bool codeRequested, bool codeVerified
});
@@ -261,19 +263,20 @@ $Res call({
}
/// @nodoc
class __$LegacyLinkPhoneViewStateCopyWithImpl<$Res>
implements _$LegacyLinkPhoneViewStateCopyWith<$Res> {
__$LegacyLinkPhoneViewStateCopyWithImpl(this._self, this._then);
class __$LinkPhoneStateCopyWithImpl<$Res>
implements _$LinkPhoneStateCopyWith<$Res> {
__$LinkPhoneStateCopyWithImpl(this._self, this._then);
final _LegacyLinkPhoneViewState _self;
final $Res Function(_LegacyLinkPhoneViewState) _then;
final _LinkPhoneState _self;
final $Res Function(_LinkPhoneState) _then;
/// Create a copy of LegacyLinkPhoneViewState
/// Create a copy of LinkPhoneState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? phoneNumber = null,Object? isoCode = null,Object? sentTo = null,Object? errorMessage = null,Object? isLoading = null,Object? codeRequested = null,Object? codeVerified = null,}) {
return _then(_LegacyLinkPhoneViewState(
@override @pragma('vm:prefer-inline') $Res call({Object? phoneNumber = null,Object? isoCode = null,Object? code = null,Object? sentTo = null,Object? errorMessage = null,Object? isLoading = null,Object? codeRequested = null,Object? codeVerified = null,}) {
return _then(_LinkPhoneState(
phoneNumber: null == phoneNumber ? _self.phoneNumber : phoneNumber // ignore: cast_nullable_to_non_nullable
as String,isoCode: null == isoCode ? _self.isoCode : isoCode // ignore: cast_nullable_to_non_nullable
as String,code: null == code ? _self.code : code // ignore: cast_nullable_to_non_nullable
as String,sentTo: null == sentTo ? _self.sentTo : sentTo // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable

View File

@@ -1,12 +1,12 @@
import 'package:legacy_auth/src/features/link_phone/presentation/state/link_phone_view_model.dart';
import 'package:legacy_theme/legacy_theme.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/providers/link_phone_controller.dart';
import 'package:legacy_theme/legacy_theme.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
class LegacyRequestLinkPhoneScreen extends ConsumerStatefulWidget {
final NavigationContract navigationContract;
const LegacyRequestLinkPhoneScreen({
@@ -15,10 +15,39 @@ class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
});
@override
Widget build(BuildContext context, WidgetRef ref) {
ConsumerState<LegacyRequestLinkPhoneScreen> createState() =>
_LegacyRequestLinkPhoneScreenState();
}
final viewModel = ref.read(legacyLinkPhoneViewModelProvider.notifier);
final viewState = ref.watch(legacyLinkPhoneViewModelProvider);
class _LegacyRequestLinkPhoneScreenState
extends ConsumerState<LegacyRequestLinkPhoneScreen> {
late final TextEditingController _phoneController;
@override
void initState() {
super.initState();
final initial = ref.read(linkPhoneControllerProvider).phoneNumber;
_phoneController = TextEditingController(text: initial);
_phoneController.addListener(_onPhoneChanged);
}
@override
void dispose() {
_phoneController.removeListener(_onPhoneChanged);
_phoneController.dispose();
super.dispose();
}
void _onPhoneChanged() {
ref.read(linkPhoneControllerProvider.notifier).setPhone(
_phoneController.text,
);
}
@override
Widget build(BuildContext context) {
final viewState = ref.watch(linkPhoneControllerProvider);
final notifier = ref.read(linkPhoneControllerProvider.notifier);
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
@@ -43,7 +72,6 @@ class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
style: const TextStyle(fontSize: 16, letterSpacing: 0),
),
const SizedBox(height: 48),
Column(
spacing: 8,
children: [
@@ -62,12 +90,12 @@ class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
initialSelection: viewState.isoCode,
onChanged: (country) {
final code = country.code;
if (code != null) viewModel.updateCountry(code);
if (code != null) notifier.setIsoCode(code);
},
),
Expanded(
child: CustomTextField(
controller: viewModel.phoneNumberController,
controller: _phoneController,
hint: context.translate(I18n.phoneNumber),
keyboardType: TextInputType.number,
),
@@ -76,9 +104,7 @@ class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
),
],
),
const SizedBox(height: 16),
if (viewState.errorMessage.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
@@ -90,15 +116,13 @@ class LegacyRequestLinkPhoneScreen extends ConsumerWidget {
),
),
],
const SizedBox(height: 24),
PrimaryButton(
onPressed: () async {
await viewModel.requestCode();
final updatedState = ref.read(legacyLinkPhoneViewModelProvider);
if (updatedState.errorMessage.isEmpty) {
navigationContract.pushTo(AppRoutes.phoneCode);
await notifier.requestCode();
final updated = ref.read(linkPhoneControllerProvider);
if (updated.codeRequested) {
widget.navigationContract.pushTo(AppRoutes.phoneCode);
}
},
text: context.translate(I18n.next),

View File

@@ -1,10 +1,10 @@
import 'package:legacy_auth/src/features/link_phone/presentation/state/link_phone_view_model.dart';
import 'package:legacy_theme/legacy_theme.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/widgets/link_phone_code_input.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:navigation/navigation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/providers/link_phone_controller.dart';
import 'package:legacy_auth/src/features/link_phone/presentation/widgets/link_phone_code_input.dart';
import 'package:legacy_theme/legacy_theme.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
@@ -17,9 +17,8 @@ class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final viewModel = ref.read(legacyLinkPhoneViewModelProvider.notifier);
final viewState = ref.watch(legacyLinkPhoneViewModelProvider);
final viewState = ref.watch(linkPhoneControllerProvider);
final notifier = ref.read(linkPhoneControllerProvider.notifier);
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
@@ -34,7 +33,10 @@ class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
children: [
Text(
context.translate(I18n.connect),
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
),
),
const SizedBox(height: 24),
Text.rich(
@@ -55,15 +57,13 @@ class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
const SizedBox(height: 48),
Text(
context.translate(I18n.enterCodeHere),
style: TextStyle(fontSize: 16),
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 24),
LegacyLinkPhoneCodeInput(
length: 6,
onCodeChanged: viewModel.updateCode,
onCodeChanged: notifier.setCode,
),
if (viewState.errorMessage.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
@@ -81,12 +81,9 @@ class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
children: [
PrimaryButton(
onPressed: () async {
await viewModel.verifyCode();
final updatedState = ref.read(
legacyLinkPhoneViewModelProvider,
);
if (updatedState.codeVerified) {
await notifier.verifyCode();
final updated = ref.read(linkPhoneControllerProvider);
if (updated.codeVerified) {
navigationContract.pushTo(AppRoutes.legacyLogin);
}
},
@@ -96,7 +93,7 @@ class LegacyVerifyLinkPhoneCodeScreen extends ConsumerWidget {
const SizedBox(height: 24),
Text(
context.translate(I18n.didNotReceiveIt),
style: TextStyle(
style: const TextStyle(
fontSize: 18,
letterSpacing: 0,
height: 1.5,

View File

@@ -38,6 +38,7 @@ dependencies:
get_it: ^9.0.5
go_router: ^17.0.0
flutter_riverpod: ^3.0.3
riverpod_annotation: ^3.0.3
freezed_annotation: ^3.1.0
freezed: ^3.2.3
dio: ^5.9.2