diff --git a/lib/main.dart b/lib/main.dart index d600826..05ec130 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:plaso_connect/constants/colors.dart'; -import 'package:plaso_connect/screens/donorlist.dart'; +import 'package:plaso_connect/screens/showOxygenposts.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -30,7 +30,7 @@ class MyApp extends StatelessWidget { primaryColor: kelectronBlue, iconTheme: IconThemeData(color: kelectronBlue), ), - home: DonorList(), + home: ShowOxygenPosts(), ); } } diff --git a/lib/models/oxygenpostmodel.dart b/lib/models/oxygenpostmodel.dart new file mode 100644 index 0000000..a35d604 --- /dev/null +++ b/lib/models/oxygenpostmodel.dart @@ -0,0 +1,28 @@ +class OxygenPostModel { + final String title; + final String description; + final String pin; + final String postedOn; + final String postedBy; + final String postedRole; + + OxygenPostModel({ + required this.title, + required this.description, + required this.pin, + required this.postedOn, + required this.postedBy, + required this.postedRole, + }); + + Map toMap() { + return { + "title": title, + "description": description, + "pin": pin, + "postedOn": postedOn, + "postedBy": postedBy, + "postedRole": postedRole, + }; + } +} diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart new file mode 100644 index 0000000..0b8c3ee --- /dev/null +++ b/lib/screens/addoxygen.dart @@ -0,0 +1,183 @@ +import 'package:flutter/material.dart'; +import 'package:plaso_connect/constants/colors.dart'; +import 'package:plaso_connect/models/oxygenpostmodel.dart'; +import 'package:plaso_connect/services/database.dart'; +import 'package:plaso_connect/widgets/formbanner.dart'; +import 'package:plaso_connect/widgets/inputfield.dart'; + +class AddOxygenDetails extends StatefulWidget { + @override + _AddOxygenDetailsState createState() => _AddOxygenDetailsState(); +} + +class _AddOxygenDetailsState extends State { + late TextEditingController titlecontroller; + late TextEditingController descriptioncontroller; + late TextEditingController pincontroller; + + String headerstring = + "Please ensure all the data that you are providing are from verified sources.\nFeeding any false information or spamming will lead to permanent ban."; + + void postPressed() async { + var oxygenPostModel = OxygenPostModel( + title: titlecontroller.text, + description: descriptioncontroller.text, + pin: pincontroller.text, + postedOn: DateTime.now().toString(), + postedBy: "Admin", + postedRole: "Admin", + ); + await DatabaseMethod().uploadOxygen(oxygenPostModel); + clearcontrollers(); + } + + void clearcontrollers() { + titlecontroller.clear(); + descriptioncontroller.clear(); + pincontroller.clear(); + } + + @override + void initState() { + super.initState(); + titlecontroller = TextEditingController(); + descriptioncontroller = TextEditingController(); + pincontroller = TextEditingController(); + } + + @override + void dispose() { + titlecontroller.dispose(); + descriptioncontroller.dispose(); + pincontroller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return SafeArea( + child: Scaffold( + body: Stack( + children: [ + formBanner( + size: size, + svgPath: "assets/images/medicine.svg", + ), + SingleChildScrollView( + child: Container( + width: double.infinity, + margin: EdgeInsets.only( + top: size.height * 0.35, + left: 20, + right: 20, + ), + padding: EdgeInsets.all(15), + decoration: BoxDecoration( + color: kbackgroundLight, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(20), + topRight: Radius.circular(20), + ), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + blurRadius: 10.0, + spreadRadius: 5.0, + offset: Offset(0.0, 0.0), + ) + ], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "*$headerstring", + style: TextStyle( + color: Colors.red, + fontSize: 15, + ), + ), + SizedBox(height: 10), + inputforOxygen( + controller: titlecontroller, + prefixIcon: Icons.title_rounded, + hintText: "Title of the post", + textInputType: TextInputType.text, + maxLines: 1, + ), + inputforOxygen( + controller: descriptioncontroller, + prefixIcon: Icons.description_rounded, + hintText: "Full Information", + textInputType: TextInputType.text, + maxLines: 3, + ), + inputforOxygen( + controller: pincontroller, + prefixIcon: Icons.location_on_rounded, + hintText: "Area PIN code", + textInputType: TextInputType.number, + maxLines: 1, + ), + SizedBox(height: 30), + GestureDetector( + onTap: () { + postPressed(); + print("Posted"); + }, + child: doneBtn(), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + + Widget doneBtn() { + return Container( + margin: EdgeInsets.symmetric(horizontal: 30), + child: Material( + elevation: 5, + borderRadius: BorderRadius.circular(15), + color: kelectronBlue[700], + child: Container( + padding: EdgeInsets.symmetric(vertical: 12), + child: Center( + child: Text( + "Post", + style: TextStyle( + color: Colors.white, + fontSize: 20, + fontWeight: FontWeight.w600, + ), + ), + ), + ), + ), + ); + } + + Widget inputforOxygen({ + required TextEditingController controller, + required IconData prefixIcon, + required String hintText, + required TextInputType textInputType, + required int maxLines, + }) { + return Container( + margin: EdgeInsets.symmetric(vertical: 10), + child: inputField( + controller: controller, + prefixIcon: prefixIcon, + hintText: hintText, + textInputType: textInputType, + maxLines: maxLines, + ), + ); + } +} diff --git a/lib/screens/plasmaform.dart b/lib/screens/plasmaform.dart index c2b8f48..5819d86 100644 --- a/lib/screens/plasmaform.dart +++ b/lib/screens/plasmaform.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:plaso_connect/constants/colors.dart'; import 'package:plaso_connect/models/donormodel.dart'; import 'package:plaso_connect/services/database.dart'; +import 'package:plaso_connect/widgets/formbanner.dart'; import 'package:plaso_connect/widgets/inputfield.dart'; class PlasmaDonate extends StatefulWidget { @@ -80,38 +80,9 @@ class _PlasmaDonateState extends State { child: Scaffold( body: Stack( children: [ - Positioned( - top: 0, - left: 0, - child: Container( - height: size.height * 0.3, - width: size.width, - padding: EdgeInsets.all(15), - decoration: BoxDecoration( - boxShadow: [ - BoxShadow( - color: klightShadowForLight, - offset: Offset(0.0, 0.0), - blurRadius: 7.0, - ), - BoxShadow( - color: kdarkShadowForLight, - offset: Offset(4.0, 4.0), - blurRadius: 7.0, - ), - ], - color: Color(0xFFEFEEEE), - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(30), - bottomRight: Radius.circular(30), - ), - // image: DecorationImage( - // image: AssetImage("assets/images/banner2.png"), - // fit: BoxFit.cover, - // ), - ), - child: SvgPicture.asset("assets/images/login.svg"), - ), + formBanner( + size: size, + svgPath: "assets/images/login.svg", ), SingleChildScrollView( child: Container( @@ -154,30 +125,35 @@ class _PlasmaDonateState extends State { prefixIcon: Icons.account_circle_rounded, hintText: "Full Name", textInputType: TextInputType.name, + maxLines: 1, ), inputforPlasma( controller: phonecontroller, prefixIcon: Icons.phone_rounded, hintText: "Phone Number", textInputType: TextInputType.phone, + maxLines: 1, ), inputforPlasma( controller: agecontroller, prefixIcon: Icons.add_rounded, hintText: "Age", textInputType: TextInputType.number, + maxLines: 1, ), inputforPlasma( controller: addresscontroller, prefixIcon: Icons.location_on_rounded, hintText: "Full Address", textInputType: TextInputType.name, + maxLines: 3, ), inputforPlasma( controller: pincontroller, prefixIcon: Icons.location_on_rounded, hintText: "Address PIN code", textInputType: TextInputType.number, + maxLines: 1, ), Padding( padding: const EdgeInsets.symmetric(vertical: 5), @@ -321,6 +297,7 @@ class _PlasmaDonateState extends State { prefixIcon: Icons.date_range_rounded, hintText: "Date of Recovery", textInputType: TextInputType.datetime, + maxLines: 1, ) : Container(height: 0), Row( @@ -437,6 +414,7 @@ class _PlasmaDonateState extends State { required IconData prefixIcon, required String hintText, required TextInputType textInputType, + required int maxLines, }) { return Container( margin: EdgeInsets.symmetric(vertical: 10), @@ -445,6 +423,7 @@ class _PlasmaDonateState extends State { prefixIcon: prefixIcon, hintText: hintText, textInputType: textInputType, + maxLines: maxLines, ), ); } diff --git a/lib/screens/showOxygenposts.dart b/lib/screens/showOxygenposts.dart new file mode 100644 index 0000000..50c56eb --- /dev/null +++ b/lib/screens/showOxygenposts.dart @@ -0,0 +1,118 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/material.dart'; +import 'package:plaso_connect/constants/colors.dart'; +import 'package:plaso_connect/models/oxygenpostmodel.dart'; +import 'package:plaso_connect/widgets/boxdecoration.dart'; + +class ShowOxygenPosts extends StatelessWidget { + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return SafeArea( + child: Scaffold( + appBar: AppBar( + title: Text("Oxygen Posts"), + centerTitle: true, + ), + body: Container( + height: size.height, + width: size.width, + child: StreamBuilder( + stream: FirebaseFirestore.instance + .collection("oxygenPosts") + .snapshots(), + builder: + (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + return ListView.builder( + itemCount: snapshot.data!.docs.length, + itemBuilder: (context, index) { + OxygenPostModel oxygenPostModel = OxygenPostModel( + title: snapshot.data!.docs[index]["title"], + description: snapshot.data!.docs[index]["description"], + pin: snapshot.data!.docs[index]["pin"], + postedOn: snapshot.data!.docs[index]["postedOn"], + postedBy: snapshot.data!.docs[index]["postedBy"], + postedRole: snapshot.data!.docs[index]["postedRole"], + ); + return oxygenCard( + oxygenPostModel: oxygenPostModel, + size: size, + ); + }, + ); + } else if (snapshot.hasError) { + return Text("Error"); + } else { + return Center( + child: CircularProgressIndicator(), + ); + } + }, + ), + ), + ), + ); + } + + Widget oxygenCard({ + required OxygenPostModel oxygenPostModel, + required Size size, + }) { + return Container( + margin: EdgeInsets.all(20), + padding: EdgeInsets.all(20), + decoration: newboxDecoration(), + width: size.width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + oxygenPostModel.title, + style: TextStyle( + color: kelectronBlue, + fontSize: 22, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 3), + Text( + oxygenPostModel.description, + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 3), + Text( + "Area PIN: ${oxygenPostModel.pin}", + style: TextStyle( + color: Colors.grey[800], + fontSize: 18, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 10), + Text( + "30/07/2001 -by Admin", + style: TextStyle( + color: kelectronBlue, + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 3), + Text( + "Role: Admin", + style: TextStyle( + color: Colors.grey[800], + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/signup.dart b/lib/screens/signup.dart index fa8a283..6292673 100644 --- a/lib/screens/signup.dart +++ b/lib/screens/signup.dart @@ -45,6 +45,7 @@ class _SignUpPageState extends State { prefixIcon: Icons.account_circle_rounded, hintText: "Full Name", textInputType: TextInputType.name, + maxLines: 1, ), SizedBox(height: 25), inputField( @@ -52,6 +53,7 @@ class _SignUpPageState extends State { prefixIcon: Icons.phone, hintText: "Phone Number", textInputType: TextInputType.phone, + maxLines: 1, ), SizedBox(height: 35), loginButton( diff --git a/lib/services/database.dart b/lib/services/database.dart index bceb548..5e52eb8 100644 --- a/lib/services/database.dart +++ b/lib/services/database.dart @@ -1,5 +1,6 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:plaso_connect/models/donormodel.dart'; +import 'package:plaso_connect/models/oxygenpostmodel.dart'; class DatabaseMethod { final FirebaseFirestore db = FirebaseFirestore.instance; @@ -20,4 +21,24 @@ class DatabaseMethod { .where("pin", isEqualTo: pin) .snapshots(); } + + Future uploadOxygen(OxygenPostModel oxygenPostModel) async { + var userMap = oxygenPostModel.toMap(); + try { + await db + .collection("oxygenPosts") + .doc(oxygenPostModel.title) + .set(userMap); + print("Done"); + } catch (e) { + print(e.toString()); + } + } + + Stream getOxygen({required String pin}) { + return db + .collection("oxygenPosts") + .where("pin", isEqualTo: pin) + .snapshots(); + } } diff --git a/lib/widgets/formbanner.dart b/lib/widgets/formbanner.dart new file mode 100644 index 0000000..4deac52 --- /dev/null +++ b/lib/widgets/formbanner.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:plaso_connect/constants/colors.dart'; + +Widget formBanner({ + required Size size, + required String svgPath, +}) { + return Positioned( + top: 0, + left: 0, + child: Container( + height: size.height * 0.3, + width: size.width, + padding: EdgeInsets.all(15), + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: klightShadowForLight, + offset: Offset(0.0, 0.0), + blurRadius: 7.0, + ), + BoxShadow( + color: kdarkShadowForLight, + offset: Offset(4.0, 4.0), + blurRadius: 7.0, + ), + ], + color: Color(0xFFEFEEEE), + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(30), + bottomRight: Radius.circular(30), + ), + // image: DecorationImage( + // image: AssetImage("assets/images/banner2.png"), + // fit: BoxFit.cover, + // ), + ), + child: SvgPicture.asset(svgPath), + ), + ); +} diff --git a/lib/widgets/inputfield.dart b/lib/widgets/inputfield.dart index ccf3499..117becf 100644 --- a/lib/widgets/inputfield.dart +++ b/lib/widgets/inputfield.dart @@ -7,12 +7,14 @@ Widget inputField({ required IconData prefixIcon, required String hintText, required TextInputType textInputType, + required int maxLines, }) { return Container( decoration: newboxDecoration(), child: TextFormField( controller: controller, keyboardType: textInputType, + maxLines: maxLines, style: TextStyle( fontSize: 22, color: Colors.grey[700],