From 044afedbc559ea65e5346c0c1ccc83b8f6ead947 Mon Sep 17 00:00:00 2001 From: Khwaishks <98842925+Khwaishks@users.noreply.github.com> Date: Sun, 25 Jun 2023 02:38:14 +0530 Subject: [PATCH] update ContactUs.dart --- lib/Screens/ContactUs.dart | 351 +++++++++++++++++++++++++++++++++---- 1 file changed, 314 insertions(+), 37 deletions(-) diff --git a/lib/Screens/ContactUs.dart b/lib/Screens/ContactUs.dart index 4b45426..bdf23c3 100644 --- a/lib/Screens/ContactUs.dart +++ b/lib/Screens/ContactUs.dart @@ -1,6 +1,232 @@ +// import 'package:flutter/material.dart'; +// import 'package:firebase_core/firebase_core.dart'; +// import 'package:cloud_firestore/cloud_firestore.dart'; + +// void main() async { +// WidgetsFlutterBinding.ensureInitialized(); +// await Firebase.initializeApp(); +// runApp(MyApp()); +// } + +// class MyApp extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// return MaterialApp( +// title: 'Smart Printer', +// theme: ThemeData( +// // app's theme configuration +// ), +// home: HomePage(), +// ); +// } +// } + +// class HomePage extends StatelessWidget { +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// appBar: AppBar( +// title: Text('Home'), +// ), +// body: Center( +// child: ElevatedButton( +// onPressed: () { +// Navigator.push( +// context, +// MaterialPageRoute(builder: (context) => ContactUs()), +// ); +// }, +// child: Text('Contact Us'), +// ), +// ), +// ); +// } +// } + +// class ContactUs extends StatelessWidget { +// final TextEditingController nameController = TextEditingController(); +// final TextEditingController emailController = TextEditingController(); +// final TextEditingController messageController = TextEditingController(); + +// ContactUs({Key? key}) : super(key: key); + +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// body: SingleChildScrollView( // Wrap the Container with SingleChildScrollView +// child: Container( +// padding: EdgeInsets.symmetric(horizontal: 20.0), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Padding( +// padding: const EdgeInsets.only(left: 10.0, top: 60.0), +// child: GestureDetector( +// onTap: () { +// Navigator.pop(context); +// }, +// child: CircleAvatar( +// child: Icon(Icons.arrow_back, size: 30.0, color: Colors.blue), +// backgroundColor: Colors.white, +// radius: 30.0, +// ), +// ), +// ), +// SizedBox( +// height: 10.0, +// ), +// Padding( +// padding: const EdgeInsets.only(left: 20.0), +// child: Text( +// 'Contact Us', +// style: TextStyle( +// color: Colors.blue, +// fontSize: 30.0, +// fontWeight: FontWeight.w700, +// ), +// ), +// ), +// Padding( +// padding: const EdgeInsets.only(left: 20.0), +// child: Text( +// 'Team', +// style: TextStyle( +// color: Colors.white, +// fontSize: 18, +// fontWeight: FontWeight.w700, +// ), +// ), +// ), +// SizedBox(height: 20), +// Container( +// decoration: BoxDecoration( +// color: Colors.white, +// borderRadius: BorderRadius.only( +// topLeft: Radius.circular(20.0), +// topRight: Radius.circular(20.0), +// ), +// ), +// padding: EdgeInsets.all(20.0), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.stretch, +// children: [ +// SizedBox(height: 20), +// Text( +// "We value your input! Get in touch with us and we'll be happy to respond as soon as possible.", +// style: TextStyle(fontSize: 16, color: Colors.blue), +// ), +// SizedBox(height: 30), +// TextFormField( +// controller: nameController, +// decoration: InputDecoration( +// hintText: "Enter your name", +// border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), +// ), +// ), +// SizedBox(height: 20), +// TextFormField( +// controller: emailController, +// keyboardType: TextInputType.emailAddress, +// decoration: InputDecoration( +// hintText: "Enter your email", +// border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), +// ), +// ), +// SizedBox(height: 20), +// TextFormField( +// controller: messageController, +// maxLines: 4, +// decoration: InputDecoration( +// hintText: "Enter your message", +// border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), +// ), +// ), +// SizedBox(height: 40), +// ElevatedButton( +// onPressed: () { +// submitForm(context); +// }, +// style: ElevatedButton.styleFrom( +// primary: Colors.blue, +// padding: EdgeInsets.symmetric(vertical: 15), +// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)), +// ), +// child: Text( +// "Submit", +// style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white), +// ), +// ), +// ], +// ), +// ), +// ], +// ), +// ), +// ), +// ); +// } + +// void submitForm(BuildContext context) async { +// String name = nameController.text; +// String email = emailController.text; +// String message = messageController.text; + +// if (name.isNotEmpty && email.isNotEmpty && message.isNotEmpty) { +// await FirebaseFirestore.instance.collection('contacts').add({ +// 'name': name, +// 'email': email, +// 'message': message, +// 'timestamp': DateTime.now(), +// }); + +// showDialog( +// context: context, +// builder: (BuildContext context) { +// return AlertDialog( +// title: Text("Success"), +// content: Text("Form submitted successfully!"), +// actions: [ +// TextButton( +// child: Text("OK"), +// onPressed: () { +// Navigator.of(context).pop(); +// }, +// ), +// ], +// ); +// }, +// ); + +// nameController.clear(); +// emailController.clear(); +// messageController.clear(); +// } else { +// showDialog( +// context: context, +// builder: (BuildContext context) { +// return AlertDialog( +// title: Text("Error"), +// content: Text("Please fill in all the fields."), +// actions: [ +// TextButton( +// child: Text("OK"), +// onPressed: () { +// Navigator.of(context).pop(); +// }, +// ), +// ], +// ); +// }, +// ); +// } +// } +// } import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:smart_printer/Screens/SideMenu.dart'; +import 'package:smart_printer/Screens/HomePage.dart'; +import 'package:firebase_auth/firebase_auth.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -14,7 +240,7 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Smart Printer', theme: ThemeData( - // app's theme configuration + // app's theme configuration ), home: HomePage(), ); @@ -22,6 +248,8 @@ class MyApp extends StatelessWidget { } class HomePage extends StatelessWidget { + final String user = FirebaseAuth.instance.currentUser!.email!; + @override Widget build(BuildContext context) { return Scaffold( @@ -29,14 +257,22 @@ class HomePage extends StatelessWidget { title: Text('Home'), ), body: Center( - child: ElevatedButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => ContactUs()), - ); - }, - child: Text('Contact Us'), + child: Padding( + padding: const EdgeInsets.all(20.0), + child: ElevatedButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => ContactUs(defaultEmail: user)), + ); + }, + child: Text('Contact Us'), + style: ElevatedButton.styleFrom( + primary: Colors.blue, + padding: EdgeInsets.symmetric(vertical: 12), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + ), + ), ), ), ); @@ -44,17 +280,34 @@ class HomePage extends StatelessWidget { } class ContactUs extends StatelessWidget { - final TextEditingController nameController = TextEditingController(); + //Added controllers. final TextEditingController emailController = TextEditingController(); - final TextEditingController messageController = TextEditingController(); + final TextEditingController nameController; + final TextEditingController phoneController; + final TextEditingController messageController; - ContactUs({Key? key}) : super(key: key); + // Initialized controllers. + ContactUs({Key? key, required String defaultEmail}) + : nameController = TextEditingController(), + phoneController = TextEditingController(), + messageController = TextEditingController(), + super(key: key) { + emailController.text = defaultEmail; + } @override Widget build(BuildContext context) { return Scaffold( - body: SingleChildScrollView( // Wrap the Container with SingleChildScrollView + body: SingleChildScrollView( child: Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [Color(0xFFA0B5EB), Color(0xFFC9F0E4)], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + ), + ), + padding: EdgeInsets.symmetric(horizontal: 20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -67,7 +320,7 @@ class ContactUs extends StatelessWidget { }, child: CircleAvatar( child: Icon(Icons.arrow_back, size: 30.0, color: Colors.blue), - backgroundColor: Colors.white, + backgroundColor:Colors.white.withOpacity(0.5), radius: 30.0, ), ), @@ -91,7 +344,7 @@ class ContactUs extends StatelessWidget { child: Text( 'Team', style: TextStyle( - color: Colors.white, + color: Colors.blue, fontSize: 18, fontWeight: FontWeight.w700, ), @@ -100,7 +353,8 @@ class ContactUs extends StatelessWidget { SizedBox(height: 20), Container( decoration: BoxDecoration( - color: Colors.white, + // color: Colors.white, + color: Colors.white.withOpacity(0.5), borderRadius: BorderRadius.only( topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0), @@ -113,9 +367,20 @@ class ContactUs extends StatelessWidget { SizedBox(height: 20), Text( "We value your input! Get in touch with us and we'll be happy to respond as soon as possible.", - style: TextStyle(fontSize: 16, color: Colors.blue), + style: TextStyle(fontSize: 18, color: Colors.blue,fontWeight: FontWeight.bold), ), SizedBox(height: 30), + TextFormField( + controller: emailController, + keyboardType: TextInputType.emailAddress, + autofocus: false, + enabled: false, // Adding this line to disable editing + decoration: InputDecoration( + hintText: "Enter your email", + border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), + ), + ), + SizedBox(height: 20), TextFormField( controller: nameController, decoration: InputDecoration( @@ -123,15 +388,17 @@ class ContactUs extends StatelessWidget { border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), ), ), - SizedBox(height: 20), + + SizedBox(height:20), TextFormField( - controller: emailController, - keyboardType: TextInputType.emailAddress, + controller: phoneController, + keyboardType: TextInputType.phone, decoration: InputDecoration( - hintText: "Enter your email", + hintText: "Enter your phone number", border: OutlineInputBorder(borderRadius: BorderRadius.circular(30)), ), ), + SizedBox(height: 20), TextFormField( controller: messageController, @@ -142,18 +409,21 @@ class ContactUs extends StatelessWidget { ), ), SizedBox(height: 40), - ElevatedButton( - onPressed: () { - submitForm(context); - }, - style: ElevatedButton.styleFrom( - primary: Colors.blue, - padding: EdgeInsets.symmetric(vertical: 15), - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)), - ), - child: Text( - "Submit", - style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white), + Container( + alignment: Alignment.center, + child: ElevatedButton( + onPressed: () { + submitForm(context); + }, + style: ElevatedButton.styleFrom( + primary: Colors.blue, + padding: EdgeInsets.symmetric(vertical: 12, horizontal: 24), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + ), + child: Text( + "Submit", + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white), + ), ), ), ], @@ -165,17 +435,21 @@ class ContactUs extends StatelessWidget { ), ); } + // Retrieve values. void submitForm(BuildContext context) async { - String name = nameController.text; String email = emailController.text; + String name = nameController.text; + String phone = phoneController.text; String message = messageController.text; - if (name.isNotEmpty && email.isNotEmpty && message.isNotEmpty) { + // Added to Firestore document. + if (email.isNotEmpty && name.isNotEmpty && phone.isNotEmpty && message.isNotEmpty) { await FirebaseFirestore.instance.collection('contacts').add({ - 'name': name, 'email': email, + 'name': name, 'message': message, + 'phone': phone, 'timestamp': DateTime.now(), }); @@ -196,10 +470,13 @@ class ContactUs extends StatelessWidget { ); }, ); + // Clear fields. + // emailController.clear(); nameController.clear(); - emailController.clear(); messageController.clear(); + phoneController.clear(); + } else { showDialog( context: context,