Skip to content

Commit

Permalink
locked vertical view only
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbadone committed Dec 5, 2023
1 parent f935e44 commit e1e12b1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_amazon_clone_bloc/src/config/router/router.dart';
import 'package:flutter_amazon_clone_bloc/src/config/themes/app_theme.dart';
import 'package:flutter_amazon_clone_bloc/src/data/repositories/account_repository.dart';
Expand Down Expand Up @@ -46,6 +47,9 @@ import 'package:path_provider/path_provider.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getApplicationDocumentsDirectory());
await dotenv.load(fileName: "config.env");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/data/datasources/api/auth_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AuthAPI {
Future<http.Response> isTokenValid({required var token}) async {
try {
http.Response res =
await http.post(Uri.parse(isTokenValidUri), headers: <String, String>{
await http.get(Uri.parse(isTokenValidUri), headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'x-auth-token': token,
});
Expand Down
2 changes: 2 additions & 0 deletions lib/src/data/repositories/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AuthRepository {
try {
http.Response res = await AuthAPI().isTokenValid(token: token);

print(jsonDecode(res.body));

if (res.statusCode == 200) {
bool isTokenValid = jsonDecode(res.body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AdminFourImageOfferCubit extends Cubit<AdminFourImageOfferState> {
}
}

Future<void> adminGetFourImagesOffer() async {
Future<void> adminGetFourImagesOffer({required bool isUser}) async {
try {
emit(AdminFourImageOfferLoadingS());

Expand All @@ -43,7 +43,12 @@ class AdminFourImageOfferCubit extends Cubit<AdminFourImageOfferState> {

tempFourImagesOfferList = await adminRepository.adminGetFourImagesOffer();

fourImagesOfferList = tempFourImagesOfferList.reversed.toList();
if (isUser) {
tempFourImagesOfferList.shuffle();
fourImagesOfferList = tempFourImagesOfferList;
} else {
fourImagesOfferList = tempFourImagesOfferList.reversed.toList();
}

emit(AdminGetFourImageOfferSuccessS(
fourImagesOfferList: fourImagesOfferList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ class PageRedirectionCubit extends Cubit<PageRedirectionState> {
prefs.setString('x-auth-token', '');
token = '';
}
print('about to run token');
isValid = await authRepository.isTokenValid(token: token);

if (isValid == true) {
User user = await userRepository.getUserDataInitial(token);
userType = user.type;
print(userType);
emit(PageRedirectionSuccess(isValid: isValid, userType: userType));
} else {
emit(PageRedirectionInvalid(isValid: isValid, userType: 'invalid'));
}
} catch (e) {
print(e);
throw Exception(e.toString());
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/presentation/views/admin/admin_offers_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class AdminOffersScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
context.read<AdminFourImageOfferCubit>().adminGetFourImagesOffer();
context
.read<AdminFourImageOfferCubit>()
.adminGetFourImagesOffer(isUser: false);
return Scaffold(
floatingActionButton: CustomFloatingActionButton(
onPressed: () =>
Expand Down Expand Up @@ -62,7 +64,7 @@ class AdminOffersScreen extends StatelessWidget {
} else {
context
.read<AdminFourImageOfferCubit>()
.adminGetFourImagesOffer();
.adminGetFourImagesOffer(isUser: false);
return SizedBox(
height: MediaQuery.sizeOf(context).height / 1.2,
child: const Center(
Expand Down
43 changes: 25 additions & 18 deletions lib/src/presentation/views/cart/cart_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,36 +360,43 @@ class CartScreen extends StatelessWidget {
BlocBuilder<CartOffersCubit1, CartOffersState1>(
builder: (context, state) {
if (state is CartOffersSuccessS1) {
return AddToCartWidget(
title: 'Top picks for you',
isTitleLong: false,
productList: state.productList,
averageRating: state.averageRatingList,
);
return state.productList.isEmpty
? const SizedBox()
: AddToCartWidget(
title: 'Top picks for you',
isTitleLong: false,
productList: state.productList,
averageRating: state.averageRatingList,
);
}
return const SizedBox();
}),
BlocBuilder<CartOffersCubit2, CartOffersState2>(
builder: (context, state) {
if (state is CartOffersSuccessS2) {
return AddToCartWidget(
title: 'Frequently viewed with items in your cart',
isTitleLong: true,
productList: state.productList,
averageRating: state.averageRatingList,
);
return state.productList.isEmpty
? const SizedBox()
: AddToCartWidget(
title:
'Frequently viewed with items in your cart',
isTitleLong: true,
productList: state.productList,
averageRating: state.averageRatingList,
);
}
return const SizedBox();
}),
BlocBuilder<CartOffersCubit3, CartOffersState3>(
builder: (context, state) {
if (state is CartOffersSuccessS3) {
return AddToCartWidget(
title: 'Recommendations for you',
isTitleLong: false,
productList: state.productList,
averageRating: state.averageRatingList,
);
return state.productList.isEmpty
? const SizedBox()
: AddToCartWidget(
title: 'Recommendations for you',
isTitleLong: false,
productList: state.productList,
averageRating: state.averageRatingList,
);
}
return const SizedBox();
}),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/presentation/views/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
BlocProvider.of<CarouselImageBloc>(context).add(ResetCarouselEvent());
context.read<AdminFourImageOfferCubit>().adminGetFourImagesOffer();
context
.read<AdminFourImageOfferCubit>()
.adminGetFourImagesOffer(isUser: true);

return Scaffold(
appBar: const PreferredSize(
Expand Down Expand Up @@ -83,7 +85,7 @@ class _HomeScreenState extends State<HomeScreen> {
} else {
context
.read<AdminFourImageOfferCubit>()
.adminGetFourImagesOffer();
.adminGetFourImagesOffer(isUser: true);
return SizedBox(
height: MediaQuery.sizeOf(context).height / 1.2,
child: const Center(
Expand Down
4 changes: 3 additions & 1 deletion server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ authRouter.post('/api/signin', async (req, res ) => {
}
})

authRouter.post('/IsTokenValid', async (req, res) => {
authRouter.get('/IsTokenValid', async (req, res) => {
try {
console.log('inside istokenValid');
const token = req.header('x-auth-token');


if(token == '') return res.json(false);
if(!token) return res.json(false);
const isVerified = jwt.verify(token, 'passwordKey');
Expand Down

0 comments on commit e1e12b1

Please sign in to comment.