integrated with previous
This commit is contained in:
@ -1,10 +1,183 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rogapp/common/ui/widgets/uis.dart';
|
||||
import 'package:rogapp/model/location_response.dart';
|
||||
import 'package:rogapp/screens/home/home_controller.dart';
|
||||
import 'package:rogapp/screens/home/location_controller.dart';
|
||||
import 'package:rogapp/theme/theme.dart';
|
||||
import 'package:rogapp/utils/db_helper.dart';
|
||||
import 'package:rogapp/utils/text_util.dart';
|
||||
import 'package:rogapp/widgets/base_layer_widget.dart';
|
||||
import 'package:rogapp/widgets/bottom_sheet_new.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({super.key});
|
||||
HomeScreen({super.key});
|
||||
StreamSubscription? subscription;
|
||||
final HomeController homeController = Get.find<HomeController>();
|
||||
final LocationController locationController = Get.find<LocationController>();
|
||||
|
||||
final double zoomThreshold = 0.08;
|
||||
final double boundsThreshold = 0.0005;
|
||||
|
||||
LatLngBounds? lastBounds;
|
||||
double? lastZoom;
|
||||
|
||||
|
||||
Widget getMarkerShape(Feature i, BuildContext context){
|
||||
|
||||
//print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
|
||||
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
homeController.currentFeature.assign(i);
|
||||
if(homeController.currentFeature != null) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
isDismissible: true,
|
||||
builder:((context) => BottomSheetNew())
|
||||
//builder:((context) => BottomSheetWidget())
|
||||
).whenComplete((){
|
||||
locationController.skip_gps = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
child: Container(
|
||||
height: 32,
|
||||
width: 32,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.transparent,
|
||||
border: Border.all(
|
||||
color: i.properties!.buy_point! > 0 ? Colors.blue : Colors.red,
|
||||
width: 3,
|
||||
style: BorderStyle.solid
|
||||
)
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Icon(Icons.circle,size: 6.0,),
|
||||
i.properties!.cp == -1 ?
|
||||
Transform.rotate(
|
||||
alignment: Alignment.centerLeft,
|
||||
origin: Offset.fromDirection(1, 26),
|
||||
angle: 270 * pi / 180,
|
||||
child: Icon(Icons.play_arrow_outlined, color: Colors.red, size: 70,)):
|
||||
Container(color: Colors.transparent,),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
Container(color: Colors.white, child: Text(TextUtils.getDisplayTextForFeature(i), style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color:Colors.red,))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Placeholder();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
TextButton(onPressed: () async {
|
||||
DatabaseHelper dbaseHelper = DatabaseHelper.instance;
|
||||
final res = await dbaseHelper.getFeatureByLatLon(35.807369, 137.240684);
|
||||
print(res[0].toString());
|
||||
},
|
||||
child: const Text("Click", style: TextStyle(color: Colors.white),))
|
||||
],
|
||||
),
|
||||
body: Obx(() =>
|
||||
FlutterMap(
|
||||
mapController: homeController.mapController,
|
||||
options: MapOptions(
|
||||
onMapReady: (){
|
||||
homeController.mapController!.mapEventStream.listen((MapEvent mapEvent) {
|
||||
if (mapEvent is MapEventMoveStart) {
|
||||
}
|
||||
if (mapEvent is MapEventMoveEnd) {
|
||||
LatLngBounds bounds = homeController.mapController!.bounds!;
|
||||
homeController.currentBound.assign(bounds);
|
||||
final _cz = homeController.mapController.zoom;
|
||||
}
|
||||
});
|
||||
} ,
|
||||
onPositionChanged: (position, hasGesture){
|
||||
if (hasGesture) {
|
||||
LatLngBounds currentBounds = position.bounds!;
|
||||
|
||||
if (lastBounds != null && lastZoom != null) {
|
||||
// Compute difference between last bounds and current bounds
|
||||
double boundsDifference = lastBounds!.north - currentBounds.north +
|
||||
lastBounds!.south - currentBounds.south +
|
||||
lastBounds!.east - currentBounds.east +
|
||||
lastBounds!.west - currentBounds.west;
|
||||
|
||||
// Compute difference between last zoom and current zoom
|
||||
double zoomDifference = lastZoom! - position.zoom!;
|
||||
|
||||
if (boundsDifference.abs() > boundsThreshold || zoomDifference.abs() > zoomThreshold) {
|
||||
LatLngBounds bounds = homeController.mapController!.bounds!;
|
||||
homeController.currentBound.assign(bounds);
|
||||
print('----threshold reached ---');
|
||||
homeController.fetchLocalLocationForBound(bounds);
|
||||
//loadData(position.bounds); // Load new data when either threshold is exceeded
|
||||
}
|
||||
} else {
|
||||
LatLngBounds bounds = homeController.mapController!.bounds!;
|
||||
homeController.currentBound.assign(bounds);
|
||||
homeController.fetchLocalLocationForBound(bounds);
|
||||
//loadData(position.bounds); // Load new data if this is the first time
|
||||
}
|
||||
|
||||
lastBounds = currentBounds; // Update the last bounds
|
||||
lastZoom = position.zoom; // Update the last zoom
|
||||
|
||||
}
|
||||
},
|
||||
bounds: homeController.currentBound.isNotEmpty ? homeController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]),
|
||||
zoom: 14,
|
||||
maxZoom:18.4,
|
||||
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
|
||||
),
|
||||
children: [
|
||||
const BaseLayer(),
|
||||
CurrentLocationLayer(),
|
||||
homeController.currentFeaturesforBound.isNotEmpty ?
|
||||
MarkerLayer(
|
||||
markers:homeController.currentFeaturesforBound.map((i) {
|
||||
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
|
||||
return Marker(
|
||||
anchorPos: AnchorPos.exactly(Anchor(108.0, 18.0)),
|
||||
height: 32.0,
|
||||
width: 120.0,
|
||||
point: LatLng(i.latitude!, i.longitude!),
|
||||
builder: (ctx){
|
||||
return getMarkerShape(i, context);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
:
|
||||
Center(child: CircularProgressIndicator()),
|
||||
],
|
||||
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user