Skip to content
Snippets Groups Projects
Commit ec8eb361 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

add: search_bar.dart

parent 1e90cf64
No related branches found
No related tags found
1 merge request!10Clhp map
import 'dart:async'; import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:fuzzy/fuzzy.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../consts.dart'; import '../consts.dart';
...@@ -26,26 +25,6 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -26,26 +25,6 @@ class _DefaultPageState extends State<DefaultPage> {
late Future<List<Measurement>> markerListFuture; late Future<List<Measurement>> markerListFuture;
late Future<Uint8List> relationFuture; late Future<Uint8List> relationFuture;
late 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 @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -142,33 +121,6 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -142,33 +121,6 @@ class _DefaultPageState extends State<DefaultPage> {
body: FutureBuilder( body: FutureBuilder(
future: Future.wait([markerListFuture, relationFuture]), future: Future.wait([markerListFuture, relationFuture]),
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) { builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
// Display loading screen while app state is being set
if (snapshot.connectionState == ConnectionState.waiting) {
return Container(
decoration: const BoxDecoration( // Loading screen
color: darkestBlue,
),
child: Center(
child: Image.asset(
'assets/icons/frozen.png', // Loading screen icon
// Icon from: https://www.flaticon.com/free-icons/cold-water"
color: lightBlue,
width: 170,
height: 170,
),
),
);
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else {
// If no server connection, alert user upon completing build
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!serverConnection && !dialogShown) {
dialogShown = true;
showConnectionMessage();
}
});
List<Measurement> markerList = snapshot.data![0] as List<Measurement>; List<Measurement> markerList = snapshot.data![0] as List<Measurement>;
Uint8List relation = snapshot.data![1] as Uint8List; Uint8List relation = snapshot.data![1] as Uint8List;
...@@ -185,7 +137,6 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -185,7 +137,6 @@ class _DefaultPageState extends State<DefaultPage> {
), ),
); );
} }
},
), ),
), ),
); );
......
...@@ -88,9 +88,10 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -88,9 +88,10 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
return Column( return Column(
children: [ children: [
const SizedBox(height: contPadding), const SizedBox(height: contPadding),
/*if (true) NB: add search bar /*if (true) {
const SearchBar(), const SearchBar(),
const SizedBox(height: contPadding),*/ const SizedBox(height: contPadding),
},*/
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
child: Stack( // Stack of quick view, map layer, satellite layer, and buttons child: Stack( // Stack of quick view, map layer, satellite layer, and buttons
......
import 'package:flutter/material.dart';
import 'package:fuzzy/fuzzy.dart';
class SearchBar extends StatelessWidget {
late 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment