去掉搜索 和 定位

This commit is contained in:
2024-11-17 21:55:44 +08:00
parent 542500a538
commit a0fc8a4395
334 changed files with 858 additions and 904 deletions

View File

@ -14,19 +14,17 @@ const _indicator = 'images/indicator.png';
double _fabHeight = 16.0;
typedef RequestPermission = Future<bool> Function();
typedef PoiItemBuilder = Widget Function(Poi poi, bool selected);
// typedef PoiItemBuilder = Widget Function(Poi poi, bool selected);
class LocationPicker extends StatefulWidget {
const LocationPicker({
required Key key,
required this.requestPermission,
required this.poiItemBuilder,
this.zoomLevel = 16.0,
this.zoomGesturesEnabled = false,
this.showZoomControl = false,
required this.centerIndicator,
this.enableLoadMore = true,
required this.onItemSelected,
}) : assert(zoomLevel >= 3 && zoomLevel <= 19),
super(key: key);
@ -34,7 +32,7 @@ class LocationPicker extends StatefulWidget {
final RequestPermission requestPermission;
/// Poi列表项Builder
final PoiItemBuilder poiItemBuilder;
// final PoiItemBuilder poiItemBuilder;
/// 显示的缩放登记
final double zoomLevel;
@ -52,7 +50,7 @@ class LocationPicker extends StatefulWidget {
final bool enableLoadMore;
/// 选中回调
final ValueChanged<PoiInfo> onItemSelected;
// final ValueChanged<PoiInfo> onItemSelected;
@override
_LocationPickerState createState() => _LocationPickerState();
@ -68,7 +66,7 @@ class _LocationPickerState extends State<LocationPicker>
bool _moveByUser = true;
// 当前请求到的poi列表
List<PoiInfo> _poiInfoList = [];
// List<PoiInfo> _poiInfoList = [];
// 当前地图中心点
late LatLng _currentCenterCoordinate;
@ -172,57 +170,76 @@ class _LocationPickerState extends State<LocationPicker>
],
),
panelBuilder: (scrollController) {
return StreamBuilder<List<PoiInfo>>(
stream: _poiStream.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
final data = snapshot.data;
return EasyRefresh(
footer: MaterialFooter(),
onLoad: widget.enableLoadMore ? _handleLoadMore : null,
child: ListView.builder(
padding: EdgeInsets.zero,
controller: scrollController,
shrinkWrap: true,
itemCount: data!.length,
itemBuilder: (context, index) {
final poi = data[index].poi;
final selected = data[index].selected;
return GestureDetector(
onTap: () {
// 遍历数据列表, 设置当前被选中的数据项
for (int i = 0; i < data.length; i++) {
data[i].selected = i == index;
}
// 如果索引是0, 说明是当前位置, 更新这个数据
_onMyLocation.add(index == 0);
// 刷新数据
_poiStream.add(data);
// 设置地图中心点
_setCenterCoordinate(poi.latLng!);
// 回调
widget.onItemSelected(data[index]);
},
child: widget.poiItemBuilder(poi, selected),
);
},
return Container(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'附近位置',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
SizedBox(height: 16),
// Expanded(
// child: _buildPoiList(scrollController),
// ),
],
),
);
// return StreamBuilder<List<PoiInfo>>(
// stream: _poiStream.stream,
// builder: (context, snapshot) {
// if (snapshot.hasData) {
// final data = snapshot.data;
// return EasyRefresh(
// footer: MaterialFooter(),
// onLoad: widget.enableLoadMore ? _handleLoadMore : null,
// child: ListView.builder(
// padding: EdgeInsets.zero,
// controller: scrollController,
// shrinkWrap: true,
// itemCount: data!.length,
// itemBuilder: (context, index) {
// final poi = data[index].poi;
// final selected = data[index].selected;
// return GestureDetector(
// onTap: () {
// // 遍历数据列表, 设置当前被选中的数据项
// for (int i = 0; i < data.length; i++) {
// data[i].selected = i == index;
// }
// // 如果索引是0, 说明是当前位置, 更新这个数据
// _onMyLocation.add(index == 0);
// // 刷新数据
// _poiStream.add(data);
// // 设置地图中心点
// _setCenterCoordinate(poi.latLng!);
// // 回调
// widget.onItemSelected(data[index]);
// },
// // child: widget.poiItemBuilder(poi, selected),
// );
// },
// ),
// );
// } else {
// return Center(child: CircularProgressIndicator());
// }
// },
// );
},
);
}
Future<void> _search(LatLng location) async {
final poiList = await AmapSearch.instance.searchAround(location);
_poiInfoList = poiList.map((poi) => PoiInfo(poi)).toList();
// final poiList = await AmapSearch.instance.searchAround(location);
// _poiInfoList = poiList.map((poi) => PoiInfo(poi)).toList();
// 默认勾选第一项
if (_poiInfoList.isNotEmpty) _poiInfoList[0].selected = true;
_poiStream.add(_poiInfoList);
// if (_poiInfoList.isNotEmpty) _poiInfoList[0].selected = true;
// _poiStream.add(_poiInfoList);
// 重置页数
_page = 1;
@ -242,25 +259,24 @@ class _LocationPickerState extends State<LocationPicker>
}
Future<void> _handleLoadMore() async {
final poiList = await AmapSearch.instance.searchAround(
_currentCenterCoordinate,
page: ++_page,
);
_poiInfoList.addAll(poiList.map((poi) => PoiInfo(poi)).toList());
_poiStream.add(_poiInfoList);
// final poiList = await AmapSearch.instance.searchAround(
// _currentCenterCoordinate,
// page: ++_page,
// );
// _poiInfoList.addAll(poiList.map((poi) => PoiInfo(poi)).toList());
// _poiStream.add(_poiInfoList);
}
}
mixin _BLoCMixin on State<LocationPicker> {
// poi流
final _poiStream = StreamController<List<PoiInfo>>();
// final _poiStream = StreamController<List<PoiInfo>>();
// 是否在我的位置
final _onMyLocation = StreamController<bool>();
@override
void dispose() {
_poiStream.close();
_onMyLocation.close();
super.dispose();
}

View File

@ -1,13 +1,13 @@
import 'package:amap_search_fluttify/amap_search_fluttify.dart';
class PoiInfo {
PoiInfo(this.poi);
final Poi poi;
bool selected = false;
@override
String toString() {
return 'PoiInfo{poi: $poi, selected: $selected}';
}
}
// import 'package:amap_search_fluttify/amap_search_fluttify.dart';
//
// class PoiInfo {
// PoiInfo(this.poi);
//
// final Poi poi;
// bool selected = false;
//
// @override
// String toString() {
// return 'PoiInfo{poi: $poi, selected: $selected}';
// }
// }