Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 21
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 21
22_23-J 21
Commits
c24889e2
Commit
c24889e2
authored
May 10, 2023
by
Karunarathna K.M.D.Y.K
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT19978666' into 'master'
Added crop diseases screens See merge request
!12
parents
6118d66e
3be36692
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
466 additions
and
0 deletions
+466
-0
FrontEnd/lib/screens/menu_screens/crop_diseases/disease_details_screen.dart
...ns/menu_screens/crop_diseases/disease_details_screen.dart
+192
-0
FrontEnd/lib/screens/menu_screens/crop_diseases/diseases_screen.dart
...b/screens/menu_screens/crop_diseases/diseases_screen.dart
+155
-0
FrontEnd/lib/services/auth_service.dart
FrontEnd/lib/services/auth_service.dart
+82
-0
FrontEnd/lib/services/disease_service.dart
FrontEnd/lib/services/disease_service.dart
+37
-0
No files found.
FrontEnd/lib/screens/menu_screens/crop_diseases/disease_details_screen.dart
0 → 100644
View file @
c24889e2
import
'package:flutter/material.dart'
;
import
'package:govimithura/providers/disease_provider.dart'
;
import
'package:govimithura/providers/img_util_provider.dart'
;
import
'package:govimithura/utils/loading_overlay.dart'
;
import
'package:govimithura/utils/screen_size.dart'
;
import
'package:govimithura/widgets/utils/common_widget.dart'
;
import
'package:provider/provider.dart'
;
import
'../../../utils/utils.dart'
;
class
DiseaseDetailsScreen
extends
StatefulWidget
{
final
int
leafId
;
final
int
diseaseId
;
const
DiseaseDetailsScreen
(
{
super
.
key
,
required
this
.
leafId
,
required
this
.
diseaseId
});
@override
State
<
DiseaseDetailsScreen
>
createState
()
=>
_DiseaseDetailsScreenState
();
}
class
_DiseaseDetailsScreenState
extends
State
<
DiseaseDetailsScreen
>
with
SingleTickerProviderStateMixin
{
late
DiseaseProvider
pDisease
;
late
AnimationController
_controller
;
late
Animation
<
double
>
_animation
;
@override
void
dispose
()
{
_controller
.
dispose
();
super
.
dispose
();
}
@override
void
initState
()
{
super
.
initState
();
_controller
=
AnimationController
(
duration:
const
Duration
(
seconds:
2
),
vsync:
this
,
);
final
curvedAnimation
=
CurvedAnimation
(
parent:
_controller
,
curve:
Curves
.
easeInOut
);
_animation
=
Tween
<
double
>(
begin:
0
,
end:
1
).
animate
(
curvedAnimation
);
_controller
.
forward
();
pDisease
=
Provider
.
of
<
DiseaseProvider
>(
context
,
listen:
false
);
Future
.
delayed
(
Duration
.
zero
,
()
=>
initialize
());
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
"Crop Disease Details"
),
centerTitle:
true
,
),
body:
SingleChildScrollView
(
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
20
),
child:
Consumer
<
DiseaseProvider
>(
builder:
(
context
,
disease
,
child
)
{
return
Column
(
children:
[
Material
(
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
circular
(
70
),
child:
SizedBox
(
height:
150
,
child:
Row
(
children:
[
spacingWidget
(
20
,
SpaceDirection
.
horizontal
),
CircleAvatar
(
onBackgroundImageError:
(
exception
,
stackTrace
)
=>
Utils
.
showSnackBar
(
context
,
'Error loading image'
),
backgroundColor:
Theme
.
of
(
context
).
primaryColor
,
radius:
50
,
backgroundImage:
Provider
.
of
<
ImageUtilProvider
>(
context
,
listen:
false
)
.
image
,
),
spacingWidget
(
20
,
SpaceDirection
.
horizontal
),
Flexible
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
disease
.
leafEntity
.
description
,
style:
const
TextStyle
(
fontSize:
25
,
fontWeight:
FontWeight
.
bold
,
),
),
const
Text
(
"Leaf Name"
,
style:
TextStyle
(
fontSize:
16
,
color:
Colors
.
grey
,
),
),
],
),
),
],
),
),
),
if
(!
disease
.
diseaseEntity
.
name
.
toLowerCase
()
.
startsWith
(
"healthy"
))
Column
(
children:
[
const
SizedBox
(
height:
15
,
),
Text
(
disease
.
diseaseEntity
.
name
,
style:
const
TextStyle
(
fontWeight:
FontWeight
.
w600
,
fontSize:
20
,
),
),
spacingWidget
(
20
,
SpaceDirection
.
vertical
),
if
(
disease
.
diseaseEntity
.
image
.
isNotEmpty
)
Container
(
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
10
),
image:
DecorationImage
(
image:
NetworkImage
(
disease
.
diseaseEntity
.
image
),
fit:
BoxFit
.
cover
),
),
height:
ScreenSize
.
height
*
0.3
,
width:
ScreenSize
.
width
,
),
spacingWidget
(
20
,
SpaceDirection
.
vertical
),
Text
(
disease
.
diseaseEntity
.
description
,
style:
const
TextStyle
(
fontSize:
16
,
),
),
],
)
else
_successIntro
()
],
);
},
)),
),
);
}
Widget
_successIntro
()
{
return
ScaleTransition
(
scale:
_animation
,
child:
SizedBox
(
height:
ScreenSize
.
height
*
0.6
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Container
(
width:
200
,
height:
200
,
decoration:
const
BoxDecoration
(
shape:
BoxShape
.
circle
,
color:
Colors
.
green
,
),
child:
const
Icon
(
Icons
.
check_rounded
,
size:
120
,
color:
Colors
.
white
,
),
),
spacingWidget
(
20
,
SpaceDirection
.
vertical
),
const
Text
(
"This leaf is Healthy"
,
style:
TextStyle
(
fontSize:
30
,
fontWeight:
FontWeight
.
bold
),
),
],
),
),
);
}
Future
<
void
>
initialize
()
async
{
await
LoadingOverlay
.
of
(
context
).
during
(
pDisease
.
getLeafsById
(
widget
.
leafId
,
widget
.
diseaseId
,
context
),
);
}
}
FrontEnd/lib/screens/menu_screens/crop_diseases/diseases_screen.dart
0 → 100644
View file @
c24889e2
import
'package:flutter/material.dart'
;
import
'package:govimithura/providers/ml_provider.dart'
;
import
'package:govimithura/utils/loading_overlay.dart'
;
import
'package:govimithura/widgets/utils/buttons/custom_elevated_button.dart'
;
import
'package:image_picker/image_picker.dart'
;
import
'package:provider/provider.dart'
;
import
'../../../providers/img_util_provider.dart'
;
import
'../../../utils/screen_size.dart'
;
import
'../../../utils/utils.dart'
;
import
'../../../widgets/utils/common_widget.dart'
;
import
'../../../widgets/utils/image_util.dart'
;
import
'disease_details_screen.dart'
;
class
DiseasesScreen
extends
StatefulWidget
{
const
DiseasesScreen
({
super
.
key
});
@override
State
<
DiseasesScreen
>
createState
()
=>
_DiseasesScreenState
();
}
class
_DiseasesScreenState
extends
State
<
DiseasesScreen
>
{
@override
Widget
build
(
BuildContext
context
)
{
Size
imageSize
=
Size
(
ScreenSize
.
width
,
ScreenSize
.
height
*
0.45
);
return
Consumer
<
ImageUtilProvider
>(
builder:
(
context
,
pImage
,
child
)
{
return
Stack
(
children:
[
Container
(
height:
ScreenSize
.
height
,
width:
ScreenSize
.
width
,
color:
Theme
.
of
(
context
).
primaryColor
,
child:
Column
(
children:
const
[
CustomAssetImage
(
assetName:
"diseases_home.png"
)
],
),
),
Positioned
(
top:
ScreenSize
.
height
*
0.12
,
height:
ScreenSize
.
height
*
0.725
,
width:
ScreenSize
.
width
,
child:
Container
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
ScreenSize
.
width
*
0.05
,
vertical:
ScreenSize
.
height
*
0.02
,
),
decoration:
const
BoxDecoration
(
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
only
(
topLeft:
Radius
.
circular
(
20
),
topRight:
Radius
.
circular
(
20
)),
),
child:
Column
(
children:
[
ButtonBar
(
children:
[
CustomElevatedButton
(
text:
"Predict"
,
onPressed:
()
async
{
if
(
pImage
.
imagePath
==
null
)
{
Utils
.
showSnackBar
(
context
,
"Please select an image"
);
return
;
}
MLProvider
pML
=
Provider
.
of
<
MLProvider
>(
context
,
listen:
false
);
LoadingOverlay
overlay
=
LoadingOverlay
.
of
(
context
);
int
leafId
=
await
overlay
.
during
(
pML
.
predictLeaf
(
context
));
if
(
mounted
)
{
int
diseaseId
=
await
overlay
.
during
(
pML
.
predictDisease
(
context
,
leafId
));
if
(
mounted
&&
leafId
>=
0
&&
diseaseId
>=
0
)
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
DiseaseDetailsScreen
(
leafId:
leafId
,
diseaseId:
diseaseId
,
),
),
);
}
}
},
),
],
),
spacingWidget
(
10
,
SpaceDirection
.
vertical
),
Container
(
height:
imageSize
.
height
,
width:
imageSize
.
width
,
decoration:
BoxDecoration
(
image:
DecorationImage
(
image:
pImage
.
image
??
const
AssetImage
(
"assets/images/diseases_home.png"
),
fit:
BoxFit
.
cover
),
),
),
ButtonBar
(
alignment:
MainAxisAlignment
.
spaceAround
,
children:
[
FloatingActionButton
(
heroTag:
'gallery'
,
backgroundColor:
Theme
.
of
(
context
)
.
floatingActionButtonTheme
.
backgroundColor
,
onPressed:
()
async
{
await
Utils
.
pickImage
(
ImageSource
.
gallery
,
imageSize
,
context
);
},
child:
const
Icon
(
Icons
.
image_rounded
,
),
),
FloatingActionButton
.
large
(
heroTag:
'camera'
,
backgroundColor:
Theme
.
of
(
context
)
.
floatingActionButtonTheme
.
backgroundColor
,
onPressed:
()
async
{
await
Utils
.
pickImage
(
ImageSource
.
camera
,
imageSize
,
context
);
},
child:
const
Icon
(
Icons
.
photo_camera_rounded
,
size:
50
,
),
),
FloatingActionButton
(
heroTag:
'crop'
,
backgroundColor:
Theme
.
of
(
context
)
.
floatingActionButtonTheme
.
backgroundColor
,
onPressed:
()
async
{
await
Utils
.
cropImage
(
context
,
imageSize
);
},
child:
const
Icon
(
Icons
.
crop
,
),
),
],
),
],
),
),
),
],
);
},
);
}
}
FrontEnd/lib/services/auth_service.dart
0 → 100644
View file @
c24889e2
import
'package:firebase_auth/firebase_auth.dart'
;
import
'package:flutter/material.dart'
;
import
'package:govimithura/models/auth_model.dart'
;
import
'package:govimithura/models/error_model.dart'
;
class
AuthService
{
static
final
FirebaseAuth
_auth
=
FirebaseAuth
.
instance
;
Future
<
bool
>
login
(
AuthModel
authModel
)
async
{
try
{
UserCredential
userCred
=
await
_auth
.
signInWithEmailAndPassword
(
email:
authModel
.
email
,
password:
authModel
.
password
)
.
then
((
value
)
=>
value
);
return
userCred
.
user
?.
uid
!=
null
;
}
on
FirebaseAuthException
catch
(
e
)
{
if
(
e
.
code
==
'user-not-found'
)
{
ErrorModel
.
errorMessage
=
'No user found for this email.'
;
}
else
if
(
e
.
code
==
'wrong-password'
)
{
ErrorModel
.
errorMessage
=
'Wrong password provided for this user.'
;
}
else
{
ErrorModel
.
errorMessage
=
e
.
message
??
''
;
}
}
on
Exception
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
toString
();
}
return
false
;
}
Future
<
AuthModel
?>
register
(
AuthModel
authModel
)
async
{
try
{
await
_auth
.
createUserWithEmailAndPassword
(
email:
authModel
.
email
,
password:
authModel
.
password
)
.
then
((
value
)
=>
{
debugPrint
(
"User registered
${value.user!.uid}
"
),
authModel
.
uid
=
value
.
user
!.
uid
,
});
return
authModel
;
}
on
FirebaseAuthException
catch
(
e
)
{
if
(
e
.
code
==
'email-already-in-use'
)
{
ErrorModel
.
errorMessage
=
'The account already exists for this email.'
;
}
else
if
(
e
.
code
==
'invalid-email'
)
{
ErrorModel
.
errorMessage
=
'Invalid email address.'
;
}
else
{
ErrorModel
.
errorMessage
=
e
.
message
??
''
;
}
return
null
;
}
on
Exception
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
toString
();
return
null
;
}
}
bool
isLoggedIn
()
{
_auth
.
userChanges
().
listen
((
User
?
user
)
{
if
(
user
==
null
)
{
debugPrint
(
'User is currently signed out!'
);
}
else
{
debugPrint
(
'User is signed in!'
);
}
});
return
_auth
.
currentUser
!=
null
;
}
Future
<
void
>
signOut
()
async
{
await
_auth
.
signOut
();
}
static
Future
<
void
>?
forgetPassword
(
String
email
)
async
{
try
{
return
await
_auth
.
sendPasswordResetEmail
(
email:
email
);
}
on
FirebaseAuthException
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
message
??
''
;
return
;
}
on
Exception
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
toString
();
return
;
}
}
}
FrontEnd/lib/services/disease_service.dart
0 → 100644
View file @
c24889e2
import
'package:cloud_firestore/cloud_firestore.dart'
;
import
'../models/error_model.dart'
;
class
DiseaseService
{
static
final
_leafs
=
FirebaseFirestore
.
instance
.
collection
(
'leafs'
);
static
Future
<
QuerySnapshot
<
Map
<
String
,
dynamic
>>?>
getLeafsById
(
int
id
)
async
{
QuerySnapshot
<
Map
<
String
,
dynamic
>>?
documentSnapshot
;
try
{
documentSnapshot
=
await
_leafs
.
where
(
'id'
,
isEqualTo:
id
).
get
();
}
on
FirebaseException
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
message
!;
}
on
Exception
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
toString
();
}
return
documentSnapshot
;
}
static
Future
<
QuerySnapshot
<
Map
<
String
,
dynamic
>>?>
getDiseaseById
(
String
leafRef
,
int
id
)
async
{
QuerySnapshot
<
Map
<
String
,
dynamic
>>?
documentSnapshot
;
try
{
documentSnapshot
=
await
_leafs
.
doc
(
leafRef
)
.
collection
(
"diseases"
)
.
where
(
'id'
,
isEqualTo:
id
)
.
get
();
}
on
FirebaseException
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
message
!;
}
on
Exception
catch
(
e
)
{
ErrorModel
.
errorMessage
=
e
.
toString
();
}
return
documentSnapshot
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment