diff --git a/lib/api/google_sign_in.dart b/lib/api/google_sign_in.dart deleted file mode 100644 index ec3d6f4..0000000 --- a/lib/api/google_sign_in.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:google_sign_in/google_sign_in.dart'; - -class GoogleSignInApi { - static final _googleSignIn = GoogleSignIn(); - - static Future login() => _googleSignIn.signIn(); - static Future logout() => _googleSignIn.disconnect(); -} diff --git a/lib/controller/global_controller.dart b/lib/controller/global_controller.dart deleted file mode 100644 index 6512421..0000000 --- a/lib/controller/global_controller.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:geolocator/geolocator.dart'; -import 'package:get/get.dart'; - -class GlobalController extends GetxController { - final RxBool _isLoading = true.obs; - final RxDouble _lattitude = 0.0.obs; - final RxDouble _longitude = 0.0.obs; - - RxBool checkLoading() => _isLoading; - RxDouble getLattitude() => _lattitude; - RxDouble getLongitude() => _longitude; - - @override - void onInit() { - if (_isLoading.isTrue) { - getLocation(); - } - super.onInit(); - } - - getLocation() async { - bool isServiceEnabled; - LocationPermission locationPermission; - - isServiceEnabled = await Geolocator.isLocationServiceEnabled(); - // return if service is not enabled - if (!isServiceEnabled) { - return Future.error("Location service is not enabled"); - } - - // status of the service - locationPermission = await Geolocator.checkPermission(); - - if (locationPermission == LocationPermission.deniedForever) { - return Future.error("Location permission is denied forever"); - } else if (locationPermission == LocationPermission.denied) { - // request location - locationPermission = await Geolocator.requestPermission(); - if (locationPermission == LocationPermission.denied) { - return Future.error("Location permission is denied"); - } - } - - //getting the current location - return await Geolocator.getCurrentPosition( - desiredAccuracy: LocationAccuracy.high) - .then((value) { - _lattitude.value = value.latitude; - _longitude.value = value.longitude; - _isLoading.value = false; - }); - } -} diff --git a/lib/datas/category_json.dart b/lib/datas/category_json.dart deleted file mode 100644 index d4952c2..0000000 --- a/lib/datas/category_json.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore: constant_identifier_names -const List CoursesJson = [ - { - 'image': 'assets/images/cardImg/quality.jpg', - 'title': 'Crop Quality Detection', - }, - { - 'image': 'assets/images/cardImg/disease.jpg', - 'title': "Crop's Disease Detection ", - }, - { - 'image': 'assets/images/cardImg/weed.jpg', - 'title': 'Weed Detection', - }, - { - 'image': 'assets/images/cardImg/yeild.webp', - 'title': 'Yeild Prediction', - }, -]; diff --git a/lib/datas/disease_info.dart b/lib/datas/disease_info.dart deleted file mode 100644 index ff10c2a..0000000 --- a/lib/datas/disease_info.dart +++ /dev/null @@ -1,20 +0,0 @@ -Map> cropDiseases = { - 'bacterial blight': { - 'Symptoms': - 'Water-soaked spots on leaves which are delimited by leaf veins, giving them an angular appearance; lesions increase in size and turn black and necrotic; leaves drop from the plant; disease may also cause elongated gray-black lesions extending from the leaves to petioles and stem which are known as the "blackarm" phase; severe blackarm symptoms may cause the stem to be girdled; water-soaked lesions may be present on bolls; boll lesions enlarge and become sunken and brown-black in color.', - 'Cause': 'Bacterium', - 'Comments': - 'Disease if often introduced to cotton fields by infested seeds.', - 'Management': - ' The use of resistant cotton varieties is the most effective method of controlling the disease; cultural practices such as plowing crop residue into soil after harvest can also limit disease emergence.', - }, - 'fussarium wilt': { - 'Symptoms': - 'Wilting of cotyledons and seedling leaves; cotyledons become chlorotic at the edges and then necrotic; older plants exhibit symptoms of wilting and leaf chlorosis; wilting is usually gradual but may be pronounced after heavy summer rain; if infection is severe plants become stunted and may be killed; vascular system of infected plants becomes discolored and can be seen by cutting the stem.', - 'Cause': 'Fungus', - 'Comments': - 'Disease emergence is favored by warm temperatures; fungus may be introduced to field through infected seed or by contaminated equipment and human movement.', - 'Management': - 'Use on certified, disease-free seed; plant varieties with higher resistance to the disease in areas with a history of Fusarium diseases; fumigating the soil may reduce disease incidence.', - }, -}; diff --git a/lib/detection_pages/crop_quality.dart b/lib/detection_pages/crop_quality.dart deleted file mode 100644 index 36d49b3..0000000 --- a/lib/detection_pages/crop_quality.dart +++ /dev/null @@ -1,658 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:google_fonts/google_fonts.dart'; -import 'package:http/http.dart'; - -class CropQuality extends StatefulWidget { - final String title; - final String category; - - const CropQuality({super.key, required this.title, required this.category}); - @override - State createState() { - // TODO: implement createState - return CropQualityState(); - } -} - -class CropQualityState extends State { - int type_of_crop = 0, soil_type = 0, pesticide_use = 0, pesticide_count = 0; - double pesticide_week = 0; - int count = 1; - bool isLoading = false, result = false; - int ans = 0; - @override - Widget build(BuildContext context) { - List questions = [ - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Row( - children: [ - const SizedBox( - width: 5, - ), - const CircleAvatar( - radius: 20, - foregroundColor: Colors.black, - backgroundColor: Colors.black, - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Container( - width: 290, - height: 50, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(25), - bottomRight: Radius.circular(25)), - ), - child: Align( - alignment: Alignment.centerRight, - child: Center( - child: Padding( - padding: const EdgeInsets.only(left: 15), - child: Text( - 'What Type of Crop are you growing?', - style: TextStyle( - fontFamily: GoogleFonts.poppins().fontFamily, - color: Colors.white, - fontSize: 16), - ), - ), - )), - ), - ), - ], - ), - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.all(10), - child: Container( - height: 50, - width: 150, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(5), - child: DropdownButton( - value: type_of_crop, - items: const [ - DropdownMenuItem( - value: 0, - child: Text("Food Crops"), - ), - DropdownMenuItem( - value: 1, - child: Text("Cash Crops"), - ), - ], - onChanged: (int? value) { - setState(() { - type_of_crop = value!; - }); - }), - ), - ), - ), - ), - Padding( - padding: const EdgeInsets.all(5), - child: Align( - alignment: Alignment.topRight, - child: ElevatedButton( - onPressed: () { - count = 2; - setState(() {}); - }, - child: const Text('OK'), - )), - ) - ], - ), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Row( - children: [ - const SizedBox( - width: 5, - ), - const CircleAvatar( - radius: 20, - foregroundColor: Colors.black, - backgroundColor: Colors.black, - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Container( - width: 290, - height: 50, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(25), - bottomRight: Radius.circular(25)), - ), - child: Center( - child: Text( - 'What Type of Soil are you using?', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 16), - ), - ), - ), - ), - ], - ), - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.all(10), - child: Container( - height: 50, - width: 225, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: DropdownButton( - value: soil_type, - items: const [ - DropdownMenuItem( - value: 0, - child: Text("Alluvial Soil"), - ), - DropdownMenuItem( - value: 1, - child: Text("Others(Red,Black etc)"), - ), - ], - onChanged: (int? value) { - setState(() { - soil_type = value!; - }); - }), - ), - ), - ), - ), - Padding( - padding: const EdgeInsets.all(5), - child: Align( - alignment: Alignment.topRight, - child: ElevatedButton( - onPressed: () { - count = 3; - setState(() {}); - }, - child: const Text('OK'), - )), - ) - ], - ), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Row( - children: [ - const SizedBox( - width: 5, - ), - const CircleAvatar( - radius: 20, - foregroundColor: Colors.black, - backgroundColor: Colors.black, - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Container( - width: 220, - height: 50, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(25), - bottomRight: Radius.circular(25)), - ), - child: Center( - child: Text( - 'Do you use pesticides?', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 16), - ), - ), - ), - ), - ], - ), - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.all(10), - child: Container( - height: 50, - width: 170, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - child: Padding( - padding: const EdgeInsets.all(5), - child: Container( - height: 50, - width: 150, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - child: DropdownButton( - value: pesticide_use, - items: const [ - DropdownMenuItem( - value: 0, - child: Text("Never"), - ), - DropdownMenuItem( - value: 1, - child: Text("Previously Used"), - ), - DropdownMenuItem( - value: 2, - child: Text("Currently Using"), - ), - ], - onChanged: (int? value) { - setState(() { - pesticide_use = value!; - }); - }), - ), - ), - ), - ), - ), - Padding( - padding: const EdgeInsets.all(5), - child: Align( - alignment: Alignment.topRight, - child: ElevatedButton( - onPressed: () { - count = 4; - setState(() {}); - }, - child: const Text('OK'), - )), - ) - ], - ), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Row( - children: [ - const SizedBox( - width: 5, - ), - const CircleAvatar( - radius: 20, - foregroundColor: Colors.black, - backgroundColor: Colors.black, - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Container( - width: 290, - height: 50, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(25), - bottomRight: Radius.circular(25)), - ), - child: Center( - child: Text( - 'Pesticide count in a week? (0-100)', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 16), - ), - ), - ), - ), - ], - ), - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.all(8), - child: Container( - width: 120, - height: 50, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - padding: const EdgeInsets.all(10), - child: TextField( - keyboardType: TextInputType.number, - onChanged: (value) { - setState(() {}); - pesticide_count = int.parse(value); - }, - )), - ), - ), - Padding( - padding: const EdgeInsets.all(5), - child: Align( - alignment: Alignment.topRight, - child: ElevatedButton( - onPressed: () { - count = 5; - setState(() {}); - }, - child: const Text('OK'), - )), - ) - ], - ), - Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Row( - children: [ - const SizedBox( - width: 5, - ), - const CircleAvatar( - radius: 20, - foregroundColor: Colors.black, - backgroundColor: Colors.black, - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Container( - width: 290, - height: 50, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(25), - bottomRight: Radius.circular(25)), - ), - child: Center( - child: Padding( - padding: const EdgeInsets.only(left: 15), - child: Text( - ' How many weeks did you use pesticide?', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 16), - ), - ), - ), - ), - ), - ], - ), - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: const EdgeInsets.all(8), - child: Container( - width: 120, - height: 50, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(15)), - padding: const EdgeInsets.all(10), - child: TextField( - keyboardType: TextInputType.number, - onChanged: (value) { - setState(() { - pesticide_week = double.parse(value); - }); - }, - )), - ), - ), - Padding( - padding: const EdgeInsets.all(20), - child: Align( - alignment: Alignment.topCenter, - child: GestureDetector( - onTap: () async { - isLoading = true; - ans = await getData(); - result = true; - setState(() {}); - }, - child: Container( - height: 40, - width: 350, - color: const Color.fromARGB(255, 75, 117, 32), - child: Center( - child: Text( - 'Submit', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 14), - ), - ), - ), - )), - ) - ], - ), - ]; - Size size = MediaQuery.of(context).size; - var height = size.height; - // TODO: implement build - return Scaffold( - appBar: AppBar( - title: Text( - "${widget.title} Crop Quality", - ), - elevation: 0.0, - backgroundColor: const Color.fromARGB(255, 75, 117, 32), - foregroundColor: const Color.fromARGB(255, 166, 231, 101), - // centerTitle: true, - // ignore: prefer_const_literals_to_create_immutables - ), - extendBodyBehindAppBar: true, - backgroundColor: const Color.fromARGB(255, 75, 117, 32), - body: (isLoading == false && result == false) - ? Column( - children: [ - SizedBox( - height: 275, - width: size.width, - child: Padding( - padding: const EdgeInsets.fromLTRB(20, 90, 0, 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const CircleAvatar( - radius: 55, - backgroundColor: Colors.white, - backgroundImage: - AssetImage("assets/images/app-logo.png"), - ), - const SizedBox( - height: 10, - ), - Text( - 'Digi Farmer', - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 32), - ) - ], - ), - ), - ), - Expanded( - child: Container( - height: height - 275 - 80, - width: size.width, - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: - BorderRadius.only(topLeft: Radius.circular(40))), - child: ListView.builder( - physics: const BouncingScrollPhysics(), - itemCount: count, - itemBuilder: (context, index) { - return questions[index]; - }, - )), - ), - Container( - color: Colors.white, - height: 80, - ), - ], - ) - : (result == false) - ? const CircularProgressIndicator() - : Container( - height: height, - width: size.width, - color: Colors.white, - child: Column( - children: [ - Container( - height: 250, - width: size.width, - color: const Color.fromARGB(255, 75, 117, 32), - child: Column( - children: [ - const SizedBox( - height: 60, - ), - Row( - children: [ - const Padding( - padding: EdgeInsets.all(16.0), - child: CircleAvatar( - backgroundImage: AssetImage( - 'assets/images/app-logo.png', - ), - radius: 50, - ), - ), - const SizedBox( - width: 10, - ), - Expanded( - child: Text( - 'Digi Farmer has calculated and here are the results!', - style: GoogleFonts.poppins( - fontSize: 16, color: Colors.white), - )), - ], - ), - Text( - 'Results', - style: GoogleFonts.poppins( - fontSize: 36, color: Colors.white), - ), - ], - )), - const SizedBox( - height: 60, - ), - SizedBox( - height: 300, - child: Image.asset( - getAsset(ans), - fit: BoxFit.fill, - )), - const SizedBox( - height: 15, - ), - Text( - getText(ans), - textAlign: TextAlign.center, - style: GoogleFonts.poppins( - fontSize: 26, fontWeight: FontWeight.w600), - ), - ], - )), - ); - } - - Future getData() async { - Random random = Random(); - int a1, a2, a3; - if (pesticide_count == 0) { - a1 = 1; - a2 = 0; - a3 = 0; - } else if (pesticide_count == 1) { - a1 = 0; - a2 = 1; - a3 = 0; - } else { - a1 = 0; - a2 = 0; - a3 = 1; - } - print(pesticide_week); - final url = Uri.parse( - 'http://karanpatra203.pythonanywhere.com/predict?a=${random.nextInt(4097 - 150) + 150}&b=$type_of_crop&c=$soil_type&d=$pesticide_count&e=$pesticide_week&f=${random.nextInt(50)}&g=$a1&h=$a2&i=$a3&k=0&l=0&m=1'); - print(url); - final headers = {"Content-type": "application/json"}; - final json = - '{"a"=${random.nextInt(4097 - 150) + 150}&"b"=$type_of_crop&"c"=$soil_type&"d"=$pesticide_count&"e"=$pesticide_week&"f"=${random.nextInt(50)}&"g"=1&"h"=2&"i"=3&"k=1&"l"=2&"m"=3}'; - final response = await get( - url, - ); - print('Status code: ${response.statusCode}'); - print('Body: ${response.body}'); - print(int.parse(response.body[1])); - return int.parse(response.body[1]); - } - - String getAsset(int ans) { - if (ans == 0) { - return "assets/plant_happy.png"; - } else { - return "assets/plant_sad.png"; - } - } - - String getText(int ans) { - if (ans == 0) { - return "Your crop is Healthy!!"; - } else if (ans == 1) { - return "Your crop may be damaged"; - } else { - return "Your crop is damaged due to overuse of pesticide"; - } - } -} diff --git a/lib/detection_pages/disease_detection.dart b/lib/detection_pages/disease_detection.dart deleted file mode 100644 index cb1adcd..0000000 --- a/lib/detection_pages/disease_detection.dart +++ /dev/null @@ -1,211 +0,0 @@ -import 'dart:io'; - -import 'package:digi_farmer/detection_pages/report_page.dart'; -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/util/model_locations.dart'; -import 'package:digi_farmer/widget/custom_heading.dart'; -import 'package:flutter/material.dart'; -import 'package:image_picker/image_picker.dart'; -import 'package:tflite/tflite.dart'; - -class DiseaseDetection extends StatefulWidget { - final String title; - final String category; - - const DiseaseDetection( - {super.key, required this.title, required this.category}); - - @override - _DiseaseDetectionState createState() => _DiseaseDetectionState(); -} - -class _DiseaseDetectionState extends State { - List? _outputs; - File? _image; - bool _loading = false; - final ImagePicker _picker = ImagePicker(); - - @override - void initState() { - super.initState(); - _loading = true; - - loadModel().then((value) { - setState(() { - _loading = false; - }); - }); - } - - loadModel() async { - if (widget.category == "Rice") { - await Tflite.loadModel( - model: MyModels.riceDiseaseModel, - labels: MyModels.riceDiseasetxt, - numThreads: 1, - ); - } else if (widget.category == "Wheat") { - await Tflite.loadModel( - model: MyModels.wheatDiseaseModel, - labels: MyModels.wheatDiseasetxt, - numThreads: 1, - ); - } else if (widget.category == "Cotton") { - await Tflite.loadModel( - model: MyModels.cottonDiseaseModel, - labels: MyModels.cottonDiseasetxt, - numThreads: 1, - ); - } else if (widget.category == "Sugarcane") { - await Tflite.loadModel( - model: MyModels.sugarcaneDiseaseModel, - labels: MyModels.sugarcaneDiseasetxt, - numThreads: 1, - ); - } - } - - classifyImage(File image) async { - var output = await Tflite.runModelOnImage( - path: image.path, - imageMean: 0.0, - imageStd: 255.0, - numResults: 2, - threshold: 0.2, - asynch: true); - setState(() { - _loading = false; - _outputs = output; - }); - } - - @override - void dispose() { - Tflite.close(); - super.dispose(); - } - - Future pickImage() async { - var image = await _picker.pickImage(source: ImageSource.gallery); - if (image == null) return null; - setState(() { - _loading = true; - _image = File(image.path); - }); - classifyImage(_image!); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - floatingActionButtonLocation: FloatingActionButtonLocation.miniCenterTop, - backgroundColor: const Color.fromARGB(255, 229, 243, 213), - appBar: AppBar( - title: Text( - widget.title.toString() + " Disease", - ), - elevation: 0.0, - backgroundColor: const Color.fromARGB(255, 75, 117, 32), - foregroundColor: const Color.fromARGB(255, 166, 231, 101), - // centerTitle: true, - // ignore: prefer_const_literals_to_create_immutables - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _loading - ? const Center(child: CircularProgressIndicator()) - : Container( - margin: const EdgeInsets.all(20), - width: MediaQuery.of(context).size.width * 0.8, - child: _image == null - ? Container() - : Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _image == null ? Container() : Image.file(_image!), - const SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text("Disease Name: "), - _image == null - ? Visibility( - child: Container(), - visible: false, - ) - : _outputs != null - ? Text( - _outputs![0]["label"] - .toString() - .toUpperCase(), - style: const TextStyle( - color: Colors.black, - fontSize: 20, - ), - ) - : Container(child: const Text("")), - ], - ), - const SizedBox( - height: 20, - ), - ElevatedButton.icon( - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CropReport( - diseaseName: _outputs![0]["label"]), - ), - ), - icon: const Icon(Icons.info), - label: const Text("See More Info"), - style: const ButtonStyle(), - ), - ], - ), - ), - !_loading && _image == null - ? Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Center( - child: CustomHeading( - subTitle: - " to Detect Disease in ${widget.title} Crops", - title: "Select an Image", - color: const Color.fromARGB(255, 75, 117, 32)), - ), - const SizedBox(height: spacer * 0.5), - FloatingActionButton( - tooltip: 'Pick Image', - onPressed: pickImage, - child: const Icon( - Icons.add_a_photo, - size: 20, - color: Colors.white, - ), - ), - ], - ) - : Container( - height: smallSpacer, - ), - - // IconButton( - // onPressed: pickImage, - // icon: Icon( - // Icons.add_a_photo, - // size: 20, - // color: Colors.white, - // ), - // ), - ], - ), - ); - } -} diff --git a/lib/detection_pages/report_page.dart b/lib/detection_pages/report_page.dart deleted file mode 100644 index ece42fc..0000000 --- a/lib/detection_pages/report_page.dart +++ /dev/null @@ -1,143 +0,0 @@ -import 'dart:io'; -import 'dart:ui'; - -import 'package:digi_farmer/datas/disease_info.dart'; -import 'package:flutter/material.dart'; - -import 'package:pdf/pdf.dart'; -import 'package:pdf/widgets.dart' as pw; -import 'package:path_provider/path_provider.dart'; -import 'package:flutter/rendering.dart'; - -final globalKey = GlobalKey(); - -class CropReport extends StatelessWidget { - final String diseaseName; - - const CropReport({super.key, required this.diseaseName}); - - @override - Widget build(BuildContext context) { - final disease = cropDiseases[diseaseName]; - - // print(disease); - return Scaffold( - appBar: AppBar( - title: const Text("Disease Info"), - elevation: 0.0, - backgroundColor: const Color.fromARGB(255, 75, 117, 32), - foregroundColor: const Color.fromARGB(255, 166, 231, 101), - ), - body: RepaintBoundary( - key: globalKey, // Add a global key to the RepaintBoundary widget - child: SingleChildScrollView( - child: ListView( - shrinkWrap: true, - physics: const BouncingScrollPhysics(), - children: [ - ListTile( - minVerticalPadding: 2, - title: Center( - child: Text( - diseaseName.toString().toUpperCase(), - style: const TextStyle( - fontSize: 22, - ), - )), - ), - ListTile( - title: const Text('Symptoms'), - subtitle: - Text(addBulletPoints(disease!["Symptoms"].toString())), - ), - ListTile( - title: const Text('Causes'), - subtitle: Text(disease["Cause"].toString()), - ), - ListTile( - title: const Text('Comments'), - subtitle: Text(disease["Comments"].toString()), - ), - ListTile( - title: const Text('Management Techniques'), - subtitle: - Text(addBulletPoints(disease["Management"].toString())), - ), - ], - ), - ), // Your text widget goes here - ), - floatingActionButton: FloatingActionButton( - onPressed: () { - generatePDF(); - }, - elevation: 0.0, - backgroundColor: const Color.fromARGB(255, 75, 117, 32), - foregroundColor: const Color.fromARGB(255, 166, 231, 101), - child: const Icon(Icons.file_download), - ), - ); - } - - String addBulletPoints(String text) { - List segments = text.split(';'); - List bulletPoints = []; - - for (String segment in segments) { - bulletPoints.add('• $segment'); - } - - return bulletPoints.join('\n'); - } - - Future generatePDF() async { - final pdf = pw.Document(); - - // Get the boundary of the RepaintBoundary widget - final boundary = - globalKey.currentContext?.findRenderObject() as RenderRepaintBoundary?; - if (boundary != null) { - final image = await boundary.toImage(); - final byteData = await image.toByteData(format: ImageByteFormat.png); - final pngBytes = byteData!.buffer.asUint8List(); - - final pdfImage = pw.MemoryImage(pngBytes); - - pdf.addPage( - pw.Page( - build: (pw.Context context) { - return pw.Center( - child: pw.Image(pdfImage), - ); - }, - ), - ); - - // Add the image of the text to the PDF - // pdf.addPage( - // pw.Page( - // build: (pw.Context context) { - // return pw.Center( - // child: pw.Image(pw.MemoryImage(pngBytes)), - // ); - // }, - // ), - // ); - - // Get the document directory path - final directory = await getApplicationDocumentsDirectory(); - final path = directory.path; - - // Save the PDF file - final file = File('$path/example.pdf'); - await file.writeAsBytes(await pdf.save()); - - // Open the PDF file - // Note: You can use any PDF viewer app installed on the device to open the PDF file - // For example, you can use the 'open_file' package to open the PDF using the default PDF viewer app - // Make sure to add the 'open_file' package to your pubspec.yaml file - // import 'package:open_file/open_file.dart'; - // await OpenFile.open(file.path); - } - } -} diff --git a/lib/detection_pages/weed_detection.dart b/lib/detection_pages/weed_detection.dart deleted file mode 100644 index a69653f..0000000 --- a/lib/detection_pages/weed_detection.dart +++ /dev/null @@ -1,154 +0,0 @@ -import 'dart:io'; - -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/util/model_locations.dart'; -import 'package:digi_farmer/widget/custom_heading.dart'; -import 'package:flutter/material.dart'; -import 'package:image_picker/image_picker.dart'; -import 'package:tflite/tflite.dart'; - -class WeedDetection extends StatefulWidget { - final String title; - final String category; - - const WeedDetection({super.key, required this.title, required this.category}); - - @override - WeedDetectionState createState() => WeedDetectionState(); -} - -class WeedDetectionState extends State { - List? _outputs; - File? _image; - bool _loading = false; - final ImagePicker _picker = ImagePicker(); - - @override - void initState() { - super.initState(); - _loading = true; - - loadModel().then((value) { - setState(() { - _loading = false; - }); - }); - } - - loadModel() async { - await Tflite.loadModel( - model: MyModels.weedDetectionModel, - labels: MyModels.weedDetectiontxt, - numThreads: 1, - ); - } - - classifyImage(File image) async { - var output = await Tflite.runModelOnImage( - path: image.path, - imageMean: 0.0, - imageStd: 255.0, - numResults: 2, - threshold: 0.2, - asynch: true); - setState(() { - _loading = false; - _outputs = output; - }); - } - - @override - void dispose() { - Tflite.close(); - super.dispose(); - } - - Future pickImage() async { - var image = await _picker.pickImage(source: ImageSource.gallery); - if (image == null) return null; - setState(() { - _loading = true; - _image = File(image.path); - }); - classifyImage(_image!); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - floatingActionButtonLocation: FloatingActionButtonLocation.miniCenterTop, - backgroundColor: Color.fromARGB(255, 229, 243, 213), - appBar: AppBar( - title: Text( - widget.title.toString() + " Weed Detection", - ), - elevation: 0.0, - backgroundColor: Color.fromARGB(255, 75, 117, 32), - foregroundColor: Color.fromARGB(255, 166, 231, 101), - // centerTitle: true, - // ignore: prefer_const_literals_to_create_immutables - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _loading - ? Center(child: CircularProgressIndicator()) - : Container( - margin: EdgeInsets.all(20), - width: MediaQuery.of(context).size.width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _image == null ? Container() : Image.file(_image!), - SizedBox( - height: 20, - ), - _image == null - ? Visibility( - child: Container(), - visible: false, - ) - : _outputs != null - ? Text( - _outputs![0]["label"], - style: TextStyle( - color: Colors.black, fontSize: 20), - ) - : Container(child: Text("")) - ], - ), - ), - !_loading && _image == null - ? Center( - child: CustomHeading( - subTitle: " to Detect Weed in ${widget.title} Crops", - title: "Select an Image", - color: Color.fromARGB(255, 75, 117, 32)), - ) - : Container( - height: smallSpacer, - ), - SizedBox(height: spacer), - FloatingActionButton( - tooltip: 'Pick Image', - onPressed: pickImage, - child: Icon( - Icons.add_a_photo, - size: 20, - color: Colors.white, - ), - ), - // IconButton( - // onPressed: pickImage, - // icon: Icon( - // Icons.add_a_photo, - // size: 20, - // color: Colors.white, - // ), - // ), - ], - ), - ); - } -} diff --git a/lib/detection_pages/yeild_prediction.dart b/lib/detection_pages/yeild_prediction.dart deleted file mode 100644 index 423e074..0000000 --- a/lib/detection_pages/yeild_prediction.dart +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:convert'; - -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/widget/custom_heading.dart'; -import 'package:flutter/material.dart'; -import 'package:http/http.dart'; - -class YieldPrediction extends StatefulWidget { - final String title; - final String category; - - const YieldPrediction( - {super.key, required this.title, required this.category}); - - @override - State createState() => _YieldPredictionState(); -} - -class _YieldPredictionState extends State { - final districtNameController = TextEditingController(); - final seasonNameController = TextEditingController(); - final areaNameController = TextEditingController(); - - // Posting json to the server - final url = "http://127.0.0.1:5000/jsonPost"; - void postData() async { - final response = await post(Uri.parse(url), body: { - "district": districtNameController, - "season": seasonNameController, - "area": areaNameController, - }); - } - - //Getting json output from the server - var _postsJson; - var img; - final url2 = "http://127.0.0.1:5000/dataupload"; - void fetchPosts() async { - final response2 = await get(Uri.parse(url2)); - final jsonData = jsonDecode(response2.body); - final imagefile = Image.network("http://127.0.0.1:5000/yieldimg/img.png"); - setState(() { - _postsJson = jsonData; - img = imagefile; - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - floatingActionButtonLocation: - FloatingActionButtonLocation.miniCenterTop, - backgroundColor: Color.fromARGB(255, 229, 243, 213), - appBar: AppBar( - title: Text( - widget.title.toString() + " Yield Prediction", - ), - elevation: 0.0, - backgroundColor: Color.fromARGB(255, 75, 117, 32), - foregroundColor: Color.fromARGB(255, 166, 231, 101), - // centerTitle: true, - // ignore: prefer_const_literals_to_create_immutables - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: CustomHeading( - title: widget.title + " Yield Prediction", - subTitle: "", - color: Color.fromARGB(255, 75, 117, 32)), - ), - Padding( - padding: EdgeInsets.all(15), - child: Column( - children: [ - Padding( - padding: EdgeInsets.all(15), - child: TextField( - controller: districtNameController, - decoration: InputDecoration( - border: OutlineInputBorder(), - labelText: 'District Name', - hintText: 'Enter Your District Name', - ), - ), - ), - Padding( - padding: EdgeInsets.all(15), - child: TextField( - controller: seasonNameController, - decoration: InputDecoration( - border: OutlineInputBorder(), - labelText: 'Season Name', - hintText: 'Enter the Season Name', - ), - ), - ), - Padding( - padding: EdgeInsets.all(15), - child: TextField( - controller: areaNameController, - decoration: InputDecoration( - border: OutlineInputBorder(), - labelText: 'Area Name', - hintText: 'Enter Your Area Name', - ), - ), - ), - SizedBox( - height: spacer, - ), - ElevatedButton( - child: Text('Submit'), - onPressed: postData, - ), - img != null ? img : Container(), - ], - ), - ) - ], - )); - } - - @override - void initState() { - super.initState(); - fetchPosts(); - } -} diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart deleted file mode 100644 index 0d813b0..0000000 --- a/lib/firebase_options.dart +++ /dev/null @@ -1,70 +0,0 @@ -// File generated by FlutterFire CLI. -// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members -import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; -import 'package:flutter/foundation.dart' - show defaultTargetPlatform, kIsWeb, TargetPlatform; - -/// Default [FirebaseOptions] for use with your Firebase apps. -/// -/// Example: -/// ```dart -/// import 'firebase_options.dart'; -/// // ... -/// await Firebase.initializeApp( -/// options: DefaultFirebaseOptions.currentPlatform, -/// ); -/// ``` -class DefaultFirebaseOptions { - static FirebaseOptions get currentPlatform { - if (kIsWeb) { - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for web - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - } - switch (defaultTargetPlatform) { - case TargetPlatform.android: - return android; - case TargetPlatform.iOS: - return ios; - case TargetPlatform.macOS: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for macos - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - case TargetPlatform.windows: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for windows - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - case TargetPlatform.linux: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for linux - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); - default: - throw UnsupportedError( - 'DefaultFirebaseOptions are not supported for this platform.', - ); - } - } - - static const FirebaseOptions android = FirebaseOptions( - apiKey: 'AIzaSyBMIQpZx0N8vAo1Oqw2I1OSR-sZR-cKDII', - appId: '1:643236272873:android:2c497bb2ce05f42a67ae78', - messagingSenderId: '643236272873', - projectId: 'digi-farmer-364606', - storageBucket: 'digi-farmer-364606.appspot.com', - ); - - static const FirebaseOptions ios = FirebaseOptions( - apiKey: 'AIzaSyBRcroPZAzEjmDpL54z-5K_Ug2LckJay_Y', - appId: '1:643236272873:ios:c3d2f74663f89a3467ae78', - messagingSenderId: '643236272873', - projectId: 'digi-farmer-364606', - storageBucket: 'digi-farmer-364606.appspot.com', - androidClientId: '643236272873-c329tbvepuuu23urpvup5nvcoo76bgjk.apps.googleusercontent.com', - iosClientId: '643236272873-qek5ng0ohg7abig4ane7rlp0b09frocg.apps.googleusercontent.com', - iosBundleId: 'com.example.digiFarmer', - ); -} diff --git a/lib/main.dart b/lib/main.dart deleted file mode 100644 index 700ddf0..0000000 --- a/lib/main.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:digi_farmer/views/welcome_page.dart'; -import 'package:flutter/material.dart'; -import 'package:firebase_core/firebase_core.dart'; -import 'package:provider/provider.dart'; - -import 'firebase_options.dart'; - -import 'util/google_sign_in.dart'; -import 'util/routes.dart'; -import 'views/login_page.dart'; -import 'widget/themes.dart'; - -Future main() async { - WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp( - options: DefaultFirebaseOptions.currentPlatform, - ); - - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - // This widget is the root of your application. - @override - Widget build(BuildContext context) => ChangeNotifierProvider( - create: (context) => GoogleSignInProvider(), - child: MaterialApp( - themeMode: ThemeMode.light, - theme: MyTheme.lightTheme(context), - debugShowCheckedModeBanner: false, - title: 'Flutter Demo', - home: const WelcomePage(), - initialRoute: MyRoutes.welcomeRoute, - routes: { - // "/": (context) => WelcomePage(), - MyRoutes.welcomeRoute: (context) => const WelcomePage(), - // MyRoutes.homeRoute: (context) => HomePage(), - MyRoutes.loginRoute: (context) => const LoginPage(), - // MyRoutes.cartRoute: (context) => CartPage(), - }, - ), - ); -} diff --git a/lib/model/user_model.dart b/lib/model/user_model.dart deleted file mode 100644 index 8aa6c1f..0000000 --- a/lib/model/user_model.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:io'; - -import 'package:cloud_firestore/cloud_firestore.dart'; - -class UserModel { - final String email; - final String name; - final int phone; - final String uid; - final String username; - final String profileImageUrl; - // final List followers; - // final List following; - - UserModel({ - required this.email, - required this.name, - required this.phone, - required this.username, - required this.uid, - required this.profileImageUrl, - - // required this.followers, - // required this.following, - }); - - Map toJson() => { - "email": email, - "uid": uid, - "name": name, - "phone": phone, - "username": username, - "profileImageUrl": profileImageUrl, - // "followers": followers, - // "following": following, - }; - - static UserModel? fromSnap(DocumentSnapshot snap) { - var snapshot = snap.data() as Map; - return UserModel( - username: snapshot['username'], - uid: snapshot['uid'], - name: snapshot['name'], - phone: snapshot['phone'], - // following: snapshot['following'], - // followers: snapshot['followers'], - email: snapshot['email'], - profileImageUrl: snapshot['profileImageUrl'], - ); - } -} diff --git a/lib/pages/account_page.dart b/lib/pages/account_page.dart deleted file mode 100644 index cdb7d59..0000000 --- a/lib/pages/account_page.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'package:digi_farmer/api/google_sign_in.dart'; -import 'package:digi_farmer/views/login_page.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_sign_in/google_sign_in.dart'; - -class AccountPage extends StatefulWidget { - final User? user; - - const AccountPage({super.key, this.user}); - - @override - State createState() => _AccountPageState(); -} - -class _AccountPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: const Color.fromARGB(255, 231, 248, 212), - // extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(0), - child: AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - systemOverlayStyle: const SystemUiOverlayStyle( - // statusBarColor: Color.fromARGB(255, 146, 173, 118), - ), - ), - ), - - body: getBody(), - ); - } - - Widget getBody() { - var userName = widget.user?.displayName; - var userPicUrl = widget.user?.photoURL; - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ClipRRect( - borderRadius: BorderRadius.circular(100), - child: CircleAvatar( - radius: 40, - backgroundImage: NetworkImage( - userPicUrl.toString(), - )), - ), - const SizedBox( - height: 30, - ), - Text( - 'Name: ${userName!}', - style: const TextStyle(fontSize: 18), - ), - Text( - 'Email: ${widget.user!.email}', - style: const TextStyle(fontSize: 18), - ), - const SizedBox( - height: 30, - ), - ElevatedButton( - onPressed: () async { - await GoogleSignInApi.logout(); - - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (context) => const LoginPage())); - }, - child: const Text("LOG OUT"), - ), - ], - ), - ); - } -} diff --git a/lib/pages/crops_page.dart b/lib/pages/crops_page.dart deleted file mode 100644 index a1491c2..0000000 --- a/lib/pages/crops_page.dart +++ /dev/null @@ -1,165 +0,0 @@ -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/views/features_page.dart'; -import 'package:digi_farmer/widget/category_card.dart'; -import 'package:digi_farmer/widget/clipper.dart'; -import 'package:digi_farmer/widget/custom_heading.dart'; -import 'package:digi_farmer/widget/custom_search_feild.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_sign_in/google_sign_in.dart'; - -class CropsPage extends StatefulWidget { - final User? user; - - const CropsPage({super.key, this.user}); - - @override - State createState() => _CropsPageState(); -} - -class _CropsPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: const Color.fromARGB(255, 229, 243, 213), - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(0), - child: AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarColor: Color.fromARGB(255, 146, 173, 118), - ), - ), - ), - body: getBody(), - ); - } - - Widget getBody() { - var size = MediaQuery.of(context).size; - return SingleChildScrollView( - padding: const EdgeInsets.only(bottom: spacer), - child: Column( - children: [ - Stack( - alignment: Alignment.topCenter, - children: [ - ClipPath( - clipper: BottomClipper(), - child: Container( - width: size.width, - height: 300.0, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - )), - ), - Padding( - padding: - const EdgeInsets.only(left: appPadding, right: appPadding), - child: Column( - children: [ - const SizedBox(height: spacer + spacer * 0.5), - //heading - const Text( - "Welcome to", - style: TextStyle( - color: Color.fromARGB(255, 167, 221, 113), - fontSize: 18, - fontWeight: FontWeight.bold), - ), - const Text( - "Crops Category", - style: TextStyle( - color: Color.fromARGB(255, 161, 207, 115), - fontSize: 36, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: spacer), - - // search - const CustomSearchField( - hintField: 'Try "Rice"', - backgroundColor: Color.fromARGB(255, 203, 233, 176), - ), - // const SizedBox(height: spacer - 35), - Column( - children: [ - GridView.count( - shrinkWrap: true, - crossAxisCount: 2, - childAspectRatio: .84, - crossAxisSpacing: 20, - mainAxisSpacing: 20, - children: [ - CategoryCard( - title: "Rice", - imgSrc: "assets/images/rice.png", - press: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const FeaturesPage( - title: "Rice", - imgSrc: "assets/images/rice.png"), - )); - }, - ), - CategoryCard( - title: "Wheat", - imgSrc: "assets/images/wheat(1).png", - press: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const FeaturesPage( - title: "Wheat", - imgSrc: "assets/images/wheat(1).png"), - )); - }, - ), - CategoryCard( - title: "Cotton", - imgSrc: "assets/images/cotton.png", - press: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const FeaturesPage( - title: "Cotton", - imgSrc: "assets/images/cotton.png"), - )); - }, - ), - CategoryCard( - title: "Sugarcane", - fSize: 18, - imgSrc: "assets/images/sugar-cane.png", - press: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const FeaturesPage( - title: "Sugarcane", - imgSrc: - "assets/images/sugar-cane.png"), - )); - }, - ), - ], - ), - ], - ), - ], - ), - ), - ], - ) - ], - ), - ); - } -} diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart deleted file mode 100644 index 409d8a4..0000000 --- a/lib/pages/home_page.dart +++ /dev/null @@ -1,192 +0,0 @@ -import 'package:digi_farmer/datas/category_json.dart'; -import 'package:digi_farmer/pages/crops_page.dart'; -import 'package:digi_farmer/pages/logged_in_home.dart'; -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/widget/clipper.dart'; -import 'package:digi_farmer/widget/custom_category_card.dart'; -import 'package:digi_farmer/widget/custom_heading.dart'; -import 'package:digi_farmer/widget/custom_search_feild.dart'; -import 'package:digi_farmer/widget/custom_title.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_sign_in/google_sign_in.dart'; -import 'package:googleapis/cloudasset/v1.dart'; - -import '../views/login_page.dart'; -import '../views/root_app.dart'; - -class HomePage extends StatefulWidget { - // final User? user; - final user = FirebaseAuth.instance.currentUser; - - HomePage({super.key}); - - // const HomePage({super.key, this.user}); - - @override - State createState() => _HomePageState(); -} - -class _HomePageState extends State { - @override - void dispose() { - SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( - // statusBarColor: , - )); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: const Color.fromARGB(255, 229, 243, 213), - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(0), - child: AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarColor: Color.fromARGB(255, 146, 173, 118), - ), - ), - ), - body: StreamBuilder( - stream: FirebaseAuth.instance.authStateChanges(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return (Center(child: Text('Something Went Wrong'))); - } else if (snapshot.hasData) { - return RootApp(); - } else { - return LoginPage(); - } - }), - ); - } - - Widget getBody() { - var size = MediaQuery.of(context).size; - var userName = widget.user?.displayName!.split(' '); - var userPicUrl = widget.user?.photoURL; - return SingleChildScrollView( - padding: const EdgeInsets.only(bottom: spacer), - child: Column( - children: [ - Stack( - alignment: Alignment.topCenter, - children: [ - ClipPath( - clipper: BottomClipper(), - child: Container( - width: size.width, - height: 300.0, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - )), - ), - Padding( - padding: - const EdgeInsets.only(left: appPadding, right: appPadding), - child: Column( - children: [ - const SizedBox(height: spacer + 24), - - //heading - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - CustomHeading( - // title: 'Hi, ${userName[0]}!', - title: - 'Hi,${userName != null ? userName[0] + " !" : " Shubham"}', - subTitle: 'Let\'s start prediction.', - - color: Colors.white, - ), - Container( - height: 85, - width: 85, - child: ClipRRect( - borderRadius: BorderRadius.circular(100), - child: CircleAvatar( - backgroundColor: Colors.white, - radius: 60, - // maxRadius: 80, - foregroundImage: userPicUrl.toString() == null - ? NetworkImage(userPicUrl.toString()) - : AssetImage("assets/images/profile-pic.png") - as ImageProvider, - ), - ), - ), - ], - ), - const SizedBox(height: spacer), - - // search - const CustomSearchField( - hintField: 'Try "Disease Detection"', - backgroundColor: Color.fromARGB(255, 203, 233, 176), - ), - const SizedBox(height: spacer - 30.0), - ], - ), - ), - ], - ), - const SizedBox( - height: smallSpacer, - ), - //feature courses - const Padding( - padding: EdgeInsets.only(left: appPadding, right: appPadding), - child: CustomTitle( - title: 'Feature Functions', - arg: { - 'title': 'Feature Functions!', - 'list': CoursesJson, - }, - ), - ), - const SizedBox(height: smallSpacer), - SingleChildScrollView( - scrollDirection: Axis.horizontal, - padding: const EdgeInsets.only( - left: appPadding, - right: appPadding - 10.0, - ), - child: Wrap( - children: List.generate(CoursesJson.length, (index) { - var data = CoursesJson[index]; - - return Padding( - padding: const EdgeInsets.only(right: 15.0, bottom: 20.0), - child: GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CropsPage(), - )); - }, - child: CustomCourseCardExpand( - thumbNail: data['image'], - title: data['title'], - ), - ), - ); - }), - ), - ), - const SizedBox(height: spacer - 20.0), - - const SizedBox(height: spacer - 10.0), - ], - ), - ); - } -} diff --git a/lib/pages/logged_in_home.dart b/lib/pages/logged_in_home.dart deleted file mode 100644 index b77d325..0000000 --- a/lib/pages/logged_in_home.dart +++ /dev/null @@ -1,185 +0,0 @@ -import 'package:digi_farmer/util/authentication.dart'; -import 'package:digi_farmer/views/login_page.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:google_sign_in/google_sign_in.dart'; - -import '../datas/category_json.dart'; -import '../theme/padding.dart'; -import '../widget/clipper.dart'; -import '../widget/custom_category_card.dart'; -import '../widget/custom_heading.dart'; -import '../widget/custom_search_feild.dart'; -import '../widget/custom_title.dart'; -import 'crops_page.dart'; - -class LoggedInWidget extends StatefulWidget { - final user = FirebaseAuth.instance.currentUser; - - @override - State createState() => _LoggedInWidget(); -} - -class _LoggedInWidget extends State { - @override - void dispose() { - SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( - // statusBarColor: , - )); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - print(widget.user); - print(widget.user?.displayName); - - var size = MediaQuery.of(context).size; - var userName = widget.user?.displayName?.split(' '); - var userPicUrl = widget.user?.photoURL; - return SingleChildScrollView( - padding: const EdgeInsets.only(bottom: spacer), - child: Column( - children: [ - Stack( - alignment: Alignment.topCenter, - children: [ - ClipPath( - clipper: BottomClipper(), - child: Container( - width: size.width, - height: 300.0, - decoration: const BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - )), - ), - Padding( - padding: - const EdgeInsets.only(left: appPadding, right: appPadding), - child: Column( - children: [ - const SizedBox(height: spacer + 24), - - //heading - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - children: [ - CustomHeading( - // title: 'Hi, ${userName[0]}!', - title: - 'Hi,${userName != null ? userName[0] + " !" : " Shubham"}', - subTitle: 'Let\'s start prediction.', - - color: Colors.white, - ), - // ElevatedButton.icon( - // onPressed: _logOut, - // icon: const Icon(Icons.logout), - // label: const Text("Logout"), - // ), - ], - ), - Container( - height: 85, - width: 85, - child: ClipRRect( - borderRadius: BorderRadius.circular(100), - child: CircleAvatar( - backgroundColor: Colors.white, - radius: 60, - // maxRadius: 80, - foregroundImage: userPicUrl.toString() == null - ? NetworkImage(userPicUrl.toString()) - : const AssetImage( - "assets/images/profile-pic.png") - as ImageProvider, - ), - ), - ), - ], - ), - const SizedBox(height: spacer), - // search - const CustomSearchField( - hintField: 'Try "Disease Detection"', - backgroundColor: Color.fromARGB(255, 203, 233, 176), - ), - const SizedBox(height: spacer - 30.0), - ], - ), - ), - ], - ), - const SizedBox( - height: smallSpacer, - ), - //feature courses - const Padding( - padding: EdgeInsets.only(left: appPadding, right: appPadding), - child: CustomTitle( - title: 'Feature Functions', - arg: { - 'title': 'Feature Functions!', - 'list': CoursesJson, - }, - ), - ), - const SizedBox(height: smallSpacer), - SingleChildScrollView( - scrollDirection: Axis.horizontal, - padding: const EdgeInsets.only( - left: appPadding, - right: appPadding - 10.0, - ), - child: Wrap( - children: List.generate(CoursesJson.length, (index) { - var data = CoursesJson[index]; - - return Padding( - padding: const EdgeInsets.only(right: 15.0, bottom: 20.0), - child: GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const CropsPage(), - )); - }, - child: CustomCourseCardExpand( - thumbNail: data['image'], - title: data['title'], - ), - ), - ); - }), - ), - ), - const SizedBox(height: spacer - 20.0), - ], - ), - ); - } - - Future _logOut() async { - // final GoogleSignIn googleSignIn = GoogleSignIn(); - - await FirebaseAuth.instance.signOut(); - - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => const LoginPage(), - )); - } - - showSnackBar(String content, BuildContext context) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(content), - ), - ); - } -} diff --git a/lib/pages/tips_page.dart b/lib/pages/tips_page.dart deleted file mode 100644 index 07719a9..0000000 --- a/lib/pages/tips_page.dart +++ /dev/null @@ -1,131 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:google_fonts/google_fonts.dart'; - -class TipsPage extends StatefulWidget { - @override - _TipsPageState createState() => _TipsPageState(); -} - -class _TipsPageState extends State { - List infos = [ - Info( - title: 'Irrigation Water Supply Augmentation and Management', - subtitle: - 'By using sprinkler irrigation systems you can increase crop yields up to 50%. If the crops get too much water, the roots can rot, and the crops will not get enough oxygen from the soil. So, the surplus of water on fields can equally affect the overall growth and development of crops directly and also its yield and quality.'), - Info( - title: 'Improve Soil and then Increase Crop Yield', - subtitle: - 'Find the cause of decreasing crop yield by sait resting is the first step to finding the source of the issue whether it is a disease, a lack of nutrients, or unproductive soil Then the soil can be treated with the suitable organic product needed to solve the problem, without the use of synthetic chemicals which can harm the environment (and provide only a temporary solution) Biotechnology has been shown to increase crop yields it provides an alternative to chemical pesticides, helping eliminate millions of pounds of pesticide applications worldwide.'), - Info( - title: - 'Varieties Selection or Quality of Seeds for Crop Yield Improvement', - subtitle: - 'Improved heat-tolerant varieties allow the plant to maintain crop yields at higher temperatures. Heat tolerant varieties could increase crop yields from up to 23 %. Agricultural productivity mainly depends on the quality of seeds with which farmers sow their fields. By choosing certified seeds cost higher than those that do not have certification, but the result will be worth it because the proper quality of seeds is the main factor that affects crop yield. Planting high-quality seeds are the method to increase crop yield.'), - Info( - title: 'Conservation tillage for Crop Yield Improvement', - subtitle: - 'By applying conservation tillage practices, you save time, fuel and increases crop yield. Adverse effects of soil compaction on crop production recognized for many years.'), - Info( - title: 'Monitoring Crops Growth', - subtitle: - 'From the early stage of crop development through budding and up to harvesting, it is important to monitor plant health to timely detect any problem that can arise on given farmland and that can affect the yield of crops.Crop monitoring provides data on daily temperatures and calculates their total sum. Based on this data, the software is capable of detecting growth stages for several types of plants and represents their correlations with other data so that the farmers could make well weighted decisions.'), - Info( - title: 'Practice Seasonal Soil Rotation for Crop Yield Improvement', - subtitle: 'Practice Seasonal Soil Rotation for Crop Yield Improvement'), - Info( - title: 'Work With the Weather', - subtitle: - 'Much of farming is out of your control. Extreme weather, the daily average temperature level. and the life cycle of plants and insects are not under your authority. The weather instead of guessing what will come next is powerful for agribusiness. And technology is the most straightforward method to get there.'), - Info( - title: 'Plant High Quality Seed', - subtitle: - 'In India, farming is not a low-cost business, so it makes sense that owners and farm managers are looking to limit their expenditures. But when hoping to increase crop yield, avoid the mistake of cutting costs on seeds Low quality seeds are giving you an unfortunate result it is better to streamline farming operations in other ways rather than choosing inferior seeds'), - Info( - title: 'Plant Early, Plant Effectively', - subtitle: - 'Choosing the right time to plant is the most important part of planting. The best strategy to use to increase yields is your soil is reacty, start planting Early planting can result in increased crop yields.Select the right time to plant this is a critical process of planting if soil is ready, do the planting several tests can be performed to test how ready your solls.'), - Info( - title: 'Test Your Soil', - subtitle: - 'Testing the soil must always be on top of your list. Examine all the properties like potassium phosphorus, and fertilization levels'), - Info( - title: 'Practice Seasonal Soil Rotation', - subtitle: - 'When you are planting season-by-season, it is very important to understand how planting recurring crops can affect your overall yield. If you do not have access to either, you can need to consider planting alternative crops in alternating years. Planting an alternating crop mainly helps to diversify the demands on your soil. Try and alternate crops in different seasons, or also you practice med farming.'), - Info( - title: 'Know the Yield Potential', - subtitle: - 'It is not enough to plant seeds and hope for the best, you should understand your fields growth potential Understanding the crop types you are using is key when assessing yield potential'), - ]; - Widget infoTemplate(info) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), - color: Color.fromARGB(255, 114, 172, 56), - ), - child: ExpansionTile( - title: Text( - info.title, - style: GoogleFonts.poppins( - fontSize: 20.0, - //fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - children: [ - ListTile( - title: Text( - info.subtitle, - style: GoogleFonts.poppins(color: Colors.black54), - ), - ) - ], - ), - ), - ); - } - - @override - Widget build(BuildContext context) { - return Align( - alignment: Alignment.topCenter, - child: Container( - height: MediaQuery.of(context).size.height, - width: MediaQuery.of(context).size.width, - color: Color.fromARGB(255, 155, 194, 116), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 40, - ), - Padding( - padding: const EdgeInsets.all(10.0), - child: Text( - 'Tips', - style: GoogleFonts.poppins( - fontSize: 36, - color: Colors.black, - fontWeight: FontWeight.w500), - ), - ), - Column( - children: infos.map((info) => infoTemplate(info)).toList(), - ), - ], - ), - ), - ), - ); - } -} - -class Info { - String title; - String subtitle; - - Info({required this.title, required this.subtitle}); -} diff --git a/lib/pages/weather_page.dart b/lib/pages/weather_page.dart deleted file mode 100644 index 2028a74..0000000 --- a/lib/pages/weather_page.dart +++ /dev/null @@ -1,331 +0,0 @@ -import 'dart:convert'; - -import 'package:digi_farmer/controller/global_controller.dart'; -import 'package:flutter/material.dart'; -import 'package:geocoding/geocoding.dart'; -import 'package:geolocator/geolocator.dart'; -import 'package:get/get.dart' as GET; -import 'package:google_fonts/google_fonts.dart'; -import 'package:google_sign_in/google_sign_in.dart'; -import 'package:http/http.dart'; -import 'package:intl/intl.dart'; - -class current { - var temp; - var pressure; - var humidity; - var weather; - var id; - var desc; - current(this.temp, this.desc, this.weather, this.humidity, this.id, - this.pressure); -} - -class forecast { - var dt; - var max; - var humidity; - var min; - var weather; - var desc; - forecast(this.dt, this.humidity, this.max, this.min, this.weather, this.desc); -} - -class WeatherPage extends StatefulWidget { - final GoogleSignInAccount? user; - - const WeatherPage({super.key, this.user}); - - @override - State createState() => _WeatherPageState(); -} - -class _WeatherPageState extends State { - String city = ""; //city name - String date = (DateFormat.yMMMd().format(DateTime.now())).toString(); - - final GlobalController globalController = - GET.Get.put(GlobalController(), permanent: true); - - List weather = []; - - int hour = DateTime.now().hour; - - @override - Widget build(BuildContext context) { - return Scaffold( - body: FutureBuilder>( - future: getweather(), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator( - color: Colors.green, - )); - } else { - //print(snapshot.data); - return Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: getcolor()), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 20, - ), - Padding( - padding: const EdgeInsets.all(25), - child: Text( - "Weather", - style: GoogleFonts.poppins( - fontSize: 36, - color: Colors.white, - fontWeight: FontWeight.w500), - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - SizedBox( - height: 150, - width: 150, - child: Image.asset( - getWeatherIcon(weather[0].id), - fit: BoxFit.fill, - )), - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "${(weather[0].temp - 273.15).toStringAsFixed(1)}°", - style: GoogleFonts.poppins( - fontSize: 54, color: Colors.white), - ), - Text( - weather[0].weather, - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 20), - ), - ], - ), - ], - ), - const SizedBox( - height: 30, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Humidity', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 20, - fontWeight: FontWeight.w600), - ), - Text( - "${(weather[0].humidity).toStringAsFixed(1)}%", - style: GoogleFonts.poppins( - fontSize: 44, color: Colors.white), - ), - ], - ), - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Pressure', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 20, - fontWeight: FontWeight.w600), - ), - Text( - "${(weather[0].pressure)}", - style: GoogleFonts.poppins( - fontSize: 44, color: Colors.white), - ), - ], - ), - ], - ), - const SizedBox( - height: 10, - ), - Padding( - padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), - child: Text( - 'Forecast :', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w600), - )), - Expanded( - child: GridView( - shrinkWrap: true, - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - childAspectRatio: 1.5, - crossAxisCount: 2, - crossAxisSpacing: 10, - mainAxisSpacing: 5.0), - children: snapshot.data!.map((document) { - return Column( - // mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - DateFormat('EEEE').format( - DateTime.fromMillisecondsSinceEpoch( - document.dt * 1000)), - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w400), - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - children: [ - SizedBox( - height: 70, - child: Image.asset( - getWeatherIcon(document.desc)), - ), - Column( - children: [ - Text( - 'Max: ${(document.max - 273.15).toStringAsFixed(1)}°', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w600), - ), - Text( - 'Max: ${(document.min - 273.15).toStringAsFixed(1)}°', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w600), - ), - ], - ), - ], - ), - ], - ); - }).toList()), - ), - ], - ), - ); - } - }), - ); - } - - getAddress(lat, lon) async { - List placemark = await placemarkFromCoordinates(lat, lon); - Placemark place = placemark[0]; - - setState(() { - city = place.locality!.toString(); - }); - } - - List getcolor() { - return [ - const Color.fromARGB(255, 149, 241, 149), - const Color.fromARGB(255, 75, 117, 32), - ]; //const Color(0xFF83eaf1), const Color(0xFF3eadcf) - } - - Future> getweather() async { - Position p = await _determinePosition(); - Response r = await get(Uri.parse( - "https://api.openweathermap.org/data/2.5/onecall?lat=${p.latitude}&lon=${p.longitude}&exclude=hourly,minutely&appid=8cb6386fe572b5b0befe4eba9bfa7c2f")); - //print(r.body); - Map x = jsonDecode(r.body); - //print(x['current']); - weather.add(current( - x['current']['temp'], - x['current']['weather'][0]['description'], - x['current']['weather'][0]['main'], - x['current']['humidity'], - x['current']['weather'][0]['id'], - x['current']['pressure'])); - var y = x['daily']; - print(y); - - List z = []; - for (var i = 1; i < 5; i++) { - //print(y[i]['weather'][0]['id']); - z.add(forecast( - y[i]['dt'], - y[i]['humidity'], - y[i]['temp']['max'], - y[i]['temp']['min'], - y[i]['weather'][0]['main'], - y[i]['weather'][0]['id'])); - } - - return z; - } - - String getWeatherIcon(int condition) { - if (condition < 300) { - return 'assets/ic_storm_weather.png'; - } else if (condition < 400) { - return 'assets/ic_rainy_weather.png'; - } else if (condition < 600) { - return 'assets/ic_rainy_weather.png'; - } else if (condition < 700) { - return 'assets/ic_snow_weather.png'; - } else if (condition < 800) { - return 'assets/ic_mostly_cloudy.png'; - } else if (condition == 800) { - return 'assets/ic_clear_day.png'; - } else if (condition <= 804) { - return 'assets/ic_cloudy_weather.png'; - } else { - return 'assets/ic_unknown.png'; - } - } - - @override - void initState() { - getAddress( - globalController.getLattitude().value, - globalController.getLongitude().value, - ); - super.initState(); - } - - Future _determinePosition() async { - bool serviceEnabled; - LocationPermission permission; - serviceEnabled = await Geolocator.isLocationServiceEnabled(); - if (!serviceEnabled) { - return Future.error('Location services are disabled.'); - } - permission = await Geolocator.checkPermission(); - if (permission == LocationPermission.denied) { - permission = await Geolocator.requestPermission(); - if (permission == LocationPermission.denied) { - return Future.error('Location permissions are denied'); - } - } - if (permission == LocationPermission.deniedForever) { - return Future.error( - 'Location permissions are permanently denied, we cannot request permissions.'); - } - return await Geolocator.getCurrentPosition(); - } -} diff --git a/lib/theme/padding.dart b/lib/theme/padding.dart deleted file mode 100644 index 3ba2c09..0000000 --- a/lib/theme/padding.dart +++ /dev/null @@ -1,4 +0,0 @@ -const double appPadding = 25.0; -const double spacer = 50.0; -const double smallSpacer = 30.0; -const double miniSpacer = 10.0; diff --git a/lib/util/auth_methods.dart b/lib/util/auth_methods.dart deleted file mode 100644 index ec554c0..0000000 --- a/lib/util/auth_methods.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:io'; - -import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:firebase_auth/firebase_auth.dart'; - -import '../model/user_model.dart'; - -class AuthMethods { - final FirebaseAuth _auth = FirebaseAuth.instance; - final FirebaseFirestore _firestore = FirebaseFirestore.instance; - - Future signUpUser({ - required String? name, - required String? email, - required String? password, - required String? username, - required int phone, - required String? profileImageUrl, - }) async { - String result = 'Some error occurred'; - try { - if (email!.isNotEmpty || name!.isNotEmpty || password!.isNotEmpty) { - UserCredential user = await _auth.createUserWithEmailAndPassword( - email: email, password: password!); - print(user.user!.uid); - - UserModel userModel = UserModel( - email: email, - name: name!, - uid: user.user!.uid, - username: username!, - phone: phone, - profileImageUrl: profileImageUrl!, - // followers: [], - // following: [], - ); - - await _firestore.collection('users').doc(user.user!.uid).set( - userModel.toJson(), - ); - result = "You're successfully registered"; - } - } catch (err) { - result = err.toString(); - } - return result; - } - - Future logInUser({ - required String email, - required String password, - }) async { - String result = 'Some error occurred'; - try { - if (email.isNotEmpty || password.isNotEmpty) { - await _auth.signInWithEmailAndPassword( - email: email, password: password); - result = 'success'; - } - } catch (err) { - result = err.toString(); - } - return result; - } -} diff --git a/lib/util/authentication.dart b/lib/util/authentication.dart deleted file mode 100644 index ec2d691..0000000 --- a/lib/util/authentication.dart +++ /dev/null @@ -1,125 +0,0 @@ -import 'package:digi_farmer/views/root_app.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; -import 'package:google_sign_in/google_sign_in.dart'; -import 'package:flutter/foundation.dart' show kIsWeb; - -class Authentication { - static SnackBar customSnackBar({required String content}) { - return SnackBar( - backgroundColor: Colors.black, - content: Text( - content, - style: TextStyle(color: Colors.redAccent, letterSpacing: 0.5), - ), - ); - } - - static Future initializeFirebase({ - required BuildContext context, - }) async { - FirebaseApp firebaseApp = await Firebase.initializeApp(); - - User? user = FirebaseAuth.instance.currentUser; - - if (user == null) { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => RootApp( - user: user, - ), - ), - ); - } - - return firebaseApp; - } - - static Future signInWithGoogle({required BuildContext context}) async { - FirebaseAuth auth = FirebaseAuth.instance; - User? user; - - if (kIsWeb) { - GoogleAuthProvider authProvider = GoogleAuthProvider(); - - try { - final UserCredential userCredential = - await auth.signInWithPopup(authProvider); - - user = userCredential.user; - } catch (e) { - print(e); - } - } else { - final GoogleSignIn googleSignIn = GoogleSignIn(); - - final GoogleSignInAccount? googleSignInAccount = - await googleSignIn.signIn(); - - if (googleSignInAccount != null) { - final GoogleSignInAuthentication googleSignInAuthentication = - await googleSignInAccount.authentication; - - final AuthCredential credential = GoogleAuthProvider.credential( - accessToken: googleSignInAuthentication.accessToken, - idToken: googleSignInAuthentication.idToken, - ); - - try { - final UserCredential userCredential = - await auth.signInWithCredential(credential); - - user = userCredential.user; - } on FirebaseAuthException catch (e) { - if (e.code == 'account-exists-with-different-credential') { - ScaffoldMessenger.of(context).showSnackBar( - Authentication.customSnackBar( - content: - 'The account already exists with a different credential', - ), - ); - } else if (e.code == 'invalid-credential') { - ScaffoldMessenger.of(context).showSnackBar( - Authentication.customSnackBar( - content: - 'Error occurred while accessing credentials. Try again.', - ), - ); - } - } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - Authentication.customSnackBar( - content: 'Error occurred using Google Sign In. Try again.', - ), - ); - } - } - } - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => RootApp( - user: user, - ), - ), - ); - return user; - } - - static Future signOut({required BuildContext context}) async { - final GoogleSignIn googleSignIn = GoogleSignIn(); - - try { - if (!kIsWeb) { - await googleSignIn.signOut(); - } - await FirebaseAuth.instance.signOut(); - } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - Authentication.customSnackBar( - content: 'Error signing out. Try again.', - ), - ); - } - } -} diff --git a/lib/util/google_sign_in.dart b/lib/util/google_sign_in.dart deleted file mode 100644 index 84e3759..0000000 --- a/lib/util/google_sign_in.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; -import 'package:google_sign_in/google_sign_in.dart'; - -class GoogleSignInProvider extends ChangeNotifier { - final googleSignIn = GoogleSignIn(); - - GoogleSignInAccount? _user; - - GoogleSignInAccount get user => _user!; - - Future googleLogin() async { - final googleUser = await googleSignIn.signIn(); - if (googleUser == null) return; - _user = googleUser; - - final googleAuth = await googleUser.authentication; - - final credential = GoogleAuthProvider.credential( - accessToken: googleAuth.accessToken, - idToken: googleAuth.idToken, - ); - - await FirebaseAuth.instance.signInWithCredential(credential); - } -} diff --git a/lib/util/model_locations.dart b/lib/util/model_locations.dart deleted file mode 100644 index d8a9afa..0000000 --- a/lib/util/model_locations.dart +++ /dev/null @@ -1,17 +0,0 @@ -class MyModels { - static String riceDiseaseModel = "assets/model/disease/rice.tflite"; - static String riceDiseasetxt = "assets/model/disease/ricelabels.txt"; - - static String wheatDiseaseModel = "assets/model/disease/wheat.tflite"; - static String wheatDiseasetxt = "assets/model/disease/wheatlabels.txt"; - - static String cottonDiseaseModel = "assets/model/disease/cotton.tflite"; - static String cottonDiseasetxt = "assets/model/disease/cottonlabels.txt"; - - static String sugarcaneDiseaseModel = "assets/model/disease/sugarcane.tflite"; - static String sugarcaneDiseasetxt = - "assets/model/disease/sugarcanelabels.txt"; - - static String weedDetectionModel = "assets/model/weed/weed.tflite"; - static String weedDetectiontxt = "assets/model/weed/weedlabels.txt"; -} diff --git a/lib/util/routes.dart b/lib/util/routes.dart deleted file mode 100644 index 19f086c..0000000 --- a/lib/util/routes.dart +++ /dev/null @@ -1,7 +0,0 @@ -class MyRoutes { - static String welcomeRoute = "/welcome"; - static String loginRoute = "/login"; - static String homeRoute = "/home"; - static String homeDetailsRoute = "/detail"; - static String cartRoute = "/cart"; -} diff --git a/lib/views/features_page.dart b/lib/views/features_page.dart deleted file mode 100644 index c594557..0000000 --- a/lib/views/features_page.dart +++ /dev/null @@ -1,169 +0,0 @@ -import 'package:digi_farmer/detection_pages/crop_quality.dart'; -import 'package:digi_farmer/detection_pages/disease_detection.dart'; -import 'package:digi_farmer/detection_pages/weed_detection.dart'; -import 'package:digi_farmer/detection_pages/yeild_prediction.dart'; -import 'package:digi_farmer/pages/account_page.dart'; -import 'package:digi_farmer/pages/home_page.dart'; -import 'package:digi_farmer/theme/padding.dart'; -import 'package:digi_farmer/widget/clipper.dart'; -import 'package:digi_farmer/widget/features_card.dart'; -import 'package:flutter/material.dart'; - -class FeaturesPage extends StatefulWidget { - final String title; - final String imgSrc; - - const FeaturesPage({super.key, required this.title, required this.imgSrc}); - - @override - State createState() => _FeaturesPageState(); -} - -class _FeaturesPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Color.fromARGB(255, 229, 243, 213), - appBar: AppBar( - title: Text( - widget.title.toString() + " Features", - ), - elevation: 0.0, - backgroundColor: Color.fromARGB(255, 75, 117, 32), - foregroundColor: Color.fromARGB(255, 166, 231, 101), - // centerTitle: true, - // ignore: prefer_const_literals_to_create_immutables - ), - body: getBody(), - ); - } - - Widget getBody() { - var size = MediaQuery.of(context).size; - return SingleChildScrollView( - padding: const EdgeInsets.only(bottom: spacer), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Stack( - children: [ - ClipPath( - clipper: BottomClipper(), - child: Container( - width: size.width, - height: 150.0, - decoration: BoxDecoration( - color: Color.fromARGB(255, 75, 117, 32), - )), - ), - Center( - child: Container( - width: size.width * 0.3, - height: size.height * 0.2, - // color: Color.fromARGB(255, 224, 224, 224).withOpacity(0.5), - child: Hero( - tag: widget.imgSrc.toString(), - child: Image.asset(widget.imgSrc), - ), - ), - ), - ], - ), - const SizedBox( - height: spacer, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CropQuality( - title: widget.title, - category: widget.title, - ), - )); - }, - child: FeaturesCard( - icon: Icon( - Icons.image_search, - size: 38, - color: Color.fromARGB(255, 161, 207, 115), - ), - title: " Crop Quality", - ), - ), - SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => YieldPrediction( - title: widget.title, - category: widget.title, - ), - )); - }, - child: FeaturesCard( - icon: Icon( - Icons.online_prediction, - size: 38, - color: Color.fromARGB(255, 161, 207, 115), - ), - title: " Yeild Prediction", - ), - ), - SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => DiseaseDetection( - title: widget.title, - category: widget.title, - ), - )); - }, - child: FeaturesCard( - icon: Icon( - Icons.medication, - size: 38, - color: Color.fromARGB(255, 161, 207, 115), - ), - title: " Disease Detection", - ), - ), - SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => WeedDetection( - title: widget.title, - category: widget.title, - ), - )); - }, - child: FeaturesCard( - icon: Icon( - Icons.search_sharp, - size: 38, - color: Color.fromARGB(255, 161, 207, 115), - ), - title: " Weed Detection", - ), - ), - ], - ), - ); - } -} diff --git a/lib/views/login_page.dart b/lib/views/login_page.dart deleted file mode 100644 index 0ee6f2a..0000000 --- a/lib/views/login_page.dart +++ /dev/null @@ -1,418 +0,0 @@ -import 'dart:io'; - -import 'package:digi_farmer/api/google_sign_in.dart'; -import 'package:digi_farmer/pages/home_page.dart'; -import 'package:digi_farmer/util/auth_methods.dart'; -import 'package:digi_farmer/util/authentication.dart'; -import 'package:digi_farmer/views/register_page.dart'; -import 'package:digi_farmer/views/root_app.dart'; -import 'package:digi_farmer/widget/custom_google_sign_in_btn.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_signin_button/flutter_signin_button.dart'; - -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:provider/provider.dart'; - -import '../util/google_sign_in.dart'; - -class LoginPage extends StatefulWidget { - const LoginPage({super.key}); - - @override - State createState() => _LoginPageState(); -} - -class CustomColors { - static final Color firebaseNavy = Color(0xFF2C384A); - static final Color firebaseOrange = Color(0xFFF57C00); - static final Color firebaseAmber = Color(0xFFFFA000); - static final Color firebaseYellow = Color(0xFFFFCA28); - static final Color firebaseGrey = Color(0xFFECEFF1); - static final Color googleBackground = Color(0xFF4285F4); -} - -class _LoginPageState extends State - with SingleTickerProviderStateMixin { - late AnimationController animationController; - Duration animationDuration = const Duration(milliseconds: 250); - late Animation containerSize; - bool isLogin = false; - - bool passHide = true; - - final _formKey = GlobalKey(); - String? _name; - String? _email; - String? _password; - String? _userName; - bool _isLoading = false; - - final TextEditingController _emailIdController = new TextEditingController(); - final TextEditingController _passwordController = new TextEditingController(); - bool _isLoginLoading = false; - - @override - void dispose() { - animationController.dispose(); - super.dispose(); - } - - @override - void initState() { - // TODO: implement initState - super.initState(); - // SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); - - animationController = AnimationController( - vsync: this, - duration: animationDuration, - ); - } - - @override - Widget build(BuildContext context) { - double w = MediaQuery.of(context).size.width; - double h = MediaQuery.of(context).size.height; - - double viewInset = MediaQuery.of(context).viewInsets.bottom; - double defaultRegisterSize = h - (h * 0.1); - - containerSize = Tween(begin: h * 0.1, end: defaultRegisterSize) - .animate( - CurvedAnimation(parent: animationController, curve: Curves.linear)); - - return SafeArea( - child: Scaffold( - backgroundColor: const Color.fromARGB(255, 178, 212, 145), - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(0), - child: AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarColor: Color.fromARGB(255, 146, 173, 118), - ), - ), - ), - body: Stack( - children: [ - //Decoration - Positioned( - top: 100, - right: -50, - child: Container( - width: 100, - height: 100, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(50), - color: const Color.fromARGB(255, 133, 170, 96), - ), - ), - ), - Positioned( - top: -90, - left: -90, - child: Container( - width: 200, - height: 200, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(100), - color: const Color.fromARGB(255, 133, 170, 96), - ), - ), - ), - - //Login Form - Align( - alignment: Alignment.center, - child: SingleChildScrollView( - child: Column( - // crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox( - height: 50, - ), - const Text( - "Sign in to DigiFarmer and continue", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 32, - color: Color.fromARGB(255, 255, 255, 255), - ), - ), - const SizedBox( - height: 20, - ), - const Text( - "Enter your email and password \nbelow to continue to the DigiFarmer and let's start prediction.", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 18, - color: Color.fromARGB(255, 97, 131, 63), - ), - ), - const SizedBox( - height: 80, - ), - // Container( - // width: w * 0.6, - // height: h * 0.3, - // decoration: const BoxDecoration( - // image: DecorationImage( - // image: AssetImage( - // "assets/images/farmer-holding-tablet.png"), - // fit: BoxFit.cover, - // ), - // ), - // ), - Container( - margin: const EdgeInsets.symmetric(vertical: 10), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 5), - width: w * 0.9, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - controller: _emailIdController, - cursorColor: Color.fromARGB(255, 178, 212, 145), - decoration: InputDecoration( - icon: Icon(Icons.email, - color: Color.fromARGB(255, 178, 212, 145)), - hintText: "Email", - border: InputBorder.none, - ), - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 10), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 5), - width: w * 0.9, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - controller: _passwordController, - obscureText: passHide, - cursorColor: const Color.fromARGB(255, 178, 212, 145), - decoration: InputDecoration( - icon: const Icon(Icons.lock, - color: Color.fromARGB(255, 178, 212, 145)), - hintText: "Password", - border: InputBorder.none, - suffixIcon: IconButton( - onPressed: () { - setState(() { - //refresh UI - if (passHide) { - passHide = false; - } else { - passHide = true; - } - }); - }, - icon: Icon(passHide == true - ? Icons.remove_red_eye - : Icons.password), - color: const Color.fromARGB(255, 133, 170, 96)), - ), - ), - ), - const SizedBox( - height: 20, - ), - InkWell( - onTap: _logInUser, - borderRadius: BorderRadius.circular(30), - child: Container( - width: w * 0.7, - margin: EdgeInsets.only( - top: 0, - bottom: 15, - ), - height: 55, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: const Color.fromARGB(255, 133, 170, 96), - border: Border.all(width: .5, color: Colors.white), - ), - alignment: Alignment.center, - child: GestureDetector( - onTap: _logInUser, - child: const Text( - "LOGIN", - style: TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold), - ), - ), - ), - ), - ElevatedButton.icon( - style: ElevatedButton.styleFrom( - backgroundColor: Colors.white, - foregroundColor: Colors.black, - minimumSize: Size(150, 50), - ), - icon: - FaIcon(FontAwesomeIcons.google, color: Colors.red), - label: Text("Sign Up with Google"), - onPressed: () { - final provider = Provider.of( - context, - listen: false); - provider.googleLogin(); - }), - Container( - margin: EdgeInsets.symmetric(vertical: 10), - child: Text( - "-OR-", - style: TextStyle( - color: const Color.fromARGB(255, 133, 170, 96)), - ), - ), - const SizedBox( - height: 20, - ), - Container( - width: double.infinity, - height: containerSize.value, - decoration: const BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(100), - topRight: Radius.circular(100), - ), - color: Color.fromARGB(255, 200, 228, 176), - ), - alignment: Alignment.center, - child: GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => RegisterPage())); - }, - child: const Text( - "Don't have an account? Sign Up", - style: TextStyle( - color: Color.fromARGB(255, 97, 131, 63), - fontSize: 18), - ), - ), - ), - ], - ), - ), - ), - ], - ), - ), - ); - } - - Future signIn() async { - final user = await GoogleSignInApi.login(); - - if (user == null) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text("Sign In Failed"), - ), - ); - } else { - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => RootApp(user: null), - ), - ); - } - } - - Future skipToMain() async { - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const RootApp(), - ), - ); - } - - void _logInUser() async { - if (_emailIdController.text.isEmpty) { - _showEmptyDialog("Type something"); - } else if (_passwordController.text.isEmpty) { - _showEmptyDialog("Type something"); - } - setState(() { - _isLoading = true; - }); - String result = await AuthMethods().logInUser( - email: _emailIdController.text, - password: _passwordController.text, - ); - if (result == 'success') { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => RootApp(), - )); - showSnackBar(result, context); - } else { - showSnackBar(result, context); - } - setState(() { - _isLoading = false; - }); - } - - showSnackBar(String content, BuildContext context) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(content), - ), - ); - } - - _showEmptyDialog(String title) { - if (Platform.isAndroid) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) => AlertDialog( - content: Text("$title can't be empty"), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text("OK")) - ], - ), - ); - } else if (Platform.isIOS) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) => CupertinoAlertDialog( - content: Text("$title can't be empty"), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text("OK")) - ], - ), - ); - } - } -} diff --git a/lib/views/register_page.dart b/lib/views/register_page.dart deleted file mode 100644 index 178378c..0000000 --- a/lib/views/register_page.dart +++ /dev/null @@ -1,395 +0,0 @@ -import 'dart:io'; - -import 'package:digi_farmer/util/auth_methods.dart'; -import 'package:digi_farmer/views/login_page.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter/src/widgets/container.dart'; -import 'package:flutter/src/widgets/framework.dart'; -import 'package:image_picker/image_picker.dart'; -import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; - -class RegisterPage extends StatefulWidget { - const RegisterPage({Key? key}) : super(key: key); - - @override - State createState() => _RegisterPageState(); -} - -class _RegisterPageState extends State { - bool isLogin = false; - bool passHide = true; - - final _formKey = GlobalKey(); - String? _name; - String? _email; - String? _password; - String? _userName; - late int _phone; - bool _isLoading = false; - File? _profileImage; - bool _isUploading = false; - String? _profileImageUrl; - - @override - Widget build(BuildContext context) { - double w = MediaQuery.of(context).size.width; - double h = MediaQuery.of(context).size.height; - - return SafeArea( - child: Scaffold( - backgroundColor: const Color.fromARGB(255, 178, 212, 145), - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: const Size.fromHeight(0), - child: AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarColor: Color.fromARGB(255, 146, 173, 118), - ), - ), - ), - body: SingleChildScrollView( - child: Column( - children: [ - const Text( - "Welcome To Our App", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 28, - color: Color.fromARGB(255, 97, 131, 63), - ), - ), - const SizedBox( - height: 20, - ), - GestureDetector( - onTap: _pickProfilePicture, - child: CircleAvatar( - radius: 60, - backgroundColor: Colors.white, - backgroundImage: - _profileImage != null ? FileImage(_profileImage!) : null, - child: _profileImage == null - ? const Icon( - Icons.camera_alt, - size: 40, - color: Color.fromARGB(255, 178, 212, 145), - ) - : null, - ), - ), - const SizedBox( - height: 20, - ), - Form( - key: _formKey, - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 0), - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - cursorColor: Color.fromARGB(255, 26, 26, 26), - decoration: InputDecoration( - icon: Icon(Icons.face_outlined, - color: Color.fromARGB(255, 178, 212, 145)), - border: InputBorder.none, - labelText: "Name", - ), - validator: (input) => input!.trim().isEmpty - ? 'Please enter a valid name' - : null, - onSaved: (input) => _name = input!, - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 0), - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - cursorColor: Color.fromARGB(255, 178, 212, 145), - decoration: InputDecoration( - icon: Icon(Icons.account_box, - color: Color.fromARGB(255, 178, 212, 145)), - labelText: "Username", - border: InputBorder.none, - ), - validator: (input) => input!.trim().isEmpty - ? 'Please enter a valid username' - : null, - onSaved: (input) => _userName = input!, - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 0), - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - cursorColor: Color.fromARGB(255, 178, 212, 145), - keyboardType: TextInputType.phone, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly, - FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), - ], // Only numbers can be entered - - decoration: InputDecoration( - icon: Icon(Icons.account_box, - color: Color.fromARGB(255, 178, 212, 145)), - labelText: "Phone", - border: InputBorder.none, - ), - validator: (value) { - if (value!.isEmpty) { - return "Please Enter a Phone Number"; - } else if (!RegExp( - r'^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$') - .hasMatch(value)) { - return "Please Enter a Valid Phone Number"; - } - }, - - onChanged: (value) => _phone = int.parse(value), - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 0), - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - keyboardType: TextInputType.emailAddress, - cursorColor: Color.fromARGB(255, 178, 212, 145), - decoration: InputDecoration( - icon: Icon(Icons.email, - color: Color.fromARGB(255, 178, 212, 145)), - labelText: "Email", - border: InputBorder.none, - ), - validator: (input) => !input!.contains('@') - ? 'Please enter a valid email' - : null, - onSaved: (input) => _email = input!, - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - padding: const EdgeInsets.symmetric( - horizontal: 20, vertical: 0), - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.white, - ), - child: TextFormField( - obscureText: passHide, - cursorColor: const Color.fromARGB(255, 178, 212, 145), - decoration: InputDecoration( - icon: const Icon(Icons.lock, - color: Color.fromARGB(255, 178, 212, 145)), - labelText: "Password", - border: InputBorder.none, - suffixIcon: IconButton( - onPressed: () { - //add Icon button at end of TextFormField - setState(() { - //refresh UI - if (passHide) { - passHide = false; - } else { - passHide = true; - } - }); - }, - icon: Icon(passHide == true - ? Icons.remove_red_eye - : Icons.password), - color: const Color.fromARGB(255, 133, 170, 96)), - ), - validator: (input) => input!.length < 6 - ? 'Must be at least 6 characters' - : null, - onSaved: (input) => _password = input!, - ), - ), - const SizedBox( - height: 20, - ), - ], - ), - ), - InkWell( - onTap: () => _signUp(), - borderRadius: BorderRadius.circular(30), - child: Container( - width: w * 0.8, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: const Color.fromARGB(255, 133, 170, 96), - border: Border.all(width: .5, color: Colors.white), - ), - padding: const EdgeInsets.symmetric(vertical: 20), - alignment: Alignment.center, - child: const Text( - "SIGN UP", - style: TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold), - ), - ), - ), - ], - ), - ), - ), - ); - } - - void _pickProfilePicture() async { - final picker = ImagePicker(); - final pickedImage = await picker.pickImage(source: ImageSource.gallery); - - if (pickedImage != null) { - setState(() { - _profileImage = File(pickedImage.path); - }); - } - } - - void _signUp() async { - if (_formKey.currentState!.validate()) { - _formKey.currentState!.save(); - - if (_profileImage != null) { - setState(() { - _isUploading = true; - }); - - // Upload profile picture to Firebase Storage - String imageUrl = await _uploadProfilePicture(); - - setState(() { - _isUploading = false; - _profileImageUrl = imageUrl; - }); - } - - setState(() { - _isLoading = true; - }); - - // Logging in the user w/ Firebase - String result = await AuthMethods().signUpUser( - name: _name, - email: _email, - password: _password, - username: _userName, - phone: _phone, - profileImageUrl: _profileImageUrl, - ); - - if (result != 'success') { - showSnackBar(result, context); - } else { - Navigator.of(context).push( - MaterialPageRoute(builder: (context) => LoginPage()), - ); - print(result); - } - - setState(() { - _isLoading = false; - }); - } - } - - Future _uploadProfilePicture() async { - if (_profileImage == null) return ''; - - final fileName = DateTime.now().millisecondsSinceEpoch.toString(); - final destination = 'profile_pictures/$fileName'; - - try { - final firebase_storage.Reference ref = - firebase_storage.FirebaseStorage.instance.ref(destination); - final task = ref.putFile(_profileImage!); - final snapshot = await task; - - if (snapshot.state == firebase_storage.TaskState.success) { - final imageUrl = await snapshot.ref.getDownloadURL(); - return imageUrl; - } - } catch (error) { - print('Error uploading profile picture: $error'); - } - - return ''; - } - - showSnackBar(String content, BuildContext context) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(content), - ), - ); - } - - _showEmptyDialog(String title) { - if (Platform.isAndroid) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) => AlertDialog( - content: Text("$title can't be empty"), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text("OK"), - ) - ], - ), - ); - } else if (Platform.isIOS) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) => CupertinoAlertDialog( - content: Text("$title can't be empty"), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text("OK"), - ) - ], - ), - ); - } - } -} diff --git a/lib/views/root_app.dart b/lib/views/root_app.dart deleted file mode 100644 index 3439b0d..0000000 --- a/lib/views/root_app.dart +++ /dev/null @@ -1,234 +0,0 @@ -import 'package:digi_farmer/pages/account_page.dart'; -import 'package:digi_farmer/pages/crops_page.dart'; -import 'package:digi_farmer/pages/home_page.dart'; -import 'package:digi_farmer/pages/logged_in_home.dart'; -import 'package:digi_farmer/pages/tips_page.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:google_sign_in/google_sign_in.dart'; -import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart'; -import 'package:animated_notch_bottom_bar/animated_notch_bottom_bar/animated_notch_bottom_bar.dart'; - -import '../pages/weather_page.dart'; - -class RootApp extends StatefulWidget { - final User? user; - - const RootApp({super.key, this.user}); - - @override - _RootAppState createState() => _RootAppState(); -} - -class _RootAppState extends State { - int pageIndex = 1; - - final List iconList = [ - Icons.home, - Icons.drafts, - Icons.list, - Icons.verified_user, - ]; - - final _pageController = PageController(initialPage: 0); - - int maxCount = 5; - - @override - Widget build(BuildContext context) { - /// widget list - final List bottomBarPages = [ - // ignore: prefer_const_constructors - LoggedInWidget(), - TipsPage(), - CropsPage(), - WeatherPage(), - AccountPage(user: widget.user), - ]; - return Scaffold( - body: PageView( - controller: _pageController, - physics: const NeverScrollableScrollPhysics(), - children: List.generate( - bottomBarPages.length, (index) => bottomBarPages[index]), - ), - extendBody: true, - bottomNavigationBar: (bottomBarPages.length <= maxCount) - ? AnimatedNotchBottomBar( - pageController: _pageController, - color: const Color.fromARGB(255, 75, 117, 32), - showLabel: true, - itemLabelStyle: const TextStyle( - color: Color.fromARGB(255, 208, 255, 161), - fontSize: 12, - ), - notchColor: const Color.fromARGB(255, 75, 117, 32), - bottomBarItems: [ - const BottomBarItem( - inActiveItem: Icon( - Icons.home_filled, - color: Color.fromARGB(255, 199, 228, 165), - ), - activeItem: Icon( - Icons.home_filled, - color: Color.fromARGB(255, 199, 228, 165), - ), - itemLabel: 'Home', - ), - const BottomBarItem( - inActiveItem: Icon( - Icons.list_alt_outlined, - color: Color.fromARGB(255, 199, 228, 165), - ), - activeItem: Icon( - Icons.list_alt_outlined, - color: Color.fromARGB(255, 199, 228, 165), - ), - itemLabel: 'Tips', - ), - - ///svg example - const BottomBarItem( - inActiveItem: Icon( - CupertinoIcons.tree, - color: Color.fromARGB(255, 199, 228, 165), - ), - activeItem: Icon( - CupertinoIcons.tree, - color: Color.fromARGB(255, 199, 228, 165), - ), - itemLabel: 'Crops', - ), - const BottomBarItem( - inActiveItem: Icon( - FontAwesomeIcons.cloudMoonRain, - color: Color.fromARGB(255, 199, 228, 165), - ), - activeItem: Icon( - FontAwesomeIcons.cloudMoonRain, - color: Color.fromARGB(255, 199, 228, 165), - ), - itemLabel: 'Weather', - ), - const BottomBarItem( - inActiveItem: Icon( - Icons.account_circle_outlined, - color: Color.fromARGB(255, 199, 228, 165), - ), - activeItem: Icon( - Icons.account_circle_outlined, - color: Color.fromARGB(255, 199, 228, 165), - ), - itemLabel: 'Account', - ), - ], - onTap: (index) { - /// control your animation using page controller - _pageController.animateToPage( - index, - duration: const Duration(milliseconds: 500), - curve: Curves.easeIn, - ); - }, - ) - : null, - ); - } - - Widget getBody() { - List pages = [ - // ignore: prefer_const_constructors - HomePage(), - CropsPage(user: widget.user), - TipsPage(), - AccountPage(user: widget.user), - ]; - return IndexedStack( - index: pageIndex, - children: pages, - ); - } - - Widget getFooter() { - var size = MediaQuery.of(context).size; - List bottomItems = [ - "assets/images/home.png", - "assets/images/leaves.png", - "assets/images/rainy-day.png", - "assets/images/user.png", - ]; - return Container( - width: size.width, - height: 70, - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.12), - blurRadius: 30.0, - offset: const Offset(0, -10), - ), - ], - ), - child: ClipRRect( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(20.0), - topRight: Radius.circular(20.0), - ), - child: Padding( - padding: - const EdgeInsets.only(left: 40, right: 40, bottom: 10, top: 20), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: List.generate(bottomItems.length, (index) { - return InkWell( - onTap: () { - selectedTab(index); - }, - child: Column( - children: [ - Image.asset( - bottomItems[index], - height: 18, - color: pageIndex == index - ? const Color.fromARGB(255, 97, 131, 63) - : Colors.grey, - ), - const SizedBox( - height: 15.0, - ), - (pageIndex == index) - ? AnimatedContainer( - duration: const Duration(milliseconds: 500), - curve: Curves.easeIn, - child: Container( - height: 5.0, - width: 20.0, - decoration: BoxDecoration( - color: - const Color.fromARGB(255, 97, 131, 63), - borderRadius: BorderRadius.circular(100)), - ), - ) - : Container( - height: 5.0, - width: 20.0, - ), - ], - )); - }), - ), - ), - ), - ); - } - - selectedTab(index) { - setState(() { - pageIndex = index; - }); - } -} diff --git a/lib/views/welcome_page.dart b/lib/views/welcome_page.dart deleted file mode 100644 index 1da9c37..0000000 --- a/lib/views/welcome_page.dart +++ /dev/null @@ -1,148 +0,0 @@ -import 'package:digi_farmer/views/login_page.dart'; -import 'package:flutter/material.dart'; - -class WelcomePage extends StatefulWidget { - const WelcomePage({super.key}); - - @override - State createState() => _WelcomePageState(); -} - -class _WelcomePageState extends State { - bool changeBtn = false; - - moveToHome(BuildContext context) async { - await Future.delayed(Duration(seconds: 1)); - await Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => LoginPage(), - )); - } - - @override - Widget build(BuildContext context) { - double w = MediaQuery.of(context).size.width; - double h = MediaQuery.of(context).size.height; - return SafeArea( - child: Scaffold( - backgroundColor: Color.fromARGB(255, 178, 212, 145), - // appBar: AppBar(title: Text("Farm.io"),centerTitle: true,backgroundColor: Colors.cyan,), - body: Column( - children: [ - Container( - width: w, - height: h * 0.55, - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage( - "assets/images/farming_welcome_2-removebg.png"), - fit: BoxFit.cover), - ), - ), - // Image.asset( - // "assets/images/farming_welcome_2.jpg", - // fit: BoxFit.cover, - // ), - const SizedBox( - height: 20.0, - ), - Container( - width: w * 0.9, - padding: EdgeInsets.only(left: 10, top: 10), - child: const Align( - alignment: Alignment.centerLeft, - child: Text( - "An Iniciative towards", - textAlign: TextAlign.start, - style: TextStyle( - color: Color(0xff446129), - // fontFamily: const GoogleFonts.openSans().fontFamily, - fontFamily: 'Montserrat', - fontSize: 22, - fontWeight: FontWeight.w800, - ), - ), - ), - ), - Container( - width: w * 0.9, - padding: const EdgeInsets.only( - left: 10, - ), - child: const Align( - alignment: Alignment.centerLeft, - child: Text( - "Smart Farming", - textAlign: TextAlign.justify, - style: TextStyle( - // fontFamily: GoogleFonts.montserrat().fontFamily, - fontFamily: 'Montserrat', - height: 1.2, - // overflow: TextOverflow.visible, - fontSize: 36, - fontWeight: FontWeight.w800, - ), - ), - ), - ), - const Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.only(left: 30, top: 10, right: 10), - child: Text( - // "DigiFarmer provides various tools that can help farmers with crop quality prediction, disease detection, yield prediction, weed detection, weather detection and prediction, and much more.", - "The power to manage your farm is just a tap away with our app!", - textWidthBasis: TextWidthBasis.longestLine, - overflow: TextOverflow.clip, - softWrap: true, - style: TextStyle( - color: Color(0xff446129), - // fontFamily: 'ConcertOne-', - fontSize: 16, - fontWeight: FontWeight.w500, - ), - ), - ), - ), - const SizedBox( - height: 20.0, - ), - Align( - alignment: Alignment.centerLeft, - child: Padding( - padding: const EdgeInsets.only(left: 30), - child: Material( - color: Color(0xff446129), - borderRadius: BorderRadius.circular(changeBtn ? 50 : 30), - child: InkWell( - onTap: () => moveToHome(context), - child: AnimatedContainer( - duration: Duration(seconds: 1), - width: changeBtn ? 50 : 150, - height: 60, - alignment: Alignment.center, - child: changeBtn - ? const Icon( - Icons.done, - color: Colors.white, - ) - : const Text( - "Get Started", - style: TextStyle( - fontSize: 18, - color: Colors.white, - fontWeight: FontWeight.bold, - ), - ), - ), - ), - ), - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/widget/category_card.dart b/lib/widget/category_card.dart deleted file mode 100644 index 57e6950..0000000 --- a/lib/widget/category_card.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'package:flutter/material.dart'; - -class CategoryCard extends StatelessWidget { - final String? imgSrc; - final String? title; - final double? fSize; - final void Function()? press; - const CategoryCard({ - Key? key, - this.imgSrc, - this.title, - this.press, - this.fSize, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return ClipRRect( - borderRadius: BorderRadius.circular(13), - child: Container( - padding: EdgeInsets.all(14), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(13), - boxShadow: [ - const BoxShadow( - offset: Offset(0, 17), - blurRadius: 17, - spreadRadius: -23, - color: Color.fromARGB(255, 229, 243, 213), - ), - ], - ), - child: Material( - color: Colors.transparent, - child: InkWell( - onTap: press, - child: Padding( - padding: const EdgeInsets.all(10.0), - child: Column( - children: [ - const Spacer(), - Hero( - tag: imgSrc.toString(), - child: Image.asset( - imgSrc.toString(), - fit: BoxFit.cover, - ), - ), - const Spacer(flex: 4), - Text( - title.toString(), - textAlign: TextAlign.center, - style: TextStyle( - color: Color.fromARGB(255, 83, 128, 36), - fontSize: fSize == null ? 18 : fSize, - fontWeight: FontWeight.bold, - ), - ) - ], - ), - ), - ), - ), - ), - ); - } -} diff --git a/lib/widget/clipper.dart b/lib/widget/clipper.dart deleted file mode 100644 index 20821c8..0000000 --- a/lib/widget/clipper.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; - -class BottomClipper extends CustomClipper { - @override - Path getClip(Size size) { - var path = Path(); - path.lineTo(0, 0); - path.lineTo(0, size.height - 20); - path.quadraticBezierTo( - size.width / 4, size.height, size.width / 2, size.height); - path.quadraticBezierTo( - size.width - size.width / 4, size.height, size.width, size.height - 20); - path.lineTo(size.width, 0); - path.lineTo(0, 0); - return path; - } - - @override - bool shouldReclip(CustomClipper oldClipper) { - return true; - } -} diff --git a/lib/widget/custom_category_card.dart b/lib/widget/custom_category_card.dart deleted file mode 100644 index 48054ed..0000000 --- a/lib/widget/custom_category_card.dart +++ /dev/null @@ -1,126 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomCourseCardExpand extends StatefulWidget { - const CustomCourseCardExpand({ - Key? key, - required this.thumbNail, - required this.title, - }) : super(key: key); - - final String thumbNail; - final String title; - - @override - _CustomCourseCardExpandState createState() => _CustomCourseCardExpandState(); -} - -class _CustomCourseCardExpandState extends State { - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - return Container( - width: size.width * .6, - alignment: Alignment.topCenter, - padding: const EdgeInsets.all(7.0), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(17.0), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.1), - blurRadius: 10.0, - offset: const Offset(0, 5), - ) - ], - ), - child: Column( - children: [ - Stack( - alignment: Alignment.bottomLeft, - children: [ - Container( - height: size.width * .6, - width: size.width * .6, - child: ClipRRect( - borderRadius: BorderRadius.circular(15.0), - child: Image.asset( - widget.thumbNail, - fit: BoxFit.cover, - ), - ), - ), - ], - ), - const SizedBox(height: 15.0), - Container( - padding: const EdgeInsets.only( - left: 7.0, - right: 7.0, - ), - child: Text( - widget.title, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: const TextStyle( - color: Color.fromARGB(255, 89, 109, 42), - fontSize: 17.0, - fontWeight: FontWeight.w700, - ), - ), - ), - const SizedBox(height: 15.0), - ], - ), - ); - } -} - -class CustomCourseCardShrink extends StatefulWidget { - const CustomCourseCardShrink({ - Key? key, - required this.thumbNail, - required this.title, - required this.userName, - required this.price, - }) : super(key: key); - - final String thumbNail; - final String title; - final String userName; - final String price; - - @override - _CustomCourseCardShrinkState createState() => _CustomCourseCardShrinkState(); -} - -class _CustomCourseCardShrinkState extends State { - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - return Container( - width: size.width, - height: size.width * .2, - padding: const EdgeInsets.all(15.0), - alignment: Alignment.center, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(12.0), - ), - child: Row( - children: [ - Container( - height: size.width * .125, - width: size.width * .125, - child: ClipRRect( - borderRadius: BorderRadius.circular(12.0), - child: Image.network( - widget.thumbNail, - fit: BoxFit.cover, - ), - ), - ), - ], - ), - ); - } -} diff --git a/lib/widget/custom_google_sign_in_btn.dart b/lib/widget/custom_google_sign_in_btn.dart deleted file mode 100644 index 6bd96c1..0000000 --- a/lib/widget/custom_google_sign_in_btn.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'package:digi_farmer/views/root_app.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter/material.dart'; - -import '../util/authentication.dart'; - -class GoogleSignInButton extends StatefulWidget { - @override - _GoogleSignInButtonState createState() => _GoogleSignInButtonState(); -} - -class _GoogleSignInButtonState extends State { - bool _isSigningIn = false; - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.only(bottom: 16.0), - child: _isSigningIn - ? CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(Colors.white), - ) - : OutlinedButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.white), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(40), - ), - ), - ), - onPressed: () async { - setState(() { - _isSigningIn = true; - }); - User? user = - await Authentication.signInWithGoogle(context: context); - - setState(() { - _isSigningIn = false; - }); - - if (user != null) { - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => RootApp( - user: user, - ), - ), - ); - } - }, - child: Padding( - padding: const EdgeInsets.fromLTRB(0, 10, 0, 10), - child: Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image( - image: AssetImage("assets/google_logo.png"), - height: 25.0, - ), - Padding( - padding: const EdgeInsets.only(left: 10), - child: Text( - 'Sign in with Google', - style: TextStyle( - fontSize: 14, - color: Colors.black54, - fontWeight: FontWeight.w600, - ), - ), - ) - ], - ), - ), - ), - ); - } -} diff --git a/lib/widget/custom_heading.dart b/lib/widget/custom_heading.dart deleted file mode 100644 index 58e1645..0000000 --- a/lib/widget/custom_heading.dart +++ /dev/null @@ -1,39 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomHeading extends StatelessWidget { - const CustomHeading({ - Key? key, - required this.title, - required this.subTitle, - required this.color, - }) : super(key: key); - - final String title; - final String subTitle; - final Color color; - - @override - Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - title, - style: TextStyle( - color: color, - fontSize: 28, - fontWeight: FontWeight.w700, - ), - ), - SizedBox(height: 10.0), - Text( - subTitle, - style: TextStyle( - color: color, - fontSize: 16.0, - ), - ), - ], - ); - } -} diff --git a/lib/widget/custom_search_feild.dart b/lib/widget/custom_search_feild.dart deleted file mode 100644 index 80230e1..0000000 --- a/lib/widget/custom_search_feild.dart +++ /dev/null @@ -1,95 +0,0 @@ -import 'package:digi_farmer/theme/padding.dart'; -import 'package:flutter/material.dart'; - -class CustomSearchField extends StatefulWidget { - const CustomSearchField({ - Key? key, - required this.hintField, - this.backgroundColor, - }) : super(key: key); - - final String hintField; - final Color? backgroundColor; - - @override - _CustomSearchFieldState createState() => _CustomSearchFieldState(); -} - -class _CustomSearchFieldState extends State { - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - return Container( - width: size.width, - height: spacer, - alignment: Alignment.center, - padding: const EdgeInsets.all(5.0), - decoration: BoxDecoration( - color: widget.backgroundColor, - borderRadius: BorderRadius.circular(7.0)), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - height: 40.0, - width: 40.0, - alignment: Alignment.center, - child: Container( - child: Image.asset( - 'assets/images/search.png', - color: Color.fromARGB(255, 30, 41, 4).withOpacity(0.5), - height: 15.0, - ), - ), - ), - Flexible( - child: Container( - width: size.width, - height: 38, - alignment: Alignment.topCenter, - child: TextField( - style: TextStyle(fontSize: 15), - cursorColor: Colors.black, - decoration: InputDecoration( - hintText: widget.hintField, - hintStyle: TextStyle( - fontSize: 15, - // fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 42, 59, 24).withOpacity(0.5), - ), - border: InputBorder.none, - ), - ), - ), - ), - SizedBox(width: 10.0), - Container( - height: 40.0, - width: 40.0, - alignment: Alignment.center, - decoration: BoxDecoration( - color: Color.fromARGB(255, 79, 122, 35).withOpacity(0.7), - borderRadius: BorderRadius.circular(7.0), - boxShadow: [ - BoxShadow( - color: Color.fromARGB(255, 178, 212, 145).withOpacity(0.5), - spreadRadius: 0.0, - blurRadius: 6.0, - offset: Offset(0, 2), - ) - ], - ), - child: Container( - child: Image.asset( - 'assets/images/filter.png', - color: Color.fromARGB(255, 255, 255, 255), - height: 22.0, - ), - ), - ), - ], - ), - ); - } -} diff --git a/lib/widget/custom_title.dart b/lib/widget/custom_title.dart deleted file mode 100644 index 12e5d8e..0000000 --- a/lib/widget/custom_title.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomTitle extends StatelessWidget { - const CustomTitle({ - Key? key, - required this.title, - this.route = '/404', - this.extend = true, - this.fontSize = 20.0, - this.arg, - }) : super(key: key); - - final String title; - final String route; - final bool extend; - final double fontSize; - final arg; - - @override - Widget build(BuildContext context) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - title, - style: TextStyle( - color: Color.fromARGB(255, 75, 117, 32), - fontSize: fontSize, - fontWeight: FontWeight.w700, - ), - ), - (extend) - ? GestureDetector( - onTap: () { - // Navigator.pushNamed( - // context, - // route, - // arguments: arg, - // ); - }, - child: Text( - 'See More', - style: TextStyle( - color: Color.fromARGB(255, 75, 117, 32), - fontSize: 15.0, - fontWeight: FontWeight.w400), - ), - ) - : Container(), - ], - ); - } -} diff --git a/lib/widget/features_card.dart b/lib/widget/features_card.dart deleted file mode 100644 index 15d2670..0000000 --- a/lib/widget/features_card.dart +++ /dev/null @@ -1,50 +0,0 @@ -import 'package:flutter/material.dart'; - -class FeaturesCard extends StatefulWidget { - final Icon icon; - final String title; - - const FeaturesCard({super.key, required this.icon, required this.title}); - - @override - State createState() => _FeaturesCardState(); -} - -class _FeaturesCardState extends State { - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - - return Card( - color: Color.fromARGB(255, 250, 255, 246), - clipBehavior: Clip.antiAlias, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(40), // if you need this - side: BorderSide( - color: Colors.grey.withOpacity(0.2), - width: 1, - ), - ), - child: SizedBox( - width: size.width * 0.7, - height: size.height * 0.1, - child: Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - widget.icon, - Text( - widget.title, - style: TextStyle( - fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 67, 97, 37), - fontSize: 18, - ), - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/widget/header.dart b/lib/widget/header.dart deleted file mode 100644 index f6889d1..0000000 --- a/lib/widget/header.dart +++ /dev/null @@ -1,338 +0,0 @@ -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:geocoding/geocoding.dart'; -import 'package:geolocator/geolocator.dart'; -import 'package:get/get.dart'; -import 'package:google_fonts/google_fonts.dart'; -import 'package:http/http.dart'; -import '../controller/global_controller.dart'; -import 'package:intl/intl.dart'; -import 'package:http/src/response.dart'; - -class HeaderWidget extends StatefulWidget { - const HeaderWidget({super.key}); - - @override - State createState() => _HeaderWidgetState(); -} - -class _HeaderWidgetState extends State { - String city = ""; //city name - String date = (DateFormat.yMMMd().format(DateTime.now())).toString(); - - List weather = []; - - int hour = DateTime.now().hour; - - final GlobalController globalController = - Get.put(GlobalController(), permanent: true); - - @override - void initState() { - getAddress( - globalController.getLattitude().value, - globalController.getLongitude().value, - ); - super.initState(); - } - - getAddress(lat, lon) async { - List placemark = await placemarkFromCoordinates(lat, lon); - Placemark place = placemark[0]; - - setState(() { - city = place.locality!.toString(); - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - body: FutureBuilder>( - future: getweather(), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator( - color: Colors.green, - )); - } else { - //print(snapshot.data); - return Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: getcolor()), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 40, - ), - Padding( - padding: EdgeInsets.all(25), - child: Text( - "Weather", - style: GoogleFonts.poppins( - fontSize: 40, - color: Colors.white, - fontWeight: FontWeight.w500), - )), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Container( - height: 150, - width: 150, - child: Image.asset( - getWeatherIcon(weather[0].id), - fit: BoxFit.fill, - )), - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "${(weather[0].temp - 273.15).toStringAsFixed(1)}°", - style: GoogleFonts.poppins( - fontSize: 60, color: Colors.white), - ), - Text( - weather[0].weather, - style: GoogleFonts.poppins( - color: Colors.white, fontSize: 24), - ), - ], - ), - ], - ), - const SizedBox( - height: 30, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Humidity', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w600), - ), - Text( - "${(weather[0].humidity).toStringAsFixed(1)}%", - style: GoogleFonts.poppins( - fontSize: 50, color: Colors.white), - ), - ], - ), - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Pressure', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w600), - ), - Text( - "${(weather[0].pressure)}", - style: GoogleFonts.poppins( - fontSize: 46, color: Colors.white), - ), - ], - ), - ], - ), - const SizedBox( - height: 10, - ), - Padding( - padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), - child: Text( - 'Forecast :', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w600), - )), - Expanded( - child: GridView( - shrinkWrap: true, - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - childAspectRatio: 1.5, - crossAxisCount: 2, - crossAxisSpacing: 10, - mainAxisSpacing: 5.0), - children: snapshot.data!.map((document) { - return Column( - // mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - DateFormat('EEEE').format( - DateTime.fromMillisecondsSinceEpoch( - document.dt * 1000)), - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w400), - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - children: [ - SizedBox( - height: 70, - child: Image.asset( - getWeatherIcon(document.desc)), - ), - Column( - children: [ - Text( - 'Max: ${(document.max - 273.15).toStringAsFixed(1)}°', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w600), - ), - Text( - 'Max: ${(document.min - 273.15).toStringAsFixed(1)}°', - style: GoogleFonts.poppins( - color: Colors.white, - fontSize: 14, - fontWeight: FontWeight.w600), - ), - ], - ), - ], - ), - ], - ); - }).toList()), - ) - ], - ), - ); - } - }), - ); - } - - List getcolor() { - if (hour >= 6 && hour <= 11) { - return [ - const Color(0xFF83eaf1), - const Color(0xFF3eadcf) - ]; //const Color(0xFF83eaf1), const Color(0xFF3eadcf) - } else if (hour > 11 && hour <= 16) { - return [const Color(0xFFFFDF00), const Color(0xFFF6D108)]; - } else if (hour > 16 && hour < 19) { - return [ - Color(0xFF4e54c8), - const Color(0xFF9795ef), - ]; - } else { - return [const Color(0xFF001D37), const Color(0xFF01162E)]; - } - } - - String getWeatherIcon(int condition) { - if (condition < 300) { - return 'assets/ic_storm_weather.png'; - } else if (condition < 400) { - return 'assets/ic_rainy_weather.png'; - } else if (condition < 600) { - return 'assets/ic_rainy_weather.png'; - } else if (condition < 700) { - return 'assets/ic_snow_weather.png'; - } else if (condition < 800) { - return 'assets/ic_mostly_cloudy.png'; - } else if (condition == 800) { - return 'assets/ic_clear_day.png'; - } else if (condition <= 804) { - return 'assets/ic_cloudy_weather.png'; - } else { - return 'assets/ic_unknown.png'; - } - } - - Future _determinePosition() async { - bool serviceEnabled; - LocationPermission permission; - serviceEnabled = await Geolocator.isLocationServiceEnabled(); - if (!serviceEnabled) { - return Future.error('Location services are disabled.'); - } - permission = await Geolocator.checkPermission(); - if (permission == LocationPermission.denied) { - permission = await Geolocator.requestPermission(); - if (permission == LocationPermission.denied) { - return Future.error('Location permissions are denied'); - } - } - if (permission == LocationPermission.deniedForever) { - return Future.error( - 'Location permissions are permanently denied, we cannot request permissions.'); - } - return await Geolocator.getCurrentPosition(); - } - - Future> getweather() async { - Position p = await _determinePosition(); - var r = await get(Uri.parse( - "https://api.openweathermap.org/data/2.5/onecall?lat=${p.latitude}&lon=${p.longitude}&exclude=hourly,minutely&appid=8cb6386fe572b5b0befe4eba9bfa7c2f")); - //print(r.body); - Map x = jsonDecode(r.body); - //print(x['current']); - weather.add(current( - x['current']['temp'], - x['current']['weather'][0]['description'], - x['current']['weather'][0]['main'], - x['current']['humidity'], - x['current']['weather'][0]['id'], - x['current']['pressure'])); - var y = x['daily']; - print(y); - - List z = []; - for (var i = 1; i < 5; i++) { - //print(y[i]['weather'][0]['id']); - z.add(forecast( - y[i]['dt'], - y[i]['humidity'], - y[i]['temp']['max'], - y[i]['temp']['min'], - y[i]['weather'][0]['main'], - y[i]['weather'][0]['id'])); - } - - return z; - } -} - -class current { - var temp; - var pressure; - var humidity; - var weather; - var id; - var desc; - current(this.temp, this.desc, this.weather, this.humidity, this.id, - this.pressure); -} - -class forecast { - var dt; - var max; - var humidity; - var min; - var weather; - var desc; - forecast(this.dt, this.humidity, this.max, this.min, this.weather, this.desc); -} diff --git a/lib/widget/themes.dart b/lib/widget/themes.dart deleted file mode 100644 index 6445285..0000000 --- a/lib/widget/themes.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; - -class MyTheme { - static ThemeData lightTheme(BuildContext context) => ThemeData( - primarySwatch: Colors.lightGreen, - fontFamily: "Montserrat", - // fontFamily: GoogleFonts.poppins().fontFamily, - // appBarTheme: AppBarTheme( - // color: Colors.white, - // elevation: 0.0, - // iconTheme: IconThemeData(color: Colors.black), - // titleTextStyle: TextStyle(color: Colors.black), - // ), - ); - - static ThemeData darktheme(BuildContext context) => ThemeData( - brightness: Brightness.dark, - ); - - //Colors - - static Color creamColor = const Color(0xfff5f5f5); - static Color darkBluishColor = const Color(0xff403b58); -}