Skip to content

Commit

Permalink
V2/features/registered events and orders (#47)
Browse files Browse the repository at this point in the history
* Registered events and orders page UI created and integrated with data fetching and state management.

* Developers page UI changes

* Event description share button added.

---------

Co-authored-by: PeeyushKulgude <peeyush.kulgude777@gmail.com>
  • Loading branch information
RohanDoshi21 and PeeyushKulgude committed Apr 14, 2023
1 parent 3cc3d30 commit e50235d
Show file tree
Hide file tree
Showing 20 changed files with 709 additions and 94 deletions.
39 changes: 39 additions & 0 deletions lib/constants/models/registered_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class RegisteredEvent {
int? id;
String? transactionId;
int? amount;
DateTime? createdAt;
List<dynamic>? events;
String? status;

RegisteredEvent({
this.id,
this.transactionId,
this.amount,
this.createdAt,
this.events,
this.status,

});

RegisteredEvent.fromJson(Map<String, dynamic> json) {
id = json["id"];
transactionId = json["transaction_id"];
amount = json["amount"];
createdAt = DateTime.parse(json["created_at"]);
events = json["events"];
status = json["status"];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["id"] = id;
data["transaction_id"] = transactionId;
data["amount"] = amount;
data["created_at"] = createdAt!.toIso8601String();
data["events"] = events;
data["status"] = status;

return data;
}
}
1 change: 1 addition & 0 deletions lib/constants/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class EndPoints {
static String signup = '${baseUrl!}/user/signup';
static String addFCMToken = '${baseUrl!}/fcm_token/';
static String cart = '${baseUrl!}/cart/';
static String transaction = '${baseUrl!}/transaction';
}
48 changes: 32 additions & 16 deletions lib/features/event_description/ui/event_description.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import "package:share_plus/share_plus.dart";
import '../../../constants/urls.dart';
import 'package:pulzion23/features/cart_page/cubit/cart_page_cubit.dart';
import 'package:pulzion23/features/event_description/ui/widgets/button.dart';
import '../../../config/size_config.dart';
Expand All @@ -20,10 +22,8 @@ class EventDescription extends StatefulWidget {
State<EventDescription> createState() => _EventDescriptionState();
}

class _EventDescriptionState extends State<EventDescription>
with TickerProviderStateMixin {
late final TabController tabBarController =
TabController(length: 3, vsync: this);
class _EventDescriptionState extends State<EventDescription> with TickerProviderStateMixin {
late final TabController tabBarController = TabController(length: 3, vsync: this);

@override
void dispose() {
Expand Down Expand Up @@ -88,8 +88,7 @@ class _EventDescriptionState extends State<EventDescription>
Expanded(
child: BlocBuilder<CheckLoginCubit, CheckLoginState>(
builder: (context, state) {
if (state is CheckLoginFailure ||
state is CheckLoginLoading) {
if (state is CheckLoginFailure || state is CheckLoginLoading) {
return event.price == 0
? EventDescriptionPageButton(
'Register Now',
Expand All @@ -99,8 +98,7 @@ class _EventDescriptionState extends State<EventDescription>
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const LoginSignUpIntro(),
builder: (context) => const LoginSignUpIntro(),
),
);
},
Expand All @@ -112,8 +110,7 @@ class _EventDescriptionState extends State<EventDescription>
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const LoginSignUpIntro(),
builder: (context) => const LoginSignUpIntro(),
),
);
},
Expand All @@ -138,8 +135,7 @@ class _EventDescriptionState extends State<EventDescription>
'Add to Cart',
Icons.shopping_cart,
() {
BlocProvider.of<CartPageCubit>(context)
.addCartItem(event.id!);
BlocProvider.of<CartPageCubit>(context).addCartItem(event.id!);
},
),
);
Expand Down Expand Up @@ -237,6 +233,28 @@ class _EventDescriptionState extends State<EventDescription>
),
),
),
Align(
alignment: Alignment.topRight,
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top * 1.5,
right: MediaQuery.of(context).size.width / 20,
),
child: InkWell(
onTap: (() {
Share.share(
'${event.description}\n\nPulzion 23 App: ${EndPoints.playStoreURL}',
subject: 'Pulzion 2023',
sharePositionOrigin: Rect.fromLTWH(0, 0, 10, 10),
);
}),
child: const Icon(
Icons.share,
color: Colors.white,
),
),
),
),
],
),
Padding(
Expand All @@ -256,8 +274,7 @@ class _EventDescriptionState extends State<EventDescription>
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: AppColors.eventCardGradientList.elementAt(
event.id! %
AppColors.eventCardGradientList.length,
event.id! % AppColors.eventCardGradientList.length,
),
),
),
Expand Down Expand Up @@ -305,8 +322,7 @@ class _EventDescriptionState extends State<EventDescription>
),
),
),
unselectedLabelColor:
AppColors.cardSubtitleTextColor,
unselectedLabelColor: AppColors.cardSubtitleTextColor,
labelColor: AppColors.loginPageAccent,
tabs: const [
Text(
Expand Down
2 changes: 1 addition & 1 deletion lib/features/event_description/ui/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EventDescriptionPageButton extends StatelessWidget {
final Function onPressed;
const EventDescriptionPageButton(
this.buttonText, this.buttonIcon, this.onPressed,
{super.key});
{super.key,});

@override
Widget build(BuildContext context) {
Expand Down
5 changes: 1 addition & 4 deletions lib/features/event_slots/logic/booked_slot_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:convert';
import 'dart:developer';
import 'package:bloc/bloc.dart';
// ignore: depend_on_referenced_packages
import 'package:meta/meta.dart';
import 'package:http/http.dart' as http;
import 'package:pulzion23/features/home_page/logic/event_details_cubit_cubit.dart';

part 'booked_slot_state.dart';

Expand Down
6 changes: 3 additions & 3 deletions lib/features/event_slots/ui/booked_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class EventBookingPage extends StatelessWidget {
return BlocBuilder<EventSlotsCubit, EventSlotStateCubit>(
bloc: EventSlotsCubit()..getBookingDetails(),
builder: (context, state) {
print(state.toString());
if (state is BookedSlotState) {
return BookedWindow();
return const BookedWindow();
} else if (state is NotBookedSlotState) {
return NotBookedWindow();
return const NotBookedWindow();
}

return const Center(
child: CircularProgressIndicator(),
);
Expand Down
11 changes: 7 additions & 4 deletions lib/features/event_slots/ui/booked_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import '../../../constants/images.dart';


class BookedWindow extends StatefulWidget {
const BookedWindow({super.key});

@override
State<BookedWindow> createState() => _BookedWindowState();
}
Expand All @@ -24,6 +26,7 @@ class _BookedWindowState extends State<BookedWindow>
];
List<bool> c = [false, false, false, false];

@override
void initState() {
_controller = AnimationController(
vsync: this,
Expand All @@ -32,8 +35,8 @@ class _BookedWindowState extends State<BookedWindow>
super.initState();
}

@override
void dispose() {
// TODO: implement dispose
_controller.dispose();
super.dispose();
}
Expand Down Expand Up @@ -86,7 +89,7 @@ class _BookedWindowState extends State<BookedWindow>
}


Widget EventDate(double h, double w, String event_date, String event_day) {
Widget EventDate(double h, double w, String eventDate, String eventDay) {

return Padding(
padding: const EdgeInsets.all(8.0),
Expand All @@ -100,7 +103,7 @@ class _BookedWindowState extends State<BookedWindow>
Padding(
padding: EdgeInsets.all(h * 0.005),
child: Text(
event_day,
eventDay,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
Expand All @@ -111,7 +114,7 @@ class _BookedWindowState extends State<BookedWindow>
Padding(
padding: EdgeInsets.all(h * 0.002),
child: Text(
event_date,
eventDate,
style: TextStyle(fontSize: h * 0.025),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:convert';
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;

import '../../../constants/models/registered_event.dart';
import '../../../constants/urls.dart';

part 'registered_events_and_orders_state.dart';

class RegisteredEventsAndOrdersCubit extends Cubit<RegisteredEventsAndOrdersState> {
RegisteredEventsAndOrdersCubit() : super(RegisteredEventsAndOrdersLoading());

Future<void> getRegisteredEventsAndOrders() async {
emit(RegisteredEventsAndOrdersLoading());

const storage = FlutterSecureStorage();
var token = await storage.read(key: 'token');
if (token != null) {
http.Response? response;
try {
response = await http.get(
Uri.parse(EndPoints.transaction),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
var data = jsonDecode(response.body);
List<RegisteredEvent> registeredEvents =
data['transactions'].map<RegisteredEvent>((e) => RegisteredEvent.fromJson(e)).toList();
log(response.body);
emit(RegisteredEventsAndOrdersLoaded(registeredEvents));
} catch (e) {
if (response == null) {
log('Registered Events Page Exception: $e');
emit(RegisteredEventsAndOrdersError('Failed host lookup.'));
} else {
log('Registered Events Page Exception: $e');
emit(RegisteredEventsAndOrdersError(e.toString()));
}
}
} else {
emit(RegisteredEventsAndOrdersError('Logout and login again.'));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
part of 'registered_events_and_orders_cubit.dart';

abstract class RegisteredEventsAndOrdersState {}

class RegisteredEventsAndOrdersLoaded extends RegisteredEventsAndOrdersState {
List<RegisteredEvent> registeredEvents;
RegisteredEventsAndOrdersLoaded(this.registeredEvents);
}

class RegisteredEventsAndOrdersError extends RegisteredEventsAndOrdersState {
final String errorMessage;

RegisteredEventsAndOrdersError(this.errorMessage);
}

class RegisteredEventsAndOrdersLoading extends RegisteredEventsAndOrdersState {}

0 comments on commit e50235d

Please sign in to comment.