I am making a flight application. I want to redirect to page containing data same to one flight i select. I redirect from one page to other where containing flights and the flights redirect to hotels containing data same to flight. Now i want to take the same page data to third page containing select date. I am not sure how to do that
This page contains flight data i am getting using Stream Builder and making parameter of Document Snapshot
import 'package:bpe_application/dum.dart';
import 'package:bpe_application/home/dumy.dart';
import 'package:bpe_application/home/flight.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
Widget list() {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("flights").snapshots(),
builder: (context, snapshot) {
return snapshot.hasData
? ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot dc = snapshot.data!.docs [index];
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 100,
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
child: Column(
children: [
Expanded(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 100,
child:
Text(
"From",
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 11,
),
),
),
GestureDetector(
child: Icon(Icons.arrow_circle_right,size: 35,),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>Flight(
dc: snapshot.data!.docs[index],
)));
},
)
],
),
),
SizedBox(height: 9),
Row(
children: [
Expanded(
child: Text(
dc['from'],
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 13,
),
),
),
SizedBox(
width: 16,
),
],
),
SizedBox(height: 13),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 100,
child: Text(
dc['city1'],
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 11,
),
),
),
],
)
],
),
),
Container(
color: Colors.white,
child: Row(
children: [
SizedBox(
height: 20,
width: 10,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.grey.shade300,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LayoutBuilder(
builder: (context, constraints) {
return Flex(
children: List.generate(
(constraints.constrainWidth() / 10)
.floor(),
(index) => SizedBox(
height: 1,
width: 5,
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors
.grey.shade300),
),
)),
direction: Axis.horizontal,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
);
},
),
),
),
FlatButton(
onPressed: () {},
child: Icon(Icons.watch_later_outlined),
),
SizedBox(
height: 20,
width: 10,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
bottomLeft: Radius.circular(10)),
color: Colors.grey.shade300,
),
),
),
],
),
),
Container(
height: 110,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(16),
bottomRight: Radius.circular(16)),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 0, 8),
child: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 100,
child: Text(
"To",
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 12,
),
),
),
],
),
SizedBox(height: 13),
Row(
children: [
Text(
dc['to'],
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 13,
),
),
SizedBox(
width: 16,
),
],
),
SizedBox(height: 11),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 100,
child: Text(
dc['city2'],
style: GoogleFonts.limelight(
color: Colors.black,
fontSize: 11,
),
),
),
],
)
],
),
),
),
],
),
)
);
},
)
: Center(
child: CircularProgressIndicator(),
);
},
);
}
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent, //top bar color
systemNavigationBarColor: Colors.black, //bottom bar color
systemNavigationBarIconBrightness: Brightness.dark,
));
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
title: Padding(
padding: const EdgeInsets.fromLTRB(70, 0, 0, 0),
child: Text("Flights",
style: GoogleFonts.limelight(
color: Colors.white
),),
),
),
body: ClipRRect(
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0),
),
child: Container(
height: 800.0,
width: double.infinity,
color: Colors.grey.shade200,
child: list(),
),
),
);
}
}
This page where i redirect first the hotel detail page
class Flight extends StatefulWidget {
final dc;
Flight({required this.dc});
@override
State<Flight> createState() => _FlightState();
}
class _FlightState extends State<Flight> {
final _formkey = GlobalKey<FormState>();
var name = '';
var location = '';
var price = '';
var review = '';
var description = '';
var total = '';
book() async {
await FirebaseFirestore.instance
.collection('Book')
.doc(FirebaseAuth.instance.currentUser!.uid)
.set({
'from': widget.dc.get('from'),
'to': widget.dc.get('to'),
'city1': widget.dc.get('city1'),
'city2': widget.dc.get('city2'),
'name': name,
'location': location,
'price': price,
'review': review,
'description': description,
'total': total
})
.then((value) => print('User Added'))
.catchError((error) => print('Falied to add user: $error'));
}
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent, //top bar color
systemNavigationBarColor: Colors.black, //bottom bar color
systemNavigationBarIconBrightness: Brightness.dark,
));
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
title: Padding(
padding: const EdgeInsets.fromLTRB(70, 0, 0, 0),
child: Text(
"Flights",
style: GoogleFonts.limelight(
fontSize: 25,
),
),
),
),
body: FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance
.collection('AddHotel')
.doc(FirebaseAuth.instance.currentUser!.uid)
.get(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
print('somthing went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
var data = snapshot.data;
name = data!['name'];
location = data['location'];
price = data['price'];
review = data['review'];
description = data['description'];
total = data['total'];
return ClipRRect(
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0),
),
child: Container(
height: 40,
width: 320,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
color: Color.fromARGB(255, 218, 162, 16),
onPressed: () {
setState(() {
book();
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Calender(
dc: snapshot.data!.docs[index] ,
)));
},
child: Center(
child: Text(
"Book",
style: GoogleFonts.limelight(
color: Colors.white,
),
),
),
),
),
],
),
),
),
),
);
}));
}
}
I just want to know here in hotel details page how can i make the DocumentSnapshot parameter to pass as constructor to Calender Screen
Thanks in Advance