fixed logout at refresh failed

This commit is contained in:
amirrezaghabeli
2026-04-16 16:36:55 +03:30
parent 41bba5d32c
commit cc0032b21d
12 changed files with 475 additions and 344 deletions
+8 -1
View File
@@ -41,7 +41,14 @@ List<SingleChildWidget> get essentialProviders {
List<SingleChildWidget> get cores { List<SingleChildWidget> get cores {
return [ return [
Provider(create: (context) => NetworkManager(context.read()), lazy: true), Provider(
create: (context) {
final nm = NetworkManager(context.read());
return nm;
},
lazy: true,
),
ChangeNotifierProvider(create: (context) => ThemeProvider(), lazy: true), ChangeNotifierProvider(create: (context) => ThemeProvider(), lazy: true),
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => NotificationStateService(), create: (context) => NotificationStateService(),
+12
View File
@@ -17,6 +17,14 @@ class NetworkManager {
bool _interceptorsAdded = false; bool _interceptorsAdded = false;
final SharedPreferences _prefs; final SharedPreferences _prefs;
/// Callback invoked when refresh token fails (expired, missing, or errored).
/// Should clear local auth state and navigate to the login screen.
/// // Callback to be called when refresh token fails (logout callback)
Future<void> Function()? _onAuthFailed;
void setAuthFailed(Future<void> Function() callback) {
_onAuthFailed = callback;
}
NetworkManager(this._prefs) NetworkManager(this._prefs)
: mainDio = Dio( : mainDio = Dio(
BaseOptions( BaseOptions(
@@ -75,6 +83,10 @@ class NetworkManager {
mainDio.options.headers['Authorization'] = 'Bearer $newAccessToken'; mainDio.options.headers['Authorization'] = 'Bearer $newAccessToken';
return handler.resolve(await mainDio.fetch(error.requestOptions)); return handler.resolve(await mainDio.fetch(error.requestOptions));
} }
// Refresh token failed force logout
appLogger.error('❌ Refresh token failed, triggering logout');
await _onAuthFailed!();
} }
return handler.next(error); return handler.next(error);
}, },
+24 -1
View File
@@ -10,6 +10,7 @@ import 'package:provider/single_child_widget.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:tm_app/core/config/dependencies.dart'; import 'package:tm_app/core/config/dependencies.dart';
import 'package:tm_app/core/config/web_url_strategy.dart'; import 'package:tm_app/core/config/web_url_strategy.dart';
import 'package:tm_app/core/network/network_manager.dart';
import 'package:tm_app/core/services/cache_init.dart'; import 'package:tm_app/core/services/cache_init.dart';
import 'package:tm_app/core/services/firebase_service.dart'; import 'package:tm_app/core/services/firebase_service.dart';
import 'package:tm_app/core/theme/theme_provider.dart'; import 'package:tm_app/core/theme/theme_provider.dart';
@@ -45,6 +46,8 @@ void main() async {
await FirebaseService().initializeApp(); await FirebaseService().initializeApp();
runApp(MultiProvider(providers: providers, child: const MyApp())); runApp(MultiProvider(providers: providers, child: const MyApp()));
} }
@@ -57,6 +60,24 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
Future<void> setupInteractedMessage() async { Future<void> setupInteractedMessage() async {
final overlayCtx = rootNavigatorKey.currentContext;
final networkManager = overlayCtx?.read<NetworkManager>();
networkManager?.setAuthFailed(() async {
debugPrint('🔄 Refresh token failed - navigating to auth screen');
// Use appRouter to navigate to auth screen
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.clear();
appRouter.go('/login');
});
// networkManager.onAuthFailure(() async {
// debugPrint('🔄 Refresh token failed - navigating to auth screen');
// // Use appRouter to navigate to auth screen
// final SharedPreferences _prefs = await SharedPreferences.getInstance();
// await _prefs.clear();
// appRouter.go(AppRoutes.auth);
// });
final initialMessage = await FirebaseMessaging.instance.getInitialMessage(); final initialMessage = await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) { if (initialMessage != null) {
@@ -65,7 +86,7 @@ class _MyAppState extends State<MyApp> {
// if (kIsWeb) { // if (kIsWeb) {
FirebaseMessaging.onMessage.listen((event) { FirebaseMessaging.onMessage.listen((event) {
final overlayCtx = rootNavigatorKey.currentContext;
if (overlayCtx != null) { if (overlayCtx != null) {
if (overlayCtx.mounted) { if (overlayCtx.mounted) {
@@ -88,6 +109,8 @@ class _MyAppState extends State<MyApp> {
); );
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
+17 -3
View File
@@ -24,8 +24,8 @@ class AuthViewModel with ChangeNotifier {
bool _obscurePassword = true; bool _obscurePassword = true;
bool get obscurePassword => _obscurePassword; bool get obscurePassword => _obscurePassword;
bool get isLoginEnabled => // bool get isLoginEnabled =>
usernameController.text.isNotEmpty && passwordController.text.isNotEmpty; // usernameController.text.isNotEmpty && passwordController.text.isNotEmpty;
// Auth state // Auth state
bool _isLoading = false; bool _isLoading = false;
@@ -59,8 +59,22 @@ class AuthViewModel with ChangeNotifier {
} }
} }
// void _onTextChanged() {
// notifyListeners();
// }
bool _isLoginEnabled = false;
bool get isLoginEnabled => _isLoginEnabled;
void _onTextChanged() { void _onTextChanged() {
notifyListeners(); final newValue =
usernameController.text.isNotEmpty &&
passwordController.text.isNotEmpty;
if (newValue != _isLoginEnabled) {
_isLoginEnabled = newValue;
notifyListeners();
}
} }
Future<void> login() async { Future<void> login() async {
@@ -9,6 +9,7 @@ import 'package:tm_app/view_models/liked_tenders_view_model.dart';
import 'package:tm_app/views/liked_tenders/widgets/liked_tenders_list_item.dart'; import 'package:tm_app/views/liked_tenders/widgets/liked_tenders_list_item.dart';
import 'package:tm_app/views/shared/page_selection_dialog.dart'; import 'package:tm_app/views/shared/page_selection_dialog.dart';
import '../../../core/routes/app_routes.dart';
import '../../../core/utils/app_toast.dart'; import '../../../core/utils/app_toast.dart';
import '../../shared/desktop_navigation_widget.dart'; import '../../shared/desktop_navigation_widget.dart';
import '../../shared/tablet_desktop_appbar.dart'; import '../../shared/tablet_desktop_appbar.dart';
@@ -175,7 +176,13 @@ class _LikedTendersDesktopPageState extends State<LikedTendersDesktopPage> {
), ),
), ),
SizedBox(width: 5.0.w()), SizedBox(width: 5.0.w()),
SvgPicture.asset(AssetsManager.arrowDownSmall,colorFilter: ColorFilter.mode(AppColors.grey60, BlendMode.srcIn),), SvgPicture.asset(
AssetsManager.arrowDownSmall,
colorFilter: ColorFilter.mode(
AppColors.grey60,
BlendMode.srcIn,
),
),
SizedBox(width: 5.0.w()), SizedBox(width: 5.0.w()),
], ],
), ),
@@ -230,7 +237,13 @@ class _LikedTendersDesktopPageState extends State<LikedTendersDesktopPage> {
viewModel.removeTenderById(item.tenderId!); viewModel.removeTenderById(item.tenderId!);
} }
}, },
child: LikedListItem(tender: item.tender!, isDesktop: true), child: LikedListItem(
tender: item.tender!,
isDesktop: true,
onTap: () {
TenderDetailRouteData(tenderId: item.tenderId!).push(context);
},
),
), ),
); );
}, },
@@ -10,6 +10,8 @@ import 'package:tm_app/views/liked_tenders/strings/liked_tenders_strings.dart';
import 'package:tm_app/views/liked_tenders/widgets/liked_tenders_list_item.dart'; import 'package:tm_app/views/liked_tenders/widgets/liked_tenders_list_item.dart';
import 'package:tm_app/views/login/widgets/widgets.dart'; import 'package:tm_app/views/login/widgets/widgets.dart';
import '../../../core/routes/app_routes.dart';
class LikedTendersMobilePage extends StatefulWidget { class LikedTendersMobilePage extends StatefulWidget {
const LikedTendersMobilePage({super.key}); const LikedTendersMobilePage({super.key});
@@ -209,7 +211,14 @@ class _LikedTendersMobilePageState extends State<LikedTendersMobilePage> {
viewModel.removeTenderById(item.tenderId!); viewModel.removeTenderById(item.tenderId!);
} }
}, },
child: LikedListItem(tender: item.tender!), child: LikedListItem(
tender: item.tender!,
onTap: () {
TenderDetailRouteData(
tenderId: item.tenderId!,
).push(context);
},
),
), ),
); );
} else { } else {
@@ -11,6 +11,7 @@ import 'package:tm_app/views/liked_tenders/widgets/liked_tenders_list_item.dart'
import 'package:tm_app/views/shared/page_selection_dialog.dart'; import 'package:tm_app/views/shared/page_selection_dialog.dart';
import 'package:tm_app/views/shared/tender_app_bar.dart'; import 'package:tm_app/views/shared/tender_app_bar.dart';
import '../../../core/routes/app_routes.dart';
import '../../../core/utils/app_toast.dart'; import '../../../core/utils/app_toast.dart';
import '../../shared/tablet_desktop_appbar.dart'; import '../../shared/tablet_desktop_appbar.dart';
import '../../shared/tablet_navigation_widget.dart'; import '../../shared/tablet_navigation_widget.dart';
@@ -256,7 +257,12 @@ class _LikedTendersTabletPageState extends State<LikedTendersTabletPage> {
viewModel.removeTenderById(item.tenderId!); viewModel.removeTenderById(item.tenderId!);
} }
}, },
child: LikedListItem(tender: item.tender!), child: LikedListItem(
tender: item.tender!,
onTap: () {
TenderDetailRouteData(tenderId: item.tenderId!).push(context);
},
),
), ),
); );
}, },
@@ -14,161 +14,169 @@ import '../../shared/flag.dart';
class LikedListItem extends StatelessWidget { class LikedListItem extends StatelessWidget {
const LikedListItem({ const LikedListItem({
required this.tender, required this.tender,
required this.onTap,
this.isDesktop = false, this.isDesktop = false,
super.key, super.key,
}); });
final TenderData tender; final TenderData tender;
final bool isDesktop; final bool isDesktop;
final VoidCallback onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final viewModel = context.read<LikedTendersViewModel>(); final viewModel = context.read<LikedTendersViewModel>();
return Container( return InkWell(
decoration: BoxDecoration( onTap: onTap,
color: AppColors.cardBackground, child: Container(
borderRadius: BorderRadius.circular(4), decoration: BoxDecoration(
border: Border.all(color: AppColors.grey30), color: AppColors.cardBackground,
), borderRadius: BorderRadius.circular(4),
width: double.infinity, border: Border.all(color: AppColors.grey30),
height: 250.0.h(), ),
child: Padding( width: double.infinity,
padding: EdgeInsets.symmetric(horizontal: 16.0.w(), vertical: 16.0.h()), height: 250.0.h(),
child: Column( child: Padding(
crossAxisAlignment: CrossAxisAlignment.start, padding: EdgeInsets.symmetric(
children: [ horizontal: 16.0.w(),
SizedBox(height: 10.0.h()), vertical: 16.0.h(),
isDesktop ),
? Row( child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Expanded( children: [
child: Container( SizedBox(height: 10.0.h()),
padding: EdgeInsets.symmetric( isDesktop
horizontal: 10.0.w(), ? Row(
vertical: 5.0.h(),
),
decoration: BoxDecoration(
color: AppColors.primary20,
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${HomeStrings.tenderDeadline} :',
style: TextStyle(
fontSize: 15.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.textBlue,
),
),
Text(
timeConvertor(tender.tenderDeadline!),
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.grey80,
),
),
],
),
),
),
SizedBox(width: 8.0.w()),
InkWell(
child: SvgPicture.asset(
AssetsManager.trash,
width: 32.0.w(),
height: 32.0.h(),
),
onTap: () {
if (tender.id != null) {
viewModel.removeTenderById(tender.id!);
}
},
),
],
)
: Container(
padding: EdgeInsets.symmetric(
horizontal: 10.0.w(),
vertical: 5.0.h(),
),
decoration: BoxDecoration(
color: AppColors.primary20,
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Expanded(
'${HomeStrings.tenderDeadline} :', child: Container(
style: TextStyle( padding: EdgeInsets.symmetric(
fontSize: 15.0.sp(), horizontal: 10.0.w(),
fontWeight: FontWeight.w500, vertical: 5.0.h(),
color: AppColors.textBlue, ),
decoration: BoxDecoration(
color: AppColors.primary20,
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${HomeStrings.tenderDeadline} :',
style: TextStyle(
fontSize: 15.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.textBlue,
),
),
Text(
timeConvertor(tender.tenderDeadline!),
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.grey80,
),
),
],
),
), ),
), ),
Text( SizedBox(width: 8.0.w()),
timeConvertor(tender.tenderDeadline!), InkWell(
style: TextStyle( child: SvgPicture.asset(
fontSize: 14.0.sp(), AssetsManager.trash,
fontWeight: FontWeight.w500, width: 32.0.w(),
color: AppColors.grey80, height: 32.0.h(),
), ),
onTap: () {
if (tender.id != null) {
viewModel.removeTenderById(tender.id!);
}
},
), ),
], ],
)
: Container(
padding: EdgeInsets.symmetric(
horizontal: 10.0.w(),
vertical: 5.0.h(),
),
decoration: BoxDecoration(
color: AppColors.primary20,
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${HomeStrings.tenderDeadline} :',
style: TextStyle(
fontSize: 15.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.textBlue,
),
),
Text(
timeConvertor(tender.tenderDeadline!),
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.grey80,
),
),
],
),
), ),
), SizedBox(height: 12.0.h()),
SizedBox(height: 12.0.h()), Text(
Text( tender.title!,
tender.title!,
style: TextStyle(
overflow: TextOverflow.ellipsis,
fontSize: 16.0.sp(),
fontWeight: FontWeight.w600,
color: AppColors.grey80,
),
),
SizedBox(height: 8.0.h()),
SizedBox(
width: double.infinity,
child: Text(
tender.description!,
textAlign: TextAlign.left,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
fontSize: 14.0.sp(), overflow: TextOverflow.ellipsis,
fontWeight: FontWeight.w400, fontSize: 16.0.sp(),
color: AppColors.grey70, fontWeight: FontWeight.w600,
color: AppColors.grey80,
), ),
), ),
), SizedBox(height: 8.0.h()),
const Spacer(), SizedBox(
width: double.infinity,
Row( child: Text(
children: [ tender.description!,
SvgPicture.asset(AssetsManager.location), textAlign: TextAlign.left,
SizedBox(width: 1.0.w()), maxLines: 4,
Text( overflow: TextOverflow.ellipsis,
tender.countryCode!,
style: TextStyle( style: TextStyle(
fontSize: 12.0.sp(), fontSize: 14.0.sp(),
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
color: AppColors.grey80, color: AppColors.grey70,
), ),
), ),
SizedBox(width: 8.0.w()), ),
tender.countryCode != null const Spacer(),
? Flag(countryCode: tender.countryCode!)
: const Flag(countryCode: ''),
const Spacer(),
SizedBox(width: 30.0.w()), Row(
], children: [
), SvgPicture.asset(AssetsManager.location),
], SizedBox(width: 1.0.w()),
Text(
tender.countryCode!,
style: TextStyle(
fontSize: 12.0.sp(),
fontWeight: FontWeight.w400,
color: AppColors.grey80,
),
),
SizedBox(width: 8.0.w()),
tender.countryCode != null
? Flag(countryCode: tender.countryCode!)
: const Flag(countryCode: ''),
const Spacer(),
SizedBox(width: 30.0.w()),
],
),
],
),
), ),
), ),
); );
+74 -61
View File
@@ -56,76 +56,89 @@ class _LoginDesktopPageState extends State<LoginDesktopPage> {
child: Center( child: Center(
child: SizedBox( child: SizedBox(
width: 364, width: 364,
child: Consumer<AuthViewModel>( child: Column(
builder: (context, viewModel, _) { mainAxisSize: MainAxisSize.min,
return Column( children: [
mainAxisSize: MainAxisSize.min, SvgPicture.asset(
children: [ AssetsManager.logoBig,
SvgPicture.asset( width: 320,
AssetsManager.logoBig, height: 50,
width: 320, fit: BoxFit.cover,
height: 50, ),
fit: BoxFit.cover, SizedBox(height: 72.0.h()),
), const LoginTitle(),
SizedBox(height: 72.0.h()), SizedBox(height: 32.0.h()),
const LoginTitle(), LoginTextField(
SizedBox(height: 32.0.h()), controller: viewModel.usernameController,
LoginTextField( focusNode: viewModel.usernameFocus,
controller: viewModel.usernameController, label: LoginStrings.usernameLabel,
focusNode: viewModel.usernameFocus, iconPath: AssetsManager.userIcon,
label: LoginStrings.usernameLabel, fieldHeight: 60.0.h(),
iconPath: AssetsManager.userIcon, borderRedus: 12,
fieldHeight: 60.0.h(), prefixIconPadding: 7.0.w(),
borderRedus: 12, ),
prefixIconPadding: 7.0.w(), SizedBox(height: 16.0.h()),
), Selector<AuthViewModel, bool>(
SizedBox(height: 16.0.h()), selector: (_, vm) => vm.obscurePassword,
LoginTextField( builder: (_, obscurePassword, __) {
return LoginTextField(
controller: viewModel.passwordController, controller: viewModel.passwordController,
focusNode: viewModel.passwordFocus, focusNode: viewModel.passwordFocus,
label: LoginStrings.passwordLabel, label: LoginStrings.passwordLabel,
iconPath: AssetsManager.passwordIcon, iconPath: AssetsManager.passwordIcon,
prefixIconPadding: 7.0.w(),
isPassword: true, isPassword: true,
obscureText: viewModel.obscurePassword, obscureText: obscurePassword,
fieldHeight: 60.0.h(),
onToggleVisibility: onToggleVisibility:
viewModel.togglePasswordVisibility, viewModel.togglePasswordVisibility,
borderRedus: 12, );
), },
SizedBox(height: 32.0.h()), ),
if (viewModel.isLoading) SizedBox(height: 32.0.h()),
const BaseButton(
isEnabled: false, /// ✅ Only this part rebuilds now
onPressed: null, Selector<AuthViewModel, bool>(
isLoading: true, selector: (_, vm) => vm.isLoading,
) builder: (_, isLoading, __) {
else return Selector<AuthViewModel, bool>(
BaseButton( selector: (_, vm) => vm.isLoginEnabled,
isEnabled: viewModel.isLoginEnabled, builder: (_, isEnabled, __) {
onPressed: () async { if (isLoading) {
if (viewModel.isLoginEnabled) { return BaseButton(
await viewModel.login(); isEnabled: false,
} onPressed: null,
}, isLoading: true,
), textColor: AppColors.white,
const SizedBox(height: 32.0), );
TextButton( }
onPressed: () {
const ForgotPasswordRouteData().push(context); return BaseButton(
isEnabled: isEnabled,
onPressed:
isEnabled
? () async {
await viewModel.login();
}
: null,
);
}, },
child: Text( );
LoginStrings.forgotPassword, },
style: TextStyle( ),
fontSize: 14.0.sp(), const SizedBox(height: 32.0),
fontWeight: FontWeight.w500, TextButton(
color: AppColors.mainBlue, onPressed: () {
), const ForgotPasswordRouteData().push(context);
), },
child: Text(
LoginStrings.forgotPassword,
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.mainBlue,
), ),
], ),
); ),
}, ],
), ),
), ),
), ),
+73 -59
View File
@@ -50,76 +50,90 @@ class _LoginMobilePageState extends State<LoginMobilePage> {
child: Center( child: Center(
child: SingleChildScrollView( child: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 24.0.w()), padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
child: Consumer<AuthViewModel>( child: Column(
builder: (context, viewModel, _) { mainAxisSize: MainAxisSize.min,
return Column( children: [
mainAxisSize: MainAxisSize.min, // LoginLogo(width: 190.0.w(), height: 88.0.h()),
children: [ Padding(
// LoginLogo(width: 190.0.w(), height: 88.0.h()), padding: EdgeInsets.symmetric(horizontal: 22.0.w()),
Padding( child: SvgPicture.asset(
padding: EdgeInsets.symmetric(horizontal: 22.0.w()), AssetsManager.logoBig,
child: SvgPicture.asset( width: double.infinity,
AssetsManager.logoBig, height: 50.0.h(),
width: double.infinity, ),
height: 50.0.h(), ),
), SizedBox(height: 32.0.h()),
), const LoginTitle(),
SizedBox(height: 32.0.h()), SizedBox(height: 32.0.h()),
const LoginTitle(),
SizedBox(height: 32.0.h()),
LoginTextField( LoginTextField(
controller: viewModel.usernameController, controller: viewModel.usernameController,
focusNode: viewModel.usernameFocus, focusNode: viewModel.usernameFocus,
label: LoginStrings.usernameLabel, label: LoginStrings.usernameLabel,
iconPath: AssetsManager.userIcon, iconPath: AssetsManager.userIcon,
), ),
SizedBox(height: 16.0.h()), SizedBox(height: 16.0.h()),
LoginTextField( Selector<AuthViewModel, bool>(
selector: (_, vm) => vm.obscurePassword,
builder: (_, obscurePassword, __) {
return LoginTextField(
controller: viewModel.passwordController, controller: viewModel.passwordController,
focusNode: viewModel.passwordFocus, focusNode: viewModel.passwordFocus,
label: LoginStrings.passwordLabel, label: LoginStrings.passwordLabel,
iconPath: AssetsManager.passwordIcon, iconPath: AssetsManager.passwordIcon,
isPassword: true, isPassword: true,
obscureText: viewModel.obscurePassword, obscureText: obscurePassword,
onToggleVisibility: viewModel.togglePasswordVisibility, onToggleVisibility: viewModel.togglePasswordVisibility,
), );
SizedBox(height: 32.0.h()), },
),
SizedBox(height: 32.0.h()),
if (viewModel.isLoading) /// ✅ Only this part rebuilds now
BaseButton( Selector<AuthViewModel, bool>(
isEnabled: false, selector: (_, vm) => vm.isLoading,
onPressed: null, builder: (_, isLoading, __) {
isLoading: true, return Selector<AuthViewModel, bool>(
textColor: AppColors.white, selector: (_, vm) => vm.isLoginEnabled,
) builder: (_, isEnabled, __) {
else if (isLoading) {
BaseButton( return BaseButton(
isEnabled: viewModel.isLoginEnabled, isEnabled: false,
onPressed: () async { onPressed: null,
if (viewModel.isLoginEnabled) { isLoading: true,
await viewModel.login(); textColor: AppColors.white,
} );
}, }
),
SizedBox(height: 32.0.h()), return BaseButton(
TextButton( isEnabled: isEnabled,
onPressed: () { onPressed:
const ForgotPasswordRouteData().push(context); isEnabled
? () async {
await viewModel.login();
}
: null,
);
}, },
child: Text( );
LoginStrings.forgotPassword, },
style: TextStyle( ),
fontSize: 14.0.sp(), SizedBox(height: 32.0.h()),
fontWeight: FontWeight.w500, TextButton(
color: AppColors.mainBlue, onPressed: () {
), const ForgotPasswordRouteData().push(context);
), },
child: Text(
LoginStrings.forgotPassword,
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.mainBlue,
), ),
], ),
); ),
}, ],
), ),
), ),
), ),
+76 -64
View File
@@ -52,78 +52,90 @@ class _LoginTabletPageState extends State<LoginTabletPage> {
padding: EdgeInsets.symmetric(horizontal: 24.0.w()), padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
child: SizedBox( child: SizedBox(
width: 364.0.w(), width: 364.0.w(),
child: Consumer<AuthViewModel>( child: Column(
builder: (context, viewModel, _) { mainAxisSize: MainAxisSize.min,
return Column( children: [
mainAxisSize: MainAxisSize.min, Padding(
children: [ padding: EdgeInsets.symmetric(horizontal: 22.0.w()),
Padding( child: SvgPicture.asset(
padding: EdgeInsets.symmetric(horizontal: 22.0.w()), AssetsManager.logoBig,
child: SvgPicture.asset( width: double.infinity,
AssetsManager.logoBig, height: 50.0.h(),
width: double.infinity, ),
height: 50.0.h(), ),
), SizedBox(height: 72.0.h()),
), const LoginTitle(),
SizedBox(height: 72.0.h()), SizedBox(height: 40.0.h()),
const LoginTitle(), LoginTextField(
SizedBox(height: 40.0.h()), controller: viewModel.usernameController,
LoginTextField( focusNode: viewModel.usernameFocus,
controller: viewModel.usernameController, label: LoginStrings.usernameLabel,
focusNode: viewModel.usernameFocus, iconPath: AssetsManager.userIcon,
label: LoginStrings.usernameLabel, fieldHeight: 60.0.h(),
iconPath: AssetsManager.userIcon, borderRedus: 12,
fieldHeight: 60.0.h(), prefixIconPadding: 4.0.w(),
borderRedus: 12, ),
prefixIconPadding: 4.0.w(), SizedBox(height: 24.0.h()),
), Selector<AuthViewModel, bool>(
SizedBox(height: 24.0.h()), selector: (_, vm) => vm.obscurePassword,
LoginTextField( builder: (_, obscurePassword, __) {
return LoginTextField(
controller: viewModel.passwordController, controller: viewModel.passwordController,
focusNode: viewModel.passwordFocus, focusNode: viewModel.passwordFocus,
label: LoginStrings.passwordLabel, label: LoginStrings.passwordLabel,
iconPath: AssetsManager.passwordIcon, iconPath: AssetsManager.passwordIcon,
prefixIconPadding: 4.0.w(),
isPassword: true, isPassword: true,
obscureText: viewModel.obscurePassword, obscureText: obscurePassword,
fieldHeight: 60.0.h(),
onToggleVisibility: viewModel.togglePasswordVisibility, onToggleVisibility: viewModel.togglePasswordVisibility,
borderRedus: 12, );
), },
SizedBox(height: 70.0.h()), ),
if (viewModel.isLoading) SizedBox(height: 70.0.h()),
const BaseButton(
isEnabled: false, /// ✅ Only this part rebuilds now
onPressed: null, Selector<AuthViewModel, bool>(
isLoading: true, selector: (_, vm) => vm.isLoading,
) builder: (_, isLoading, __) {
else return Selector<AuthViewModel, bool>(
BaseButton( selector: (_, vm) => vm.isLoginEnabled,
isEnabled: viewModel.isLoginEnabled, builder: (_, isEnabled, __) {
onPressed: if (isLoading) {
viewModel.isLoginEnabled return BaseButton(
? () async { isEnabled: false,
await viewModel.login(); onPressed: null,
} isLoading: true,
: null, textColor: AppColors.white,
), );
SizedBox(height: 30.0.h()), }
TextButton(
onPressed: () { return BaseButton(
const ForgotPasswordRouteData().push(context); isEnabled: isEnabled,
onPressed:
isEnabled
? () async {
await viewModel.login();
}
: null,
);
}, },
child: Text( );
LoginStrings.forgotPassword, },
style: TextStyle( ),
fontSize: 14.0.sp(), SizedBox(height: 30.0.h()),
fontWeight: FontWeight.w500, TextButton(
color: AppColors.mainBlue, onPressed: () {
), const ForgotPasswordRouteData().push(context);
), },
child: Text(
LoginStrings.forgotPassword,
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.mainBlue,
), ),
], ),
); ),
}, ],
), ),
), ),
), ),
+21 -21
View File
@@ -125,10 +125,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.4.1" version: "1.4.0"
checked_yaml: checked_yaml:
dependency: transitive dependency: transitive
description: description:
@@ -269,10 +269,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.3" version: "1.3.2"
ffi: ffi:
dependency: transitive dependency: transitive
description: description:
@@ -572,26 +572,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker name: leak_tracker
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "11.0.2" version: "10.0.8"
leak_tracker_flutter_testing: leak_tracker_flutter_testing:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker_flutter_testing name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.10" version: "3.0.9"
leak_tracker_testing: leak_tracker_testing:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker_testing name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.2" version: "3.0.1"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@@ -620,26 +620,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.18" version: "0.12.17"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.13.0" version: "0.11.1"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.17.0" version: "1.16.0"
mime: mime:
dependency: transitive dependency: transitive
description: description:
@@ -961,10 +961,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636" sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.9" version: "0.7.4"
time: time:
dependency: transitive dependency: transitive
description: description:
@@ -1041,10 +1041,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.2.0" version: "2.1.4"
vm_service: vm_service:
dependency: transitive dependency: transitive
description: description:
@@ -1118,5 +1118,5 @@ packages:
source: hosted source: hosted
version: "3.1.3" version: "3.1.3"
sdks: sdks:
dart: ">=3.9.0-0 <4.0.0" dart: ">=3.7.2 <4.0.0"
flutter: ">=3.29.0" flutter: ">=3.29.0"