Commit fd8faf69 authored by Yasasdissanayake's avatar Yasasdissanayake

final

parent 2d7ffda0
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:ifarm/Screens/AB/Food.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:switcher_button/switcher_button.dart'; import 'package:switcher_button/switcher_button.dart';
...@@ -116,10 +116,7 @@ class _HomeState extends State<Home> { ...@@ -116,10 +116,7 @@ class _HomeState extends State<Home> {
child: GestureDetector( child: GestureDetector(
onTap: foodswitch onTap: foodswitch
? () { ? () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => foodbuckets()));
} }
: null, : null,
child: Container( child: Container(
......
import 'package:flutter/material.dart';
import 'package:ifarm/Screens/AB/SplashScreen.dart';
class networkError extends StatefulWidget {
networkError({Key? key}) : super(key: key);
@override
State<networkError> createState() => _networkErrorState();
}
class _networkErrorState extends State<networkError> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
elevation: 0,
backgroundColor: Color(0xffE2E7ED),
),
body: Container(
color: Color(0xffE2E7ED),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/error.jpg',
scale: 1,
),
const Text(
'No Connection!',
style: TextStyle(
color: Color.fromARGB(255, 70, 70, 70), fontSize: 20),
),
const SizedBox(
height: 20,
),
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => splashScreen()));
},
child: Container(
decoration: BoxDecoration(
color: const Color(0xffFEC427),
borderRadius: BorderRadius.circular(15)),
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 25),
child: Text('Try Again'),
),
)
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
class QRScanner extends StatefulWidget {
QRScanner({Key? key}) : super(key: key);
@override
State<QRScanner> createState() => _QRScannerState();
}
var getResult = 'QR Code Result';
class _QRScannerState extends State<QRScanner> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
scanQRCode();
},
child: const Text('Scan QR')),
const SizedBox(
height: 20.0,
),
Text(getResult),
],
),
));
}
void scanQRCode() async {
try {
final qrCode = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
if (!mounted) return;
setState(() {
getResult = qrCode;
});
print("QRCode_Result:--");
print(qrCode);
} on PlatformException {
getResult = 'Failed to scan QR Code.';
}
}
}
...@@ -5,7 +5,7 @@ import 'package:connectivity_plus/connectivity_plus.dart'; ...@@ -5,7 +5,7 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ifarm/Screens/AB/Login.dart'; import 'package:ifarm/Screens/AB/Login.dart';
import 'package:ifarm/Screens/AB/Navbar.dart'; import 'package:ifarm/Screens/AB/Navbar.dart';
import 'package:ifarm/Screens/AB/NetworkErrorPage.dart';
import 'package:ifarm/functions/Network.dart'; import 'package:ifarm/functions/Network.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
......
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
class Bucket { class WaterBucket {
final List<String>? bucketId; final List<String>? waterbucketId;
Bucket({this.bucketId}); WaterBucket({this.waterbucketId});
factory Bucket.fromFirestore( factory WaterBucket.fromFirestore(
DocumentSnapshot<Map<String, dynamic>> snapshot, DocumentSnapshot<Map<String, dynamic>> snapshot,
) { ) {
final data = snapshot.data(); final data = snapshot.data();
return Bucket( return WaterBucket(
bucketId: waterbucketId: data?['WaterBuckets'] is Iterable
data?['Buckets'] is Iterable ? List.from(data?['regions']) : null); ? List.from(data?['regions'])
: null);
} }
} }
...@@ -14,7 +14,7 @@ class _firebaselistState extends State<firebaselist> { ...@@ -14,7 +14,7 @@ class _firebaselistState extends State<firebaselist> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Query ref = firebasedatalist.ref().child('Food'); Query ref = firebasedatalist.ref().child('Water');
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
...@@ -51,7 +51,7 @@ class _firebaselistState extends State<firebaselist> { ...@@ -51,7 +51,7 @@ class _firebaselistState extends State<firebaselist> {
onPressed: () { onPressed: () {
firebasedatalist firebasedatalist
.ref() .ref()
.child('Food') .child('Water')
.child(snapshot.key!) .child(snapshot.key!)
.remove(); .remove();
}, },
......
import 'dart:async';
import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:liquid_progress_indicator/liquid_progress_indicator.dart';
import 'package:switcher_button/switcher_button.dart';
class datafromfirebasewater extends StatefulWidget {
datafromfirebasewater({
Key? key,
}) : super(key: key);
@override
State<datafromfirebasewater> createState() => _datafromfirebasewaterState();
}
String p = '100';
String ph = '250';
class _datafromfirebasewaterState extends State<datafromfirebasewater> {
@override
void initState() {
super.initState();
getData();
runTimer();
}
Timer? timer;
void runTimer() {
timer = Timer.periodic(const Duration(seconds: 2), (_) {
getData();
});
}
getData() {
FirebaseDatabase.instance.ref().child('Water/ph').onValue.listen((event) {
setState(() {
ph = event.snapshot.value.toString();
});
});
FirebaseDatabase.instance
.ref()
.child('Water/percentage')
.onValue
.listen((event) {
setState(() {
p = event.snapshot.value.toString();
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () {
Navigator.pop(context);
timer!.cancel();
},
),
backgroundColor: const Color(0xff024F8E),
elevation: 0,
),
backgroundColor: const Color(0xff024F8E),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 40,
),
const Text(
'Bucket',
style: TextStyle(
color: Color.fromARGB(255, 255, 255, 255),
fontSize: 30,
fontFamily: 'poppins',
fontWeight: FontWeight.bold),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 100,
width: 310,
child: LiquidLinearProgressIndicator(
value: double.parse(p) / 100, // Defaults to 0.5.
valueColor: AlwaysStoppedAnimation(
double.parse(p) >= 10.0 && double.parse(p) <= 90.0
? Colors.green
: Colors.red,
),
backgroundColor: const Color.fromARGB(255, 255, 255, 255),
borderRadius: 20,
direction: Axis.vertical,
center: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: const [
FaIcon(
FontAwesomeIcons.fill,
color: Color.fromARGB(255, 0, 0, 0),
),
SizedBox(
width: 10,
),
Text(
'Water Presentage',
style: TextStyle(
fontSize: 20,
color: Color.fromARGB(179, 0, 0, 0),
fontFamily: 'poppins',
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
p,
style: const TextStyle(
fontSize: 20,
color: Color.fromARGB(255, 0, 0, 0),
fontWeight: FontWeight.bold),
),
const Text(
'%',
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontWeight: FontWeight.bold),
),
],
),
],
),
),
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 2,
color: double.parse(ph) == 0 ? Colors.green : Colors.red,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
const SizedBox(
height: 10,
),
const Text(
'PH',
style: TextStyle(
fontSize: 20,
color: Colors.white70,
fontFamily: 'poppins',
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
ph,
style: const TextStyle(
color: Colors.white,
fontSize: 40,
fontFamily: 'poppins',
),
),
],
),
],
),
),
),
],
),
),
],
),
),
);
}
}
...@@ -3,28 +3,28 @@ import 'dart:ffi'; ...@@ -3,28 +3,28 @@ import 'dart:ffi';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart'; import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database/ui/firebase_animated_list.dart'; //import 'package:firebase_database/ui/firebase_animated_list.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:ifarm/Screens/AB/bucket.dart'; //import 'package:ifarm/Screens/AB/bucket.dart';
import 'package:ifarm/Screens/AB/data.dart'; import 'package:ifarm/Screens/AB/data.dart';
import 'package:ifarm/functions/firebaseFunctions.dart'; import 'package:ifarm/functions/firebaseFunctions.dart';
class foodbuckets extends StatefulWidget { class waterbuckets extends StatefulWidget {
foodbuckets({Key? key}) : super(key: key); waterbuckets({Key? key}) : super(key: key);
@override @override
State<foodbuckets> createState() => _foodbucketsState(); State<waterbuckets> createState() => _waterbucketsState();
} }
String name = ""; String name = "";
final firebasedatalist = FirebaseDatabase.instance; final firebasedatalist = FirebaseDatabase.instance;
var getResult = 'QR Code Result'; var getResult = 'QR Code Result';
List buckets = []; List buckets = [1];
class _foodbucketsState extends State<foodbuckets> { class _waterbucketsState extends State<waterbuckets> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -33,7 +33,7 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -33,7 +33,7 @@ class _foodbucketsState extends State<foodbuckets> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Stream<QuerySnapshot> bucketref = final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots(); FirebaseFirestore.instance.collection('waterbuckets').snapshots();
return Scaffold( return Scaffold(
backgroundColor: const Color(0xff024F8E), backgroundColor: const Color(0xff024F8E),
...@@ -47,7 +47,7 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -47,7 +47,7 @@ class _foodbucketsState extends State<foodbuckets> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Text( const Text(
'Food', 'Water',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
...@@ -74,17 +74,8 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -74,17 +74,8 @@ class _foodbucketsState extends State<foodbuckets> {
storedata.add(a); storedata.add(a);
}).toList(); }).toList();
return storedata[0]['Buckets'].isEmpty return ListView.builder(
? const Center( itemCount: storedata[0]['WaterBuckets'].length,
child: Text(
'Add bucket',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
))
: ListView.builder(
itemCount: storedata[0]['Buckets'].length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
...@@ -92,8 +83,8 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -92,8 +83,8 @@ class _foodbucketsState extends State<foodbuckets> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => datafromfirebase( builder: (context) => datafromfirebase(
bucketId: storedata[0]['Buckets'] bucketId: storedata[0]
[index], ['WaterBuckets'][index],
))); )));
}, },
child: Container( child: Container(
...@@ -137,16 +128,16 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -137,16 +128,16 @@ class _foodbucketsState extends State<foodbuckets> {
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( // floatingActionButton: FloatingActionButton(
onPressed: () { // onPressed: () {
scanQRCode(); // scanQRCode();
}, // },
backgroundColor: Colors.white, // backgroundColor: Colors.white,
child: const Icon( // child: const Icon(
Icons.add, // Icons.add,
color: Color(0xff024F8E), // color: Color(0xff024F8E),
), // ),
), // ),
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment