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

add: search bar, currently constant

parent ec8eb361
No related branches found
No related tags found
1 merge request!10Clhp map
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:fuzzy/fuzzy.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'satellite_layer.dart';
import 'osm_layer.dart'; import 'osm_layer.dart';
import 'search_bar.dart';
import 'stat_charts.dart'; import 'stat_charts.dart';
import '../../consts.dart'; import '../../consts.dart';
import 'choropleth_map.dart'; import 'choropleth_map.dart';
import '../data_classes.dart'; import '../data_classes.dart';
import 'satellite_layer.dart';
import 'quick_view_chart.dart'; import 'quick_view_chart.dart';
/// MapContainerWidget is the main widget that contains the map with all /// MapContainerWidget is the main widget that contains the map with all
...@@ -88,10 +90,9 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -88,10 +90,9 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
return Column( return Column(
children: [ children: [
const SizedBox(height: contPadding), const SizedBox(height: contPadding),
/*if (true) { if (true) // NB temp always true
const SearchBar(), _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
...@@ -269,4 +270,53 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -269,4 +270,53 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
}, },
); );
} }
}
class _SearchBar extends StatelessWidget {
final width = 350.0; // NB pass value to class
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: SizedBox(
height: 35, // Adjust the height here
width: width,
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) {
searchLakeNames(value);
},
),
),
);
}
} }
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fuzzy/fuzzy.dart'; import 'package:fuzzy/fuzzy.dart';
class SearchBar extends StatelessWidget { /*
late List<String> testSearchNames = [ class _SearchBar extends StatelessWidget {
final List<String> testSearchNames = [
"Mjøsa", "Mjøsa",
"Bogstadsvannet", "Bogstadsvannet",
"Einavatnet", "Einavatnet",
...@@ -41,4 +42,4 @@ class SearchBar extends StatelessWidget { ...@@ -41,4 +42,4 @@ class SearchBar extends StatelessWidget {
), ),
); );
} }
} }*/
\ No newline at end of file \ 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