| | |
| | | import 'package:shared_preferences/shared_preferences.dart'; |
| | | import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
| | | import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'; |
| | | import 'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'; |
| | | import 'dart:convert' as convert; |
| | | |
| | | import 'package:locations/model/map/poi_model.dart'; |
| | | import 'package:shared_preferences/shared_preferences.dart'; |
| | | |
| | | class SearchUtil { |
| | | //添加搜索记录 |
| | | static addSearchRecord(BMFPoiInfo info) async { |
| | | static addSearchRecord(PoiModel info) async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | List<String>? list = prefs.getStringList("searchRecord"); |
| | | list ??= []; |
| | | |
| | | for (int i = 0; i < list.length; i++) { |
| | | BMFPoiInfo poiInfo =BMFPoiInfo.fromMap( convert.jsonDecode(list[i])); |
| | | PoiModel poiInfo = PoiModel.fromJson(convert.jsonDecode(list[i])); |
| | | if (poiInfo.address == info.address) { |
| | | list.removeAt(i); |
| | | break; |
| | |
| | | if (list.length > 10) { |
| | | list.removeRange(10, list.length); |
| | | } |
| | | list.add(convert.jsonEncode(info.toMap())); |
| | | list.add(convert.jsonEncode(info.toJson())); |
| | | |
| | | prefs.setStringList("searchRecord", list); |
| | | } |
| | | |
| | | ///获取记录 |
| | | static Future<List<BMFPoiInfo>> getRecordList() async { |
| | | static Future<List<PoiModel>> getRecordList() async { |
| | | SharedPreferences prefs = await SharedPreferences.getInstance(); |
| | | List<String>? list = prefs.getStringList("searchRecord"); |
| | | print(list); |
| | | list ??= []; |
| | | List<BMFPoiInfo> resultList = []; |
| | | List<PoiModel> resultList = []; |
| | | list.reversed.forEach((element) { |
| | | BMFPoiInfo info =BMFPoiInfo.fromMap( convert.jsonDecode(element)); |
| | | PoiModel info = PoiModel.fromJson(convert.jsonDecode(element)); |
| | | resultList.add(info); |
| | | }); |
| | | return resultList; |