Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
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
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
Sara Savanovic Djordjevic
PROG2900
Commits
3775c77b
Commit
3775c77b
authored
11 months ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: new search bar approach
parent
8571677d
No related branches found
No related tags found
1 merge request
!10
Clhp map
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/pages/default_page.dart
+79
-4
79 additions, 4 deletions
app/lib/pages/default_page.dart
app/lib/widgets/main_layout.dart
+1
-70
1 addition, 70 deletions
app/lib/widgets/main_layout.dart
app/lib/widgets/search_bar.dart
+0
-45
0 additions, 45 deletions
app/lib/widgets/search_bar.dart
with
80 additions
and
119 deletions
app/lib/pages/default_page.dart
+
79
−
4
View file @
3775c77b
import
'dart:async'
;
import
'dart:typed_data'
;
import
'package:fuzzy/fuzzy.dart'
;
import
'package:flutter/material.dart'
;
import
'../consts.dart'
;
...
...
@@ -18,7 +19,6 @@ class DefaultPage extends StatefulWidget {
class
_DefaultPageState
extends
State
<
DefaultPage
>
{
late
Timer
_timer
;
bool
showBar
=
false
;
bool
serverConnection
=
true
;
bool
dialogShown
=
false
;
...
...
@@ -111,9 +111,12 @@ class _DefaultPageState extends State<DefaultPage> {
color:
Colors
.
white54
),
onPressed:
()
{
setState
(()
{
showSearch
(
context:
context
,
delegate:
_CustomSearchDelegate
());
/*setState(() {
showBar = !showBar;
});
});
*/
},
),
],
...
...
@@ -132,7 +135,6 @@ class _DefaultPageState extends State<DefaultPage> {
markerList:
markerList
,
relation:
relation
,
serverConnection:
serverConnection
,
showSearchBar:
showBar
,
),
],
),
...
...
@@ -143,3 +145,76 @@ class _DefaultPageState extends State<DefaultPage> {
);
}
}
class
_CustomSearchDelegate
extends
SearchDelegate
{
List
<
String
>
searchItems
=
[
// NB temp values
"Mjøsa"
,
"Bogstadsvannet"
,
"Einavatnet"
,
"Femsjøen"
,
"Femunden"
,
"Fjellsjøen"
,
"Gjende"
,
"Gjersjøen"
];
@override
List
<
Widget
>
buildActions
(
BuildContext
context
)
{
return
[
IconButton
(
// Clear query
icon:
const
Icon
(
Icons
.
clear
),
onPressed:
()
{
query
=
''
;
},
)
];
}
@override
Widget
buildLeading
(
BuildContext
context
)
{
return
IconButton
(
// Close search bar
icon:
const
Icon
(
Icons
.
arrow_back
),
onPressed:
()
{
close
(
context
,
null
);
},
);
}
@override
Widget
buildResults
(
BuildContext
context
)
{
List
<
String
>
searchResults
=
[];
final
options
=
FuzzyOptions
(
threshold:
0.3
,
findAllMatches:
true
);
final
matcher
=
Fuzzy
(
searchItems
,
options:
options
);
final
results
=
matcher
.
search
(
query
);
searchResults
=
results
.
map
((
result
)
=
>
result
.
item
as
String
)
.
toList
();
return
ListView
.
builder
(
itemCount:
searchResults
.
length
,
itemBuilder:
(
context
,
index
)
{
var
result
=
searchResults
[
index
];
return
ListTile
(
title:
Text
(
result
),
);
},
);
}
@override
Widget
buildSuggestions
(
BuildContext
context
)
{
List
<
String
>
searchResults
=
[];
final
options
=
FuzzyOptions
(
threshold:
0.3
,
findAllMatches:
true
);
final
matcher
=
Fuzzy
(
searchItems
,
options:
options
);
final
results
=
matcher
.
search
(
query
);
searchResults
=
results
.
map
((
result
)
=
>
result
.
item
as
String
)
.
toList
();
return
ListView
.
builder
(
itemCount:
searchResults
.
length
,
itemBuilder:
(
context
,
index
)
{
var
result
=
searchResults
[
index
];
return
ListTile
(
title:
Text
(
result
),
);
},
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/lib/widgets/main_layout.dart
+
1
−
70
View file @
3775c77b
...
...
@@ -6,7 +6,6 @@ import 'package:google_fonts/google_fonts.dart';
import
'package:shared_preferences/shared_preferences.dart'
;
import
'osm_layer.dart'
;
import
'search_bar.dart'
;
import
'stat_charts.dart'
;
import
'../../consts.dart'
;
import
'choropleth_map.dart'
;
...
...
@@ -20,13 +19,11 @@ class MapContainerWidget extends StatefulWidget {
final
List
<
Measurement
>
markerList
;
final
Uint8List
relation
;
final
bool
serverConnection
;
final
bool
showSearchBar
;
const
MapContainerWidget
({
Key
?
key
,
required
this
.
markerList
,
required
this
.
relation
,
required
this
.
serverConnection
,
required
this
.
showSearchBar
})
:
super
(
key:
key
);
@override
...
...
@@ -91,17 +88,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
double
boxHeight
=
1.4
;
return
Column
(
children:
[
const
SizedBox
(
height:
12
),
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
),
child:
AnimatedOpacity
(
duration:
const
Duration
(
milliseconds:
300
),
curve:
Curves
.
easeInOut
,
opacity:
widget
.
showSearchBar
?
1.0
:
0.0
,
child:
const
_SearchBar
(
width:
350
),
// NB temp hardcoded value
),
),
const
SizedBox
(
height:
12
),
const
SizedBox
(
height:
contPadding
*
1.5
),
ClipRRect
(
borderRadius:
BorderRadius
.
circular
(
20
),
child:
Stack
(
// Stack of quick view, map layer, satellite layer, and buttons
...
...
@@ -280,59 +267,3 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
);
}
}
class _SearchBar extends StatefulWidget {
final double width;
const _SearchBar({
Key? key,
required this.width,
}) : super(key: key);
@override
_SearchBarState createState() => _SearchBarState();
}
class _SearchBarState extends State<_SearchBar> {
final List<String> testSearchNames = [
"Mjøsa",
"Bogstadsvannet",
"Einavatnet",
"Femsjøen",
"Femunden",
"Fjellsjøen",
"Gjende",
"Gjersjøen"
];
List<String> searchLakeNames(String query) {
final options = FuzzyOptions(threshold: 0.3, findAllMatches: true);
final matcher = Fuzzy(testSearchNames, options: options);
final results = matcher.search(query);
return results.map((result) => result.item as String).toList();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: SizedBox(
width: widget.width,
height: 32,
child: TextField(
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
hintText: '
Search
...
',
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15.0),
),
),
onChanged: (value) {
setState(() {}); // Trigger a rebuild when the text changes
searchLakeNames(value);
},
),
),
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/lib/widgets/search_bar.dart
deleted
100644 → 0
+
0
−
45
View file @
8571677d
import
'package:flutter/material.dart'
;
import
'package:fuzzy/fuzzy.dart'
;
/*
class _SearchBar extends StatelessWidget {
final List<String> testSearchNames = [
"Mjøsa",
"Bogstadsvannet",
"Einavatnet",
"Femsjøen",
"Femunden",
"Fjellsjøen",
"Gjende",
"Gjersjøen"
];
// Searching function for lake names using Fuzzy library
List<String> searchLakeNames(String query) {
final options = FuzzyOptions(threshold: 0.3, findAllMatches: true);
final matcher = Fuzzy(testSearchNames, options: options);
final results = matcher.search(query);
// Extracting lake names from the results and casting them to strings
return results.map((result) => result.item as String).toList();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
decoration: InputDecoration(
hintText: 'Search...',
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
onChanged: (value) {
searchLakeNames(value);
},
),
);
}
}*/
\ No newline at end of file
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