Skip to content

Commit

Permalink
Coupon System Added ,
Browse files Browse the repository at this point in the history
Booking Screen Is Now Completed
  • Loading branch information
Dev-Adnani committed Aug 19, 2022
1 parent d711cc3 commit 4845784
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 11 deletions.
18 changes: 18 additions & 0 deletions lib/app/constants/app.coupons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Currently I Have Implemented Temp Coupons You Can Get Coupons From Supabase And Use If You Want

class AppDiscount {
static List<String> couponCode = [
'Flat10',
'Flat5',
'KingZ48',
];

static List<String> couponListDisplay = [
'No Coupon For You',
'Flat10',
'Flat5',
'No Coupon For You',
'KingZ48',
'No Coupon For You'
];
}
124 changes: 116 additions & 8 deletions lib/presentation/screens/bookingScreen/booking.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:metroom/app/constants/app.colors.dart';
import 'package:metroom/app/constants/app.coupons.dart';
import 'package:metroom/core/models/booking.model.dart';
import 'package:metroom/core/models/room.model.dart';
import 'package:metroom/core/notifiers/authentication.notifier.dart';
Expand All @@ -12,19 +13,33 @@ import 'package:metroom/presentation/widgets/custom.button.dart';
import 'package:metroom/presentation/widgets/custom.snackbar.dart';
import 'package:provider/provider.dart';

