Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import 'package:flutter / material . dart'; import ' . . / viewmodel / owner _ request _ list _ viewmodel.dart'; class OwnerRequestListPage extends StatefulWidget {

import 'package:flutter/material.dart';
import '../viewmodel/owner_request_list_viewmodel.dart';
class OwnerRequestListPage extends StatefulWidget {
@override
_OwnerRequestListPageState createState()=>_OwnerRequestListPageState();
}
class _OwnerRequestListPageState extends State {
final OwnerRequestListViewModel viewModel = OwnerRequestListViewModel();
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: const Text('Reservation Requests'),
backgroundColor: Colors.blueGrey,
automaticallyImplyLeading: false,
actions: [
PopupMenuButton(
onSelected: (value){
if (value == 'viewProfile'){
Navigator.pushNamed(context,'/restaurantProfilePage');
} else if (value == 'logout'){
_handleLogout(context);
}
},
itemBuilder: (context)=>[
const PopupMenuItem(
value: 'viewProfile',
child: Text('View Restaurant Profile'),
),
const PopupMenuItem(
value: 'logout',
child: Text('Logout'),
),
],
),
],
),
body: _buildReservationList(),
);
}
Widget _buildReservationList(){
return viewModel.reservationRequests.isEmpty
? const Center(
child: Text(
'No reservation requests',
style: TextStyle(fontSize: 18),
),
)
: ListView.builder(
itemCount: viewModel.reservationRequests.length,
itemBuilder: (context, index){
return _buildReservationRequestCard(
context, viewModel.reservationRequests[index]);
},
);
}
Widget _buildReservationRequestCard(
BuildContext context, Reservation reservation){
return Card(
margin: const EdgeInsets.all(8.0),
child: ListTile(
title: Text(
'${reservation.userName}- ${reservation.numberOfGuests} Guests'),
subtitle: Text('Date: ${reservation.dateTime}'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: (){
_handleAccept(context, reservation);
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.blueGrey),
child: const Text('Accept',
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: (){
_handleReject(context, reservation);
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.orangeAccent),
child: const Text(
'Reject',
style:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
),
],
),
),
);
}
void _handleAccept(BuildContext context, Reservation reservation){
viewModel.acceptReservation(reservation);
_showSnackbar(context, 'Reservation accepted');
}
void _handleReject(BuildContext context, Reservation reservation){
viewModel.rejectReservation(reservation);
_showSnackbar(context, 'Reservation rejected');
}
void _handleLogout(BuildContext context){
Navigator.pushReplacementNamed(context,'/');
}
void _showSnackbar(BuildContext context, String message){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
duration: Duration(seconds: 2),
actionOverflowThreshold: 2,
),
);
}
}
MAKE THIS CODE HAVE FIREBASE DATABASE , WHEN YOU CLICK SIGN IN BY USERNAME AND PASSWORD, GOES TO THIS PAGE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

How does expected inflation occur?

Answered: 1 week ago

Question

turtle crawled 2.1m in one minute. What was its speed in k(m)/(h)

Answered: 1 week ago

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago