developed
This commit is contained in:
parent
dcabe438ca
commit
bbfbbea52d
|
|
@ -31,6 +31,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
void _onSignIn(SignInUser event, Emitter<UserState> emit) async {
|
||||
try {
|
||||
emit(UserLoading());
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
final result = await _signInUseCase(event.params);
|
||||
result.fold(
|
||||
(failure) => emit(UserLoggedFail(failure)),
|
||||
|
|
@ -100,7 +101,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
FutureOr<void> _onGetUser(GetUser event, Emitter<UserState> emit) async {
|
||||
try {
|
||||
emit(UserLoading());
|
||||
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
final user = await _getUserFromCacheOrRemote();
|
||||
emit(UserFetched(user));
|
||||
} catch (failure) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'dart:ui' as ui;
|
||||
// import 'dart:ui' as ui;
|
||||
import 'ui.dart';
|
||||
|
||||
class AppDimensions {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ class MyApp extends StatelessWidget {
|
|||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
initialRoute: AppRouter.splash,
|
||||
theme: ThemeData(
|
||||
primarySwatch: CustomColors.primarySwatch,
|
||||
useMaterial3: false,
|
||||
primaryColor: AppColors.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,3 +9,35 @@ sealed class AppColors {
|
|||
static const Color darkGrey = Color(0xFF57575C);
|
||||
static const Color lightGrey = Color(0xFFE5E5E6);
|
||||
}
|
||||
|
||||
class CustomColors {
|
||||
static const Color primaryColor = Color(0xFF343FDE);
|
||||
|
||||
// Create a MaterialColor using the primary color
|
||||
static MaterialColor primarySwatch = MaterialColor(
|
||||
_primaryValue,
|
||||
<int, Color>{
|
||||
50: _createShade(0.1),
|
||||
100: _createShade(0.2),
|
||||
200: _createShade(0.3),
|
||||
300: _createShade(0.4),
|
||||
400: _createShade(0.5),
|
||||
500: primaryColor,
|
||||
600: _createShade(0.7),
|
||||
700: _createShade(0.8),
|
||||
800: _createShade(0.9),
|
||||
900: _createShade(1.0),
|
||||
},
|
||||
);
|
||||
|
||||
static const int _primaryValue = 0xFF343FDE;
|
||||
|
||||
// Create a shade of the primary color
|
||||
static Color _createShade(double strength) {
|
||||
final double t = strength;
|
||||
final int r = ((1 - t) * 255 + t * 52).toInt();
|
||||
final int g = ((1 - t) * 255 + t * 63).toInt();
|
||||
final int b = ((1 - t) * 255 + t * 222).toInt();
|
||||
return Color.fromARGB(255, r, g, b);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import 'dart:io';
|
||||
|
||||
class MyHttpOverrides extends HttpOverrides {
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext? context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export 'form_validator.dart';
|
||||
export 'keyboard.dart';
|
||||
export 'error_util.dart';
|
||||
export 'http_override.dart';
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ Future<void> main() async {
|
|||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await EasyLocalization.ensureInitialized();
|
||||
|
||||
// await GetStorage.init();
|
||||
|
||||
await di.init();
|
||||
|
||||
Bloc.observer = MyBlocObserver();
|
||||
|
|
@ -53,10 +51,3 @@ Future<void> main() async {
|
|||
// 5 create data source
|
||||
// 6 add di register
|
||||
|
||||
class MyHttpOverrides extends HttpOverrides {
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext? context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,13 +170,22 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||
_nextScreen();
|
||||
} else if (state is UserLoggedFail) {
|
||||
if (state.failure is CredentialFailure) {
|
||||
showCredentialErrorDialog(context);
|
||||
showErrorDialog(
|
||||
context: context,
|
||||
header: 'Invalid credentials',
|
||||
body: 'Username or Password Wrong!',
|
||||
);
|
||||
} else {
|
||||
showAuthErrorDialog(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is UserLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: AppButton(
|
||||
|
|
@ -184,6 +193,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||
btnColor: AppColors.primary,
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
Keyboard.hide(context);
|
||||
|
||||
/// sign in
|
||||
context.read<UserBloc>().add(
|
||||
SignInUser(
|
||||
SignInParams(
|
||||
|
|
@ -198,7 +210,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ class ProfileScreen extends StatefulWidget {
|
|||
class _ProfileScreenState extends State<ProfileScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
context.read<UserBloc>().add(GetUser());
|
||||
super.initState();
|
||||
context.read<UserBloc>().add(GetUser());
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -27,7 +27,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||
App.init(context);
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
body: BlocBuilder<UserBloc, UserState>(
|
||||
body: BlocConsumer<UserBloc, UserState>(
|
||||
listener: (context, state) {
|
||||
if (state is UserLoggedOut || state is UserLoggedFail) {
|
||||
_navigateToLoginScreen(context);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is UserLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
|
@ -80,7 +85,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||
RowWidget(
|
||||
text: user.fullName,
|
||||
leadingIcon: Icons.person_2_outlined,
|
||||
// trailingIcon: Icons.mode_edit_outlined,
|
||||
),
|
||||
|
||||
/// gap
|
||||
|
|
@ -90,7 +94,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||
RowWidget(
|
||||
text: user.phone,
|
||||
leadingIcon: Icons.phone_android_outlined,
|
||||
// trailingIcon: Icons.mode_edit_outlined,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
@ -168,7 +171,9 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
context.read<UserBloc>().add(SignOutUser());
|
||||
},
|
||||
child: Text(
|
||||
'Şahsy otagdan çykmak',
|
||||
style: AppText.b1!.copyWith(
|
||||
|
|
@ -185,6 +190,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _navigateToLoginScreen(BuildContext context) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
AppRouter.login,
|
||||
(route) => false,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class RowWidget extends StatelessWidget {
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../configs/configs.dart';
|
||||
import '../../core/core.dart';
|
||||
|
||||
Future<void> showCredentialErrorDialog(BuildContext context) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
height: AppDimensions.normalize(60),
|
||||
padding: Space.all(1, .5),
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Username/Password Wrong!',
|
||||
style: AppText.b1b,
|
||||
),
|
||||
Space.yf(.5),
|
||||
Text(
|
||||
'Try Again!',
|
||||
style: AppText.b1,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(
|
||||
'Dismiss',
|
||||
style: AppText.h3b?.copyWith(
|
||||
color: AppColors.primary,
|
||||
),
|
||||
))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../configs/configs.dart';
|
||||
import '../../core/core.dart';
|
||||
|
||||
Future<void> showErrorDialog({
|
||||
required BuildContext context,
|
||||
required String header,
|
||||
required String body,
|
||||
String dismissButtonText = 'Dismiss',
|
||||
VoidCallback? onDismiss,
|
||||
}) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
child: Container(
|
||||
padding: Space.all(1, .5),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
header,
|
||||
style: AppText.h3b?.copyWith(color: Colors.white),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
body,
|
||||
style: AppText.b1,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
if (onDismiss != null) {
|
||||
onDismiss();
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
dismissButtonText,
|
||||
style: AppText.h3b?.copyWith(
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
export 'auth_error_dialog.dart';
|
||||
export 'bottom_navbar.dart';
|
||||
export 'button.dart';
|
||||
export 'credential_failure_dialog.dart';
|
||||
export 'error_dialog.dart';
|
||||
export 'info_card.dart';
|
||||
export 'location_card.dart';
|
||||
export 'order_card.dart';
|
||||
|
|
|
|||
Loading…
Reference in New Issue