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 {
|
void _onSignIn(SignInUser event, Emitter<UserState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(UserLoading());
|
emit(UserLoading());
|
||||||
|
// await Future.delayed(const Duration(seconds: 3));
|
||||||
final result = await _signInUseCase(event.params);
|
final result = await _signInUseCase(event.params);
|
||||||
result.fold(
|
result.fold(
|
||||||
(failure) => emit(UserLoggedFail(failure)),
|
(failure) => emit(UserLoggedFail(failure)),
|
||||||
|
|
@ -100,7 +101,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
||||||
FutureOr<void> _onGetUser(GetUser event, Emitter<UserState> emit) async {
|
FutureOr<void> _onGetUser(GetUser event, Emitter<UserState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(UserLoading());
|
emit(UserLoading());
|
||||||
|
// await Future.delayed(const Duration(seconds: 3));
|
||||||
final user = await _getUserFromCacheOrRemote();
|
final user = await _getUserFromCacheOrRemote();
|
||||||
emit(UserFetched(user));
|
emit(UserFetched(user));
|
||||||
} catch (failure) {
|
} catch (failure) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:ui' as ui;
|
// import 'dart:ui' as ui;
|
||||||
import 'ui.dart';
|
import 'ui.dart';
|
||||||
|
|
||||||
class AppDimensions {
|
class AppDimensions {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ class MyApp extends StatelessWidget {
|
||||||
supportedLocales: context.supportedLocales,
|
supportedLocales: context.supportedLocales,
|
||||||
locale: context.locale,
|
locale: context.locale,
|
||||||
initialRoute: AppRouter.splash,
|
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 darkGrey = Color(0xFF57575C);
|
||||||
static const Color lightGrey = Color(0xFFE5E5E6);
|
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 'form_validator.dart';
|
||||||
export 'keyboard.dart';
|
export 'keyboard.dart';
|
||||||
export 'error_util.dart';
|
export 'error_util.dart';
|
||||||
|
export 'http_override.dart';
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await EasyLocalization.ensureInitialized();
|
await EasyLocalization.ensureInitialized();
|
||||||
|
|
||||||
// await GetStorage.init();
|
|
||||||
|
|
||||||
await di.init();
|
await di.init();
|
||||||
|
|
||||||
Bloc.observer = MyBlocObserver();
|
Bloc.observer = MyBlocObserver();
|
||||||
|
|
@ -53,10 +51,3 @@ Future<void> main() async {
|
||||||
// 5 create data source
|
// 5 create data source
|
||||||
// 6 add di register
|
// 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();
|
_nextScreen();
|
||||||
} else if (state is UserLoggedFail) {
|
} else if (state is UserLoggedFail) {
|
||||||
if (state.failure is CredentialFailure) {
|
if (state.failure is CredentialFailure) {
|
||||||
showCredentialErrorDialog(context);
|
showErrorDialog(
|
||||||
|
context: context,
|
||||||
|
header: 'Invalid credentials',
|
||||||
|
body: 'Username or Password Wrong!',
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
showAuthErrorDialog(context);
|
showAuthErrorDialog(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
if (state is UserLoading) {
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: AppButton(
|
child: AppButton(
|
||||||
|
|
@ -184,6 +193,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||||
btnColor: AppColors.primary,
|
btnColor: AppColors.primary,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
|
Keyboard.hide(context);
|
||||||
|
|
||||||
|
/// sign in
|
||||||
context.read<UserBloc>().add(
|
context.read<UserBloc>().add(
|
||||||
SignInUser(
|
SignInUser(
|
||||||
SignInParams(
|
SignInParams(
|
||||||
|
|
@ -198,7 +210,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ class ProfileScreen extends StatefulWidget {
|
||||||
class _ProfileScreenState extends State<ProfileScreen> {
|
class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
context.read<UserBloc>().add(GetUser());
|
|
||||||
super.initState();
|
super.initState();
|
||||||
|
context.read<UserBloc>().add(GetUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -27,7 +27,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
App.init(context);
|
App.init(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.surface,
|
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) {
|
builder: (context, state) {
|
||||||
if (state is UserLoading) {
|
if (state is UserLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
|
@ -80,7 +85,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
RowWidget(
|
RowWidget(
|
||||||
text: user.fullName,
|
text: user.fullName,
|
||||||
leadingIcon: Icons.person_2_outlined,
|
leadingIcon: Icons.person_2_outlined,
|
||||||
// trailingIcon: Icons.mode_edit_outlined,
|
|
||||||
),
|
),
|
||||||
|
|
||||||
/// gap
|
/// gap
|
||||||
|
|
@ -90,7 +94,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
RowWidget(
|
RowWidget(
|
||||||
text: user.phone,
|
text: user.phone,
|
||||||
leadingIcon: Icons.phone_android_outlined,
|
leadingIcon: Icons.phone_android_outlined,
|
||||||
// trailingIcon: Icons.mode_edit_outlined,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -168,7 +171,9 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
context.read<UserBloc>().add(SignOutUser());
|
||||||
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Şahsy otagdan çykmak',
|
'Şahsy otagdan çykmak',
|
||||||
style: AppText.b1!.copyWith(
|
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 {
|
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 'auth_error_dialog.dart';
|
||||||
export 'bottom_navbar.dart';
|
export 'bottom_navbar.dart';
|
||||||
export 'button.dart';
|
export 'button.dart';
|
||||||
export 'credential_failure_dialog.dart';
|
export 'error_dialog.dart';
|
||||||
export 'info_card.dart';
|
export 'info_card.dart';
|
||||||
export 'location_card.dart';
|
export 'location_card.dart';
|
||||||
export 'order_card.dart';
|
export 'order_card.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue