Commit fd8faf69 authored by Yasasdissanayake's avatar Yasasdissanayake

final

parent 2d7ffda0
import 'package:flutter/foundation.dart';
import 'package:flutter/material.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:switcher_button/switcher_button.dart';
......@@ -116,10 +116,7 @@ class _HomeState extends State<Home> {
child: GestureDetector(
onTap: foodswitch
? () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => foodbuckets()));
}
: null,
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';
import 'package:flutter/material.dart';
import 'package:ifarm/Screens/AB/Login.dart';
import 'package:ifarm/Screens/AB/Navbar.dart';
import 'package:ifarm/Screens/AB/NetworkErrorPage.dart';
import 'package:ifarm/functions/Network.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
......
import 'package:cloud_firestore/cloud_firestore.dart';
class Bucket {
final List<String>? bucketId;
class WaterBucket {
final List<String>? waterbucketId;
Bucket({this.bucketId});
factory Bucket.fromFirestore(
WaterBucket({this.waterbucketId});
factory WaterBucket.fromFirestore(
DocumentSnapshot<Map<String, dynamic>> snapshot,
) {
final data = snapshot.data();
return Bucket(
bucketId:
data?['Buckets'] is Iterable ? List.from(data?['regions']) : null);
return WaterBucket(
waterbucketId: data?['WaterBuckets'] is Iterable
? List.from(data?['regions'])
: null);
}
}
......@@ -14,7 +14,7 @@ class _firebaselistState extends State<firebaselist> {
@override
Widget build(BuildContext context) {
Query ref = firebasedatalist.ref().child('Food');
Query ref = firebasedatalist.ref().child('Water');
return Scaffold(
appBar: AppBar(
......@@ -51,7 +51,7 @@ class _firebaselistState extends State<firebaselist> {
onPressed: () {
firebasedatalist
.ref()
.child('Food')
.child('Water')
.child(snapshot.key!)
.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';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.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/services.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/functions/firebaseFunctions.dart';
class foodbuckets extends StatefulWidget {
foodbuckets({Key? key}) : super(key: key);
class waterbuckets extends StatefulWidget {
waterbuckets({Key? key}) : super(key: key);
@override
State<foodbuckets> createState() => _foodbucketsState();
State<waterbuckets> createState() => _waterbucketsState();
}
String name = "";
final firebasedatalist = FirebaseDatabase.instance;
var getResult = 'QR Code Result';
List buckets = [];
List buckets = [1];
class _foodbucketsState extends State<foodbuckets> {
class _waterbucketsState extends State<waterbuckets> {
@override
void initState() {
super.initState();
......@@ -33,7 +33,7 @@ class _foodbucketsState extends State<foodbuckets> {
@override
Widget build(BuildContext context) {
final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots();
FirebaseFirestore.instance.collection('waterbuckets').snapshots();
return Scaffold(
backgroundColor: const Color(0xff024F8E),
......@@ -47,7 +47,7 @@ class _foodbucketsState extends State<foodbuckets> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Food',
'Water',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
......@@ -74,17 +74,8 @@ class _foodbucketsState extends State<foodbuckets> {
storedata.add(a);
}).toList();
return storedata[0]['Buckets'].isEmpty
? const Center(
child: Text(
'Add bucket',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
))
: ListView.builder(
itemCount: storedata[0]['Buckets'].length,
return ListView.builder(
itemCount: storedata[0]['WaterBuckets'].length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
......@@ -92,8 +83,8 @@ class _foodbucketsState extends State<foodbuckets> {
context,
MaterialPageRoute(
builder: (context) => datafromfirebase(
bucketId: storedata[0]['Buckets']
[index],
bucketId: storedata[0]
['WaterBuckets'][index],
)));
},
child: Container(
......@@ -137,16 +128,16 @@ class _foodbucketsState extends State<foodbuckets> {
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
scanQRCode();
},
backgroundColor: Colors.white,
child: const Icon(
Icons.add,
color: Color(0xff024F8E),
),
),
// floatingActionButton: FloatingActionButton(
// onPressed: () {
// scanQRCode();
// },
// backgroundColor: Colors.white,
// child: const Icon(
// Icons.add,
// 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