Skip to content

Commit

Permalink
upcoming bookings page done
Browse files Browse the repository at this point in the history
  • Loading branch information
Hareesh-Nandigrama committed Jul 18, 2023
1 parent 7379954 commit c06982d
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 55 deletions.
105 changes: 51 additions & 54 deletions packages/irbs/lib/src/screens/booking_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BookingHistory extends StatefulWidget {
}

class _BookingHistoryState extends State<BookingHistory> {

@override
Widget build(BuildContext context) {
var store = context.read<CommonStore>();
Expand All @@ -33,64 +32,62 @@ class _BookingHistoryState extends State<BookingHistory> {
),
backgroundColor: Themes.tileColor,
),
body: Observer(
builder: (context) {
return Padding(
padding: const EdgeInsets.only(top: 16),
child: SingleChildScrollView(
child: Column(
children: [
//Add dropdown here
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
body: Padding(
padding: const EdgeInsets.only(top: 16),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(width: 130,child: CustomDropDown( hintText: 'Month')),
SizedBox(width: 130,child: CustomDropDown(hintText: 'Year')),
//Add dropdown here
const Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: 130, child: CustomDropDown(hintText: 'Month')),
SizedBox(
width: 130, child: CustomDropDown(hintText: 'Year')),
],
),
),

Observer(builder: (context) {
return FutureBuilder(
future: APIService()
.getBookingHistory(month: store.month, year: store.year),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const UpcomingBookingShimmer(number: 8);
} else if (snapshot.hasError) {
return const Text('Error');
} else {
List<BookingModel> currentBooking = snapshot.data!;
if (currentBooking.isEmpty) {
return const EmptyState(text: 'No bookings');
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListView.builder(
shrinkWrap: true,
itemCount: currentBooking.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
BookingModel? ans = currentBooking[index];
return CurrentBookingsWidget(
model: ans,
);
}),
],
);
}
},
);
}),
],
),
),

FutureBuilder(
future: APIService().getBookingHistory(month: store.month, year: store.year),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const UpcomingBookingShimmer(number: 8);
} else if (snapshot.hasError) {
print(snapshot.error);
return const Text('Error');
} else {
List<BookingModel> currentBooking = snapshot.data!;
if(currentBooking.isEmpty)
{
return EmptyState(text: 'No bookings');
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListView.builder(
shrinkWrap: true,
itemCount: currentBooking.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
BookingModel? ans = currentBooking[index];
return CurrentBookingsWidget(
model: ans,
);
}),
],
);
}
},
),
],
),
),
);
}
),
);
}
}
}
3 changes: 2 additions & 1 deletion packages/irbs/lib/src/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:irbs/src/globals/colors.dart';
import 'package:irbs/src/globals/styles.dart';
import 'package:irbs/src/screens/upcoming_bookings.dart';
import 'package:irbs/src/services/api.dart';
import 'package:irbs/src/store/common_store.dart';
import 'package:irbs/src/store/data_store.dart';
Expand Down Expand Up @@ -185,7 +186,7 @@ class _HomeState extends State<Home> {
),
),
onTap: (){

Navigator.of(context).push(MaterialPageRoute(builder: (context) => UpcomingBookingsPage()));
},
) : Container(),

Expand Down
75 changes: 75 additions & 0 deletions packages/irbs/lib/src/screens/upcoming_bookings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:irbs/src/models/booking_model.dart';
import 'package:irbs/src/services/api.dart';
import 'package:irbs/src/store/common_store.dart';
import 'package:irbs/src/widgets/drop_down.dart';
import 'package:irbs/src/widgets/home/current_bookings_widget.dart';
import 'package:irbs/src/widgets/home/empty_sate.dart';
import 'package:irbs/src/widgets/shimmer/current_booking_shimmer.dart';
import 'package:provider/provider.dart';
import '../globals/colors.dart';
import '../globals/styles.dart';

class UpcomingBookingsPage extends StatefulWidget {
const UpcomingBookingsPage({Key? key}) : super(key: key);

@override
State<UpcomingBookingsPage> createState() => _UpcomingBookingsPageState();
}

class _UpcomingBookingsPageState extends State<UpcomingBookingsPage> {
@override
Widget build(BuildContext context) {
var store = context.read<CommonStore>();
return Scaffold(
backgroundColor: Themes.backgroundColor,
appBar: AppBar(
centerTitle: true,
title: const Text(
'Upcoming Booking',
style: appBarStyle,
),
backgroundColor: Themes.tileColor,
),
body: Padding(
padding: const EdgeInsets.only(top: 16),
child: SingleChildScrollView(
child: Observer(builder: (context) {
return FutureBuilder(
future: APIService()
.getUpcomingBokings(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const UpcomingBookingShimmer(number: 8);
} else if (snapshot.hasError) {
return const Text('Error');
} else {
List<BookingModel> currentBooking = snapshot.data!;
if (currentBooking.isEmpty) {
return const EmptyState(text: 'No bookings');
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListView.builder(
shrinkWrap: true,
itemCount: currentBooking.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
BookingModel? ans = currentBooking[index];
return CurrentBookingsWidget(
model: ans,
);
}),
],
);
}
},
);
}),
),
),
);
}
}

0 comments on commit c06982d

Please sign in to comment.