From 00a63c7ebb7c266f58c910d135dcd7eacd8919a1 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 02:05:52 +0530 Subject: [PATCH 1/9] Refactored code --- lib/main.dart | 4 ++-- lib/screens/addoxygen.dart | 26 +++++++++++++++++++++++ lib/screens/plasmaform.dart | 37 ++++---------------------------- lib/widgets/formbanner.dart | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 35 deletions(-) create mode 100644 lib/screens/addoxygen.dart create mode 100644 lib/widgets/formbanner.dart diff --git a/lib/main.dart b/lib/main.dart index d600826..7a0ebfc 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/addoxygen.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -30,7 +30,7 @@ class MyApp extends StatelessWidget { primaryColor: kelectronBlue, iconTheme: IconThemeData(color: kelectronBlue), ), - home: DonorList(), + home: AddOxygenDetails(), ); } } diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart new file mode 100644 index 0000000..4feb795 --- /dev/null +++ b/lib/screens/addoxygen.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:plaso_connect/widgets/formbanner.dart'; + +class AddOxygenDetails extends StatefulWidget { + @override + _AddOxygenDetailsState createState() => _AddOxygenDetailsState(); +} + +class _AddOxygenDetailsState extends State { + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return SafeArea( + child: Scaffold( + body: Stack( + children: [ + formBanner( + size: size, + svgPath: "assets/images/login.svg", + ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/plasmaform.dart b/lib/screens/plasmaform.dart index c2b8f48..9b8da89 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( 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), + ), + ); +} From 01b735c3890fc8e837e91605346d2f447d1bd708 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 02:25:24 +0530 Subject: [PATCH 2/9] TextEditingController for oxygenform --- lib/main.dart | 2 +- lib/screens/addoxygen.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 7a0ebfc..1a823b5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,7 +7,7 @@ import 'package:plaso_connect/screens/addoxygen.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp(); + // await Firebase.initializeApp(); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, ]).then((val) { diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart index 4feb795..ee1e84f 100644 --- a/lib/screens/addoxygen.dart +++ b/lib/screens/addoxygen.dart @@ -16,7 +16,7 @@ class _AddOxygenDetailsState extends State { children: [ formBanner( size: size, - svgPath: "assets/images/login.svg", + svgPath: "assets/images/medicine.svg", ), ], ), From 49a12859e180fe8146ed997b6c5a96a9d4abb5f8 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 02:25:37 +0530 Subject: [PATCH 3/9] TextEditingController for oxygenform --- lib/screens/addoxygen.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart index ee1e84f..d404d56 100644 --- a/lib/screens/addoxygen.dart +++ b/lib/screens/addoxygen.dart @@ -7,6 +7,35 @@ class AddOxygenDetails extends StatefulWidget { } 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 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; From e3f66ffa424c4971d96eedcf9cd29aaa2227bbf7 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 02:58:50 +0530 Subject: [PATCH 4/9] OxygenForm UI --- lib/screens/addoxygen.dart | 112 ++++++++++++++++++++++++++++++++++++ lib/screens/plasmaform.dart | 8 +++ lib/screens/signup.dart | 2 + lib/widgets/inputfield.dart | 2 + 4 files changed, 124 insertions(+) diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart index d404d56..16741b8 100644 --- a/lib/screens/addoxygen.dart +++ b/lib/screens/addoxygen.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:plaso_connect/constants/colors.dart'; import 'package:plaso_connect/widgets/formbanner.dart'; +import 'package:plaso_connect/widgets/inputfield.dart'; class AddOxygenDetails extends StatefulWidget { @override @@ -47,9 +49,119 @@ class _AddOxygenDetailsState extends State { 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: () { + 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 9b8da89..5819d86 100644 --- a/lib/screens/plasmaform.dart +++ b/lib/screens/plasmaform.dart @@ -125,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), @@ -292,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( @@ -408,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), @@ -416,6 +423,7 @@ class _PlasmaDonateState extends State { prefixIcon: prefixIcon, hintText: hintText, textInputType: textInputType, + maxLines: maxLines, ), ); } 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/widgets/inputfield.dart b/lib/widgets/inputfield.dart index ccf3499..3ad01c2 100644 --- a/lib/widgets/inputfield.dart +++ b/lib/widgets/inputfield.dart @@ -7,6 +7,7 @@ Widget inputField({ required IconData prefixIcon, required String hintText, required TextInputType textInputType, + required int maxLines, }) { return Container( decoration: newboxDecoration(), @@ -17,6 +18,7 @@ Widget inputField({ fontSize: 22, color: Colors.grey[700], ), + maxLines: maxLines, decoration: InputDecoration( filled: true, fillColor: Color(0xFFEFEEEE), From 1a9fbf207e032c9b5b4186aee2b191cc5819ac25 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 03:15:15 +0530 Subject: [PATCH 5/9] Added OxygenPostModel --- lib/models/oxygenpost.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/models/oxygenpost.dart diff --git a/lib/models/oxygenpost.dart b/lib/models/oxygenpost.dart new file mode 100644 index 0000000..a35d604 --- /dev/null +++ b/lib/models/oxygenpost.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, + }; + } +} From 6059c97b9a7632103a7bae5ed8bd838c3274e9dc Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 03:21:34 +0530 Subject: [PATCH 6/9] Added uploadOxygen Function --- .../{oxygenpost.dart => oxygenpostmodel.dart} | 0 lib/services/database.dart | 14 ++++++++++++++ 2 files changed, 14 insertions(+) rename lib/models/{oxygenpost.dart => oxygenpostmodel.dart} (100%) diff --git a/lib/models/oxygenpost.dart b/lib/models/oxygenpostmodel.dart similarity index 100% rename from lib/models/oxygenpost.dart rename to lib/models/oxygenpostmodel.dart diff --git a/lib/services/database.dart b/lib/services/database.dart index bceb548..7a6b3b7 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,17 @@ 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()); + } + } } From 641e7ac03feee18b5047a6704e79b3d671c0df5a Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 03:54:51 +0530 Subject: [PATCH 7/9] Oxygen Upload --- lib/main.dart | 2 +- lib/screens/addoxygen.dart | 16 ++++++++++++++++ lib/widgets/inputfield.dart | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1a823b5..7a0ebfc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,7 +7,7 @@ import 'package:plaso_connect/screens/addoxygen.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - // await Firebase.initializeApp(); + await Firebase.initializeApp(); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, ]).then((val) { diff --git a/lib/screens/addoxygen.dart b/lib/screens/addoxygen.dart index 16741b8..0b8c3ee 100644 --- a/lib/screens/addoxygen.dart +++ b/lib/screens/addoxygen.dart @@ -1,5 +1,7 @@ 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'; @@ -16,6 +18,19 @@ class _AddOxygenDetailsState extends State { 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(); @@ -108,6 +123,7 @@ class _AddOxygenDetailsState extends State { SizedBox(height: 30), GestureDetector( onTap: () { + postPressed(); print("Posted"); }, child: doneBtn(), diff --git a/lib/widgets/inputfield.dart b/lib/widgets/inputfield.dart index 3ad01c2..117becf 100644 --- a/lib/widgets/inputfield.dart +++ b/lib/widgets/inputfield.dart @@ -14,11 +14,11 @@ Widget inputField({ child: TextFormField( controller: controller, keyboardType: textInputType, + maxLines: maxLines, style: TextStyle( fontSize: 22, color: Colors.grey[700], ), - maxLines: maxLines, decoration: InputDecoration( filled: true, fillColor: Color(0xFFEFEEEE), From 456e09c879ee247aaef68b7c8c1a19178319450e Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 04:13:01 +0530 Subject: [PATCH 8/9] Added OxygenPostCard --- lib/main.dart | 4 +- lib/screens/showOxygenposts.dart | 73 ++++++++++++++++++++++++++++++++ lib/services/database.dart | 7 +++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 lib/screens/showOxygenposts.dart diff --git a/lib/main.dart b/lib/main.dart index 7a0ebfc..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/addoxygen.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: AddOxygenDetails(), + home: ShowOxygenPosts(), ); } } diff --git a/lib/screens/showOxygenposts.dart b/lib/screens/showOxygenposts.dart new file mode 100644 index 0000000..8703e42 --- /dev/null +++ b/lib/screens/showOxygenposts.dart @@ -0,0 +1,73 @@ +import 'package:flutter/material.dart'; +import 'package:plaso_connect/constants/colors.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( + body: Column( + children: [ + Container( + margin: EdgeInsets.all(20), + padding: EdgeInsets.all(20), + decoration: newboxDecoration(), + width: size.width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "This is a title", + style: TextStyle( + color: kelectronBlue, + fontSize: 22, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 3), + Text( + "This is a description", + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 3), + Text( + "Area PIN: 733202", + style: TextStyle( + color: kelectronBlue, + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 3), + Text( + "30/07/2001 -by Admin", + style: TextStyle( + color: Colors.grey[800], + 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/services/database.dart b/lib/services/database.dart index 7a6b3b7..5e52eb8 100644 --- a/lib/services/database.dart +++ b/lib/services/database.dart @@ -34,4 +34,11 @@ class DatabaseMethod { print(e.toString()); } } + + Stream getOxygen({required String pin}) { + return db + .collection("oxygenPosts") + .where("pin", isEqualTo: pin) + .snapshots(); + } } From fe5b4418eac79841204cc55177d1c244e9357c71 Mon Sep 17 00:00:00 2001 From: niloysikdar Date: Sun, 2 May 2021 04:26:08 +0530 Subject: [PATCH 9/9] ShowOxygenPosts Completed --- lib/screens/showOxygenposts.dart | 161 ++++++++++++++++++++----------- 1 file changed, 103 insertions(+), 58 deletions(-) diff --git a/lib/screens/showOxygenposts.dart b/lib/screens/showOxygenposts.dart index 8703e42..50c56eb 100644 --- a/lib/screens/showOxygenposts.dart +++ b/lib/screens/showOxygenposts.dart @@ -1,5 +1,7 @@ +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 { @@ -8,66 +10,109 @@ class ShowOxygenPosts extends StatelessWidget { Size size = MediaQuery.of(context).size; return SafeArea( child: Scaffold( - body: Column( - children: [ - Container( - margin: EdgeInsets.all(20), - padding: EdgeInsets.all(20), - decoration: newboxDecoration(), - width: size.width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "This is a title", - style: TextStyle( - color: kelectronBlue, - fontSize: 22, - fontWeight: FontWeight.w600, - ), - ), - SizedBox(height: 3), - Text( - "This is a description", - style: TextStyle( - color: kelectronBlue, - fontSize: 20, - fontWeight: FontWeight.w500, - ), - ), - SizedBox(height: 3), - Text( - "Area PIN: 733202", - style: TextStyle( - color: kelectronBlue, - fontSize: 18, - fontWeight: FontWeight.w500, - ), - ), - SizedBox(height: 3), - Text( - "30/07/2001 -by Admin", - style: TextStyle( - color: Colors.grey[800], - fontSize: 18, - fontWeight: FontWeight.w500, - ), - ), - SizedBox(height: 3), - Text( - "Role: Admin", - style: TextStyle( - color: Colors.grey[800], - fontSize: 18, - fontWeight: FontWeight.w500, - ), - ), - ], - ), - ), - ], + 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, + ), + ), + ], + ), + ); + } }