From c78dc2b92d0acd9df282b540088a453057cab32e Mon Sep 17 00:00:00 2001 From: Harjot Singh Date: Sun, 4 Sep 2022 04:54:26 +0530 Subject: [PATCH] mandi page done --- .../lib/controllers/priceController.dart | 31 ++ agriculture/lib/crops.dart | 73 +++-- agriculture/lib/mandi_screen.dart | 265 +++++++++------ agriculture/lib/pricesScreen.dart | 301 ++++++++++++++++++ 4 files changed, 531 insertions(+), 139 deletions(-) create mode 100644 agriculture/lib/controllers/priceController.dart create mode 100644 agriculture/lib/pricesScreen.dart diff --git a/agriculture/lib/controllers/priceController.dart b/agriculture/lib/controllers/priceController.dart new file mode 100644 index 0000000..0b11466 --- /dev/null +++ b/agriculture/lib/controllers/priceController.dart @@ -0,0 +1,31 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:get/get.dart'; + +class PriceController extends GetxController { + Stream>>? snapshot; + getPrices(String cropName) async { + snapshot = await FirebaseFirestore.instance + .collection('crops') + .doc(cropName) + .collection('prices') + .snapshots(); + } + + List chartData = [ + // PriceData(DateTime(2016), 25), + // PriceData(DateTime(2017), 35), + PriceData(DateTime(2015), 25), + PriceData(DateTime(2016), 15), + PriceData(DateTime(2017), 115), + PriceData(DateTime(2018), 65), + PriceData(DateTime(2019), 65), + PriceData(DateTime(2020), 65), + PriceData(DateTime(2021), 65), + ]; +} + +class PriceData { + PriceData(this.year, this.price); + final DateTime year; + final int price; +} diff --git a/agriculture/lib/crops.dart b/agriculture/lib/crops.dart index 2bf0cd7..45990af 100644 --- a/agriculture/lib/crops.dart +++ b/agriculture/lib/crops.dart @@ -19,40 +19,47 @@ class _CropsState extends State { child: StreamBuilder>>( stream: FirebaseFirestore.instance.collection('crops').snapshots(), builder: (context, snapshot) { - return ListView.builder( - itemCount: snapshot.data!.docs.length, - itemBuilder: (context, index) { - String name = snapshot.data!.docs[index]['name']; - String image = snapshot.data!.docs[index]['imageUrl']; - String season = snapshot.data!.docs[index]['season']; - String water = snapshot.data!.docs[index]['water']; - String temp = snapshot.data!.docs[index]['temp']; - String soil = snapshot.data!.docs[index]['soil']; - String plantation = snapshot.data!.docs[index]['plantation']; - String method = snapshot.data!.docs[index]['method']; - String disease = snapshot.data!.docs[index]['diseases']; - String solutions = snapshot.data!.docs[index]['solution']; + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return ListView.builder( + itemCount: snapshot.data!.docs.length, + itemBuilder: (context, index) { + String name = snapshot.data!.docs[index]['name']; + String image = snapshot.data!.docs[index]['imageUrl']; + String season = snapshot.data!.docs[index]['season']; + String water = snapshot.data!.docs[index]['water']; + String temp = snapshot.data!.docs[index]['temp']; + String soil = snapshot.data!.docs[index]['soil']; + String plantation = + snapshot.data!.docs[index]['plantation']; + String method = snapshot.data!.docs[index]['method']; + String disease = snapshot.data!.docs[index]['diseases']; + String solutions = snapshot.data!.docs[index]['solution']; - return recommended(image, name, season, temp, soil, water, - plantation, method, disease, solutions, context); - }, - //scrollDirection: Axis.vertical, - primary: false, - // children: [ - // recommended("assets/rice.jpg", "Rice", "Kharif", - // "22-32 degree Celsius", "Deep clayey and loamy soil"), - // recommended("assets/wheat.jpg", "Wheat", "Rabi", - // " 10-15 degree Celsius ", "Well-drained fertile loamy"), - // recommended("assets/sugarcane.jpg", "Sugarcane", "Kharif", - // " 21-27 degree Celsius ", " Deep rich loamy soil"), - // recommended("assets/tea.jpg", "Tea", "Kharif", - // "20-30 degree Celsius ", "deep friable loamy soil"), - // recommended("assets/coffee.jpg", "Coffee", "Kharif", - // "15-28 degree Celsius ", "deep friable loamy soil"), - // recommended("assets/cotton.jpg", "Cotton", "Kharif", - // "21-30 degree Celsius ", "Black soil of Deccan Plateau"), - // ], - ); + return recommended(image, name, season, temp, soil, water, + plantation, method, disease, solutions, context); + }, + //scrollDirection: Axis.vertical, + primary: false, + // children: [ + // recommended("assets/rice.jpg", "Rice", "Kharif", + // "22-32 degree Celsius", "Deep clayey and loamy soil"), + // recommended("assets/wheat.jpg", "Wheat", "Rabi", + // " 10-15 degree Celsius ", "Well-drained fertile loamy"), + // recommended("assets/sugarcane.jpg", "Sugarcane", "Kharif", + // " 21-27 degree Celsius ", " Deep rich loamy soil"), + // recommended("assets/tea.jpg", "Tea", "Kharif", + // "20-30 degree Celsius ", "deep friable loamy soil"), + // recommended("assets/coffee.jpg", "Coffee", "Kharif", + // "15-28 degree Celsius ", "deep friable loamy soil"), + // recommended("assets/cotton.jpg", "Cotton", "Kharif", + // "21-30 degree Celsius ", "Black soil of Deccan Plateau"), + // ], + ); + } }), ), ); diff --git a/agriculture/lib/mandi_screen.dart b/agriculture/lib/mandi_screen.dart index d4cc09b..221019c 100644 --- a/agriculture/lib/mandi_screen.dart +++ b/agriculture/lib/mandi_screen.dart @@ -1,3 +1,4 @@ +import 'package:agriculture/pricesScreen.dart'; import 'package:flutter/material.dart'; import 'package:flutter/src/foundation/key.dart'; import 'package:flutter/src/widgets/framework.dart'; @@ -13,7 +14,13 @@ class MandiScreen extends StatelessWidget { Wrap( children: [ InkWell( - onTap: () {}, + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PriceScreen(cropName: 'Wheat'), + )); + }, child: SizedBox( height: 180, width: 180, @@ -40,127 +47,173 @@ class MandiScreen extends StatelessWidget { ), ), ), - SizedBox( - height: 180, - width: 180, - child: Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(15), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: 80, - child: Center( - child: - Image.asset('assets/cropIcons/rice.png'))), - Text( - "Rice", - style: TextStyle(fontSize: 24), - ) - ], + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PriceScreen(cropName: 'Rice'), + )); + }, + child: SizedBox( + height: 180, + width: 180, + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: 80, + child: Center( + child: Image.asset( + 'assets/cropIcons/rice.png'))), + Text( + "Rice", + style: TextStyle(fontSize: 24), + ) + ], + ), ), ), ), ), - SizedBox( - height: 180, - width: 180, - child: Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(15), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: 80, - child: Center( - child: Image.asset( - 'assets/cropIcons/coffee.png'))), - Text( - "Coffee", - style: TextStyle(fontSize: 24), - ) - ], + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PriceScreen(cropName: 'Coffee'), + )); + }, + child: SizedBox( + height: 180, + width: 180, + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: 80, + child: Center( + child: Image.asset( + 'assets/cropIcons/coffee.png'))), + Text( + "Coffee", + style: TextStyle(fontSize: 24), + ) + ], + ), ), ), ), ), - SizedBox( - height: 180, - width: 180, - child: Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(15), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: 80, - child: Center( - child: Image.asset( - 'assets/cropIcons/cotton.png'))), - Text( - "Cotton", - style: TextStyle(fontSize: 24), - ) - ], + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PriceScreen(cropName: 'Cotton'), + )); + }, + child: SizedBox( + height: 180, + width: 180, + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: 80, + child: Center( + child: Image.asset( + 'assets/cropIcons/cotton.png'))), + Text( + "Cotton", + style: TextStyle(fontSize: 24), + ) + ], + ), ), ), ), ), - SizedBox( - height: 180, - width: 180, - child: Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(15), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: 80, - child: Center( - child: Image.asset( - 'assets/cropIcons/sugarcane.png'))), - Text( - "Sugarcane", - style: TextStyle(fontSize: 24), - ) - ], + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + PriceScreen(cropName: 'Sugarcane'), + )); + }, + child: SizedBox( + height: 180, + width: 180, + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: 80, + child: Center( + child: Image.asset( + 'assets/cropIcons/sugarcane.png'))), + Text( + "Sugarcane", + style: TextStyle(fontSize: 24), + ) + ], + ), ), ), ), ), - SizedBox( - height: 180, - width: 180, - child: Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(15), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: 80, - child: Center( - child: - Image.asset('assets/cropIcons/tea.png'))), - Text( - "Tea", - style: TextStyle(fontSize: 24), - ) - ], + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PriceScreen(cropName: 'Tea'), + )); + }, + child: SizedBox( + height: 180, + width: 180, + child: Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + height: 80, + child: Center( + child: + Image.asset('assets/cropIcons/tea.png'))), + Text( + "Tea", + style: TextStyle(fontSize: 24), + ) + ], + ), ), ), ), diff --git a/agriculture/lib/pricesScreen.dart b/agriculture/lib/pricesScreen.dart new file mode 100644 index 0000000..508b796 --- /dev/null +++ b/agriculture/lib/pricesScreen.dart @@ -0,0 +1,301 @@ +import 'package:agriculture/controllers/priceController.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/foundation/key.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; + +class PriceScreen extends StatelessWidget { + String cropName; + PriceScreen({Key? key, required this.cropName}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10), + child: Column( + children: [ + SizedBox( + width: double.infinity, + height: 60, + child: StreamBuilder>>( + stream: FirebaseFirestore.instance + .collection('crops') + .doc(cropName.toLowerCase()) + .collection('prices') + .snapshots(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10, vertical: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text("Change in Price: "), + Row( + children: [ + Text(snapshot.data!.docs[1]['percent'] + .toString() + + " %"), + snapshot.data!.docs[1]['percent'] > 0 + ? Icon( + Icons.arrow_upward, + color: Colors.green, + ) + : Icon( + Icons.arrow_downward, + color: Colors.red, + ) + ], + ), + ], + ), + ), + ); + } + }), + ), + StreamBuilder>>( + stream: FirebaseFirestore.instance + .collection('crops') + .doc(cropName.toLowerCase()) + .collection('mandiPrice') + .snapshots(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + return Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(10.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( + children: [ + Text( + "", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text( + "Mandi 1", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text( + "Mandi 2", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text( + "Mandi 3", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text( + "Mandi 4", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text( + "Mandi 5", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + ], + ), + Column( + children: [ + Text( + "Min Price", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[0]['min']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[1]['min']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[2]['min']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[3]['min']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[4]['min']), + ], + ), + Column( + children: [ + Text( + "Avg Price", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[0]['price']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[1]['price']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[2]['price']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[3]['price']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[4]['price']), + ], + ), + Column( + children: [ + Text( + "Max Price", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[0]['max']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[1]['max']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[2]['max']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[3]['max']), + SizedBox( + height: 10, + ), + Text(snapshot.data!.docs[4]['max']), + ], + ) + ], + ), + ), + ); + } + }), + StreamBuilder>>( + stream: FirebaseFirestore.instance + .collection('crops') + .doc(cropName.toLowerCase()) + .collection('prices') + .doc('price') + .collection('graphPrice') + .snapshots(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } else { + List chartData = [ + PriceData( + DateTime(2017), snapshot.data!.docs[0]['price']), + PriceData( + DateTime(2018), snapshot.data!.docs[1]['price']), + PriceData( + DateTime(2019), snapshot.data!.docs[2]['price']), + PriceData( + DateTime(2020), snapshot.data!.docs[3]['price']), + PriceData( + DateTime(2021), snapshot.data!.docs[4]['price']), + // PriceData(DateTime(2022), snapshot.data!.docs[5]['price']), + ]; + + return Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), + child: Padding( + padding: const EdgeInsets.all(2), + child: SfCartesianChart( + title: ChartTitle( + text: "Wheat", + textStyle: TextStyle( + fontSize: 10, + decoration: TextDecoration.underline)), + primaryXAxis: DateTimeAxis(), + series: [ + LineSeries( + markerSettings: MarkerSettings(isVisible: true), + dataSource: chartData, + dataLabelSettings: + DataLabelSettings(isVisible: true), + xValueMapper: (PriceData priceData, _) => + priceData.year, + yValueMapper: (PriceData priceData, _) => + priceData.price, + ) + ], + ), + ), + ); + } + }) + ], + ), + ), + ); + } +}