class BookingScreen extends StatelessWidget {
class BookingScreen extends StatefulWidget {
final BookingScreenArgs bookingScreenArgs;

const BookingScreen({Key? key, required this.bookingScreenArgs})
: super(key: key);

@override
State<BookingScreen> createState() => _BookingScreenState();
}

class _BookingScreenState extends State<BookingScreen> {
bool check = false;

@override
void initState() {
check = false;
super.initState();
}

@override
Widget build(BuildContext context) {
ThemeNotifier _themeNotifier =
Provider.of<ThemeNotifier>(context, listen: true);
var themeFlag = _themeNotifier.darkTheme;
var userData = Provider.of<AuthenticationNotifer>(context, listen: true);
var bookNotifier = Provider.of<BookingNotifier>(context, listen: true);
TextEditingController couponText = TextEditingController();

return Scaffold(
backgroundColor: themeFlag ? AppColors.mirage : AppColors.creamColor,
Expand All @@ -42,6 +57,7 @@ class BookingScreen extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 30,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -97,15 +113,15 @@ class BookingScreen extends StatelessWidget {
Divider(
color: themeFlag ? AppColors.creamColor : AppColors.mirage),
Text(
'Room Name : ${bookingScreenArgs.roomData.roomName}',
'Room Name : ${widget.bookingScreenArgs.roomData.roomName}',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
fontSize: 16,
),
textAlign: TextAlign.left,
),
Text(
'Room Address : ${bookingScreenArgs.roomData.roomAddress}',
'Room Address : ${widget.bookingScreenArgs.roomData.roomAddress}',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
fontSize: 16,
Expand All @@ -115,21 +131,31 @@ class BookingScreen extends StatelessWidget {
overflow: TextOverflow.ellipsis,
),
Text(
'Room Type : ${bookingScreenArgs.roomData.roomType}',
'Room Type : ${widget.bookingScreenArgs.roomData.roomType}',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
fontSize: 16,
),
textAlign: TextAlign.left,
),
Text(
'Room Price : ${bookingScreenArgs.roomData.roomPrice}',
'Room Price : ${widget.bookingScreenArgs.roomData.roomPrice}',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
fontSize: 16,
),
textAlign: TextAlign.left,
),
Text(
'Discount Amount : ${check ? (widget.bookingScreenArgs.roomData.roomPrice * 5 ~/ 100) : 0}',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
fontSize: 16,
),
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Divider(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
),
Expand Down Expand Up @@ -206,6 +232,82 @@ class BookingScreen extends StatelessWidget {
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(Icons.card_giftcard),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
constraints: const BoxConstraints(maxWidth: 210),
child: TextFormField(
controller: couponText,
style: TextStyle(
color: themeFlag
? AppColors.creamColor
: AppColors.mirage,
fontSize: 16.0,
),
decoration: InputDecoration(
hintText: 'Enter Coupon Code',
hintStyle: TextStyle(
color: themeFlag
? AppColors.creamColor
: AppColors.mirage,
fontSize: 16.0,
),
),
),
),
),
],
),
TextButton(
child: const Text('Apply'),
onPressed: () {
if (couponText.text.isNotEmpty) {
if (AppDiscount.couponCode.contains(couponText.text)) {
if (check == false) {
SnackUtil.showSnackBar(
context: context,
text: 'Ohh Yeah Coupon Applied',
textColor: AppColors.creamColor,
backgroundColor: Colors.red.shade200,
);
setState(() {
check = true;
});
} else if (check == true) {
SnackUtil.showSnackBar(
context: context,
text: 'Coupon Already Applied',
textColor: AppColors.creamColor,
backgroundColor: Colors.red.shade200,
);
}
} else {
SnackUtil.showSnackBar(
context: context,
text: 'Oops Wrong Coupon Code',
textColor: AppColors.creamColor,
backgroundColor: Colors.red.shade200,
);
}
} else {
SnackUtil.showSnackBar(
context: context,
text: "Ehh Atleast Enter A Coupon!",
textColor: AppColors.creamColor,
backgroundColor: Colors.red.shade200,
);
}
},
)
],
),
SizedBox(
height: 40,
),
Expand All @@ -220,13 +322,19 @@ class BookingScreen extends StatelessWidget {
);
await PayStatus.checkMeOut(
context: context,
amt: bookingScreenArgs.roomData.roomPrice.toInt(),
amt: widget.bookingScreenArgs.roomData.roomPrice.toInt(),
).whenComplete(
() async {
if (PayStatus.paymentStatus!) {
BookingModel bookingModel = BookingModel(
bookingRazorid: 'PayStatus.payResponse!',
bookingPrice: bookingScreenArgs.roomData.roomPrice,
bookingPrice: check
? widget.bookingScreenArgs.roomData.roomPrice -
(widget.bookingScreenArgs.roomData
.roomPrice *
5 ~/
100)
: widget.bookingScreenArgs.roomData.roomPrice,
bookingStartDate: bookNotifier.startDate!,
bookingEndDate: bookNotifier.endDate!,
);
Expand All @@ -237,7 +345,7 @@ class BookingScreen extends StatelessWidget {
.confirmBooking(
bookingModel: bookingModel,
userId: userData.userId!,
roomId: bookingScreenArgs.roomData.roomId,
roomId: widget.bookingScreenArgs.roomData.roomId,
);

if (isSuccessFul) {
Expand Down
77 changes: 74 additions & 3 deletions lib/presentation/screens/feedbackScreen/feedback.screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:intl/intl.dart';
import 'package:metroom/app/constants/app.colors.dart';
import 'package:metroom/app/constants/app.coupons.dart';
import 'package:metroom/core/models/feedback.model.dart';
import 'package:metroom/core/notifiers/authentication.notifier.dart';
import 'package:metroom/core/notifiers/feedback.notifier.dart';
Expand All @@ -11,6 +14,7 @@ import 'package:metroom/presentation/widgets/custom.snackbar.dart';
import 'package:metroom/presentation/widgets/custom.text.field.dart';
import 'package:metroom/core/notifiers/theme.notifier.dart';
import 'package:provider/provider.dart';
import 'package:scratcher/scratcher.dart';

// ignore: must_be_immutable
class FeedbackScreen extends StatelessWidget {
Expand Down Expand Up @@ -121,8 +125,11 @@ class FeedbackScreen extends StatelessWidget {
),
CustomButton.customBtnLogin(
buttonName: 'Send Feedback',
onTap: () async {
_submitFeedback(context: context);
onTap: () {
if (_formKey.currentState!.validate()) {
_submitFeedback(context: context);
couponCode(context: context, themeFlag: themeFlag);
}
},
bgColor: themeFlag ? AppColors.creamColor : AppColors.mirage,
textColor:
Expand Down Expand Up @@ -157,7 +164,7 @@ class FeedbackScreen extends StatelessWidget {
if (valid) {
SnackUtil.showSnackBar(
context: context,
text: "Submitted Successfully",
text: "Thanks For Submitting Feedback,We Have A Gift For You ",
textColor: AppColors.creamColor,
backgroundColor: Colors.green,
);
Expand All @@ -172,3 +179,67 @@ class FeedbackScreen extends StatelessWidget {
}
}
}

Future couponCode(
{required BuildContext context, required bool themeFlag}) async {
return showDialog(
context: context,
builder: (BuildContext context) {
final _random = Random();
double opacity = 0.0;
return Theme(
data: Theme.of(context).copyWith(
dialogBackgroundColor:
themeFlag ? AppColors.mirage : AppColors.creamColor,
),
child: AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
title: Align(
alignment: Alignment.center,
child: Text(
'You\'ve won a Coupon Code',
style: TextStyle(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
),
),
),
content: StatefulBuilder(
builder: (context, StateSetter setState) {
return Scratcher(
color: themeFlag ? AppColors.creamColor : AppColors.mirage,
accuracy: ScratchAccuracy.low,
brushSize: 50,
threshold: 25,
onThreshold: () {
setState(() {
opacity = 1;
});
},
child: AnimatedOpacity(
opacity: opacity,
duration: const Duration(milliseconds: 300),
child: Container(
height: 300,
width: 300,
alignment: Alignment.center,
child: Text(
AppDiscount.couponListDisplay[_random.nextInt(
AppDiscount.couponListDisplay.length,
)],
style: TextStyle(
color:
themeFlag ? AppColors.creamColor : AppColors.mirage,
),
),
),
),
);
},
),
),
);
},
);
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.1"
scratcher:
dependency: "direct main"
description:
name: scratcher
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
shared_preferences:
dependency: "direct main"
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
provider: ^6.0.3
razorpay_flutter: ^1.3.0
salomon_bottom_bar: ^3.3.1
scratcher: ^2.2.1
shared_preferences: ^2.0.15
shimmer: ^2.0.0
supabase: ^0.3.4+1
Expand All @@ -51,6 +52,7 @@ flutter:
- assets/svg/
- assets/logo/
- assets/images/

# fonts:
# - family: UniNeue
# fonts:
Expand Down

0 comments on commit 4845784

Please sign in to comment.