Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
1e1a8c38
Commit
1e1a8c38
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
enhanced input validation
parent
36535a23
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/addevent.dart
+142
-40
142 additions, 40 deletions
lib/addevent.dart
with
142 additions
and
40 deletions
lib/addevent.dart
+
142
−
40
View file @
1e1a8c38
...
...
@@ -20,8 +20,6 @@ class _AddEventPageState extends State<AddEvent> {
late
String
alt
=
""
;
late
double
accuracy
=
0.0
;
late
StreamSubscription
<
Position
>
streamHandler
;
//For canceling GNSS stream on dispose
bool
_labelValidate
=
false
;
bool
_descriptionValidate
=
false
;
Future
startGNSS
()
async
{
debugPrint
(
"Check Location Permission"
);
...
...
@@ -100,13 +98,58 @@ class _AddEventPageState extends State<AddEvent> {
super
.
dispose
();
}
bool
_validateLatitude
(
value
){
if
(
value
==
""
){
return
true
;
//Empty string is valid
}
var
number
=
num
.
tryParse
(
value
);
if
(
number
!=
null
){
if
(
number
>
=
-
90.0
&&
number
<
=
90.0
){
return
true
;
// Latitude valid
}
}
return
false
;
}
bool
_validateLongitude
(
value
){
if
(
value
==
""
){
return
true
;
//Empty string is valid
}
var
number
=
num
.
tryParse
(
value
);
if
(
number
!=
null
){
if
(
number
>
=
-
180.0
&&
number
<
=
180.0
){
return
true
;
// Longitude valid
}
}
return
false
;
}
bool
_validateElevation
(
value
){
if
(
value
==
""
){
return
true
;
//Empty string is valid
}
var
number
=
num
.
tryParse
(
value
);
if
(
number
!=
null
){
return
true
;
// Any numerical value is valid for elevation
}
return
false
;
}
bool
_validateInput
(){
final
EventStoreInstance
eventsStore
=
EventStoreInstance
();
if
(
RegExp
(
r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$'
)
.
hasMatch
(
eventsStore
.
currentEvent
.
label
))
{
if
(
RegExp
(
r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$'
)
.
hasMatch
(
eventsStore
.
currentEvent
.
description
))
{
return
true
;
if
(
_validateLatitude
(
eventsStore
.
currentEvent
.
latitude
)){
if
(
_validateLongitude
(
eventsStore
.
currentEvent
.
longitude
)){
if
(
_validateElevation
(
eventsStore
.
currentEvent
.
elevation
)){
debugPrint
(
'All inputs valid'
);
return
true
;
}
}
}
}
}
return
false
;
...
...
@@ -185,11 +228,8 @@ class _AddEventPageState extends State<AddEvent> {
validator:
(
value
)
{
if
(
!
RegExp
(
r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$'
)
.
hasMatch
(
value
!
))
{
_labelValidate
=
false
;
return
"Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :"
;
}
else
{
_labelValidate
=
true
;
//eventsStore.currentEvent.label = value;
return
null
;
// Entered Text is valid
}
},
...
...
@@ -249,10 +289,8 @@ class _AddEventPageState extends State<AddEvent> {
validator:
(
value
)
{
if
(
!
RegExp
(
r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$'
)
.
hasMatch
(
value
!
))
{
_descriptionValidate
=
false
;
return
"Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :"
;
}
else
{
_descriptionValidate
=
true
;
//eventsStore.currentEvent.label = value;
return
null
;
// Entered Text is valid
}
...
...
@@ -302,46 +340,102 @@ class _AddEventPageState extends State<AddEvent> {
),
const
SizedBox
(
height:
15.0
),
TextFormField
(
readOnly:
false
,
enabled:
!
syncGNSSData
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
latitude
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Latitude'
,
border:
OutlineInputBorder
(),
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
latitude
=
value
;
readOnly:
false
,
enabled:
!
syncGNSSData
,
keyboardType:
TextInputType
.
number
,
autovalidateMode:
AutovalidateMode
.
onUserInteraction
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
latitude
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Latitude'
,
border:
OutlineInputBorder
(),
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
latitude
=
value
;
},
onFieldSubmitted:
(
value
){
if
(
!
syncGNSSData
)
{
setState
(()
{});
}
},
validator:
(
value
)
{
if
(
value
==
""
)
{
return
null
;
// Empty value is allowed
}
final
number
=
num
.
tryParse
(
value
!
);
if
(
number
!=
null
){
if
(
number
>
=
-
90.0
&&
number
<
=
90.0
){
return
null
;
// Latitude valid
}
}
return
"-90 => Latitude <= +90"
;
},
),
const
SizedBox
(
height:
15.0
),
TextFormField
(
readOnly:
false
,
enabled:
!
syncGNSSData
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
longitude
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Longitude'
,
border:
OutlineInputBorder
(),
readOnly:
false
,
enabled:
!
syncGNSSData
,
keyboardType:
TextInputType
.
number
,
autovalidateMode:
AutovalidateMode
.
onUserInteraction
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
longitude
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Longitude'
,
border:
OutlineInputBorder
(),
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
longitude
=
value
;
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
longitude
=
value
;
},
onFieldSubmitted:
(
value
){
if
(
!
syncGNSSData
)
{
setState
(()
{});
}
},
validator:
(
value
)
{
if
(
value
==
""
)
{
return
null
;
// Empty value is allowed
}
final
number
=
num
.
tryParse
(
value
!
);
if
(
number
!=
null
){
if
(
number
>
=
-
180.0
&&
number
<
=
180.0
){
return
null
;
// Longitude valid
}
}
return
"-180 => Longitude <= +180"
;
},
),
const
SizedBox
(
height:
15.0
),
TextFormField
(
readOnly:
false
,
enabled:
!
syncGNSSData
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
elevation
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Elevation'
,
border:
OutlineInputBorder
(),
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
elevation
=
value
;
readOnly:
false
,
enabled:
!
syncGNSSData
,
keyboardType:
TextInputType
.
number
,
autovalidateMode:
AutovalidateMode
.
onUserInteraction
,
controller:
TextEditingController
(
text:
eventsStore
.
currentEvent
.
elevation
.
toString
()),
decoration:
const
InputDecoration
(
labelText:
'Elevation'
,
border:
OutlineInputBorder
(),
),
onChanged:
(
value
)
{
eventsStore
.
currentEvent
.
elevation
=
value
;
},
onFieldSubmitted:
(
value
){
if
(
!
syncGNSSData
)
{
setState
(()
{});
}
},
validator:
(
value
)
{
if
(
value
==
""
)
{
return
null
;
// Empty value is allowed
}
final
number
=
num
.
tryParse
(
value
!
);
if
(
number
!=
null
){
return
null
;
// Elevation valid
}
return
"Only numerical values for elevation in [m]"
;
},
),
]
),
...
...
@@ -368,8 +462,13 @@ class _AddEventPageState extends State<AddEvent> {
child:
_validateInput
()
?
FloatingActionButton
(
onPressed:
()
{
_storeCurrentEvent
();
HapticFeedback
.
vibrate
();
if
(
_validateInput
())
{
_storeCurrentEvent
();
HapticFeedback
.
vibrate
();
}
else
{
setState
(()
{});
}
},
tooltip:
'Add Event'
,
child:
const
Icon
(
Icons
.
check
),
...
...
@@ -378,6 +477,9 @@ class _AddEventPageState extends State<AddEvent> {
enableFeedback:
false
,
backgroundColor:
Colors
.
grey
,
onPressed:
()
{
setState
(()
{
//refresh the UI
});
},
tooltip:
'Correct Inputs before adding the Event'
,
//child: const Icon(Icons.check),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment