1-bottom sheet
2-details filter
3- animated to current location
4-
This commit is contained in:
2025-04-13 12:00:13 +03:30
parent 503dcd91b8
commit 28d43aa027
13 changed files with 529 additions and 99 deletions

View File

@@ -1,22 +1,32 @@
import 'dart:async';
import 'dart:developer';
import 'package:flutter/animation.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rasadyar_core/core.dart';
import 'package:supervision/data/utils/marker_generator.dart';
class SupervisionFilterLogic extends GetxController {
enum BottomSheetStep { filter, markerSelected, markerDetails }
class SupervisionFilterLogic extends GetxController
with GetTickerProviderStateMixin {
Rx<LatLng> currentLocation = LatLng(35.824891, 50.948025).obs;
RxList<LatLng> allMarkers = <LatLng>[].obs;
RxList<LatLng> markers = <LatLng>[].obs;
Timer? _debounceTimer;
RxBool isLoading = false.obs;
RxInt filterIndex = 0.obs;
RxInt showIndex = 0.obs;
Rx<BottomSheetStep> bottomSheetStep = BottomSheetStep.filter.obs;
Rx<MapController> mapController = MapController().obs;
late final AnimatedMapController animatedMapController;
RxBool isSelected = false.obs;
late Rx<DraggableBottomSheetController> sheetController;
Future<void> determineCurrentPosition() async {
bool serviceEnabled;
@@ -45,6 +55,12 @@ class SupervisionFilterLogic extends GetxController {
final latLng = LatLng(position.latitude, position.longitude);
currentLocation.value = latLng;
markers.add(latLng);
animatedMapController.animateTo(
dest: latLng,
zoom: 18,
curve: Curves.easeInOut,
duration: const Duration(seconds: 1),
);
}
void debouncedUpdateVisibleMarkers({required LatLng center}) {
@@ -77,13 +93,50 @@ class SupervisionFilterLogic extends GetxController {
Future<void> generatedMarkers() async {
final generatedMarkers = await generateLocationsUsingCompute(100000);
allMarkers.value = generatedMarkers;
}
@override
void onInit() {
super.onInit();
animatedMapController = AnimatedMapController(
vsync: this,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
cancelPreviousAnimations: true,
);
sheetController =
DraggableBottomSheetController(
initialVisibility: false,
initialHeight: 300,
minHeight: 50,
maxHeight: 600,
).obs;
bottomSheetStep.listen((data) {
if (data == BottomSheetStep.filter) {
sheetController =
DraggableBottomSheetController(
initialVisibility: false,
initialHeight: 300,
minHeight: 50,
maxHeight: 600,
).obs;
} else if (data == BottomSheetStep.markerSelected) {
sheetController =
DraggableBottomSheetController(
initialVisibility: true,
initialHeight: 150,
minHeight: 50,
maxHeight: 150,
).obs;
sheetController.refresh();
}
});
}
@override
void onReady() {
super.onReady();
determineCurrentPosition();
generatedMarkers();
}

View File

@@ -24,6 +24,7 @@ class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
children: [
ObxValue((currentLocation) {
return FlutterMap(
mapController: controller.animatedMapController.mapController,
options: MapOptions(
initialCenter: currentLocation.value,
initialZoom: 18,
@@ -45,10 +46,18 @@ class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
.map(
(marker) => Marker(
point: marker,
child: const Icon(
Icons.location_on,
color: Colors.red,
size: 30,
child: IconButton(
onPressed: () {
controller.bottomSheetStep.value =
BottomSheetStep.markerSelected;
},
icon: Icon(
Icons.location_on,
color: Colors.red,
size: 30,
),
),
),
)
@@ -59,116 +68,274 @@ class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
);
}, controller.currentLocation),
Positioned(
right: 10,
bottom: 150,
child: ObxValue((data) {
return RFab.small(
backgroundColor: AppColor.greenNormal,
isLoading: data.value,
icon: vecWidget(Assets.vecGpsSvg),
onPressed: () {
controller.isLoading.value = true;
controller.determineCurrentPosition().then(
(value) =>
controller.isLoading.value = !controller.isLoading.value,
);
},
);
}, controller.isLoading),
),
Positioned(
right: 10,
bottom: 100,
child: RFab.smallAdd(
child: RFab.small(
backgroundColor: AppColor.blueNormal,
icon: vecWidget(Assets.vecFilterSvg, width: 24, height: 24),
onPressed: () {
controller.isSelected.value = !controller.isSelected.value;
controller.sheetController.value.toggle();
},
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ObxValue((isSelected) {
return DraggableBottomSheet(isVisible: isSelected.value);
}, controller.isSelected),
child: ObxValue((data) {
return DraggableBottomSheet(
controller: data.value,
child: ObxValue((data) {
if (data.value == BottomSheetStep.filter) {
return filterWidget();
} else if (data.value == BottomSheetStep.markerSelected) {
return const SizedBox(
height: 150,
child: Center(child: Text('Marker Selected')),
);
} else {
return const SizedBox(
height: 150,
child: Center(child: Text('Noting')),
);
}
}, controller.bottomSheetStep),
);
}, controller.sheetController),
),
],
);
}
}
class DraggableBottomSheet extends StatefulWidget {
final bool isVisible;
final double initialHeight;
final double minHeight;
final double maxHeight;
const DraggableBottomSheet({
super.key,
required this.isVisible,
this.initialHeight = 200,
this.minHeight = 0,
this.maxHeight = 700,
});
@override
State<DraggableBottomSheet> createState() => _DraggableBottomSheetState();
}
class _DraggableBottomSheetState extends State<DraggableBottomSheet> {
late double _sheetHeight;
bool isWidgetVisible = false;
@override
void initState() {
super.initState();
_sheetHeight = widget.initialHeight;
isWidgetVisible = widget.isVisible;
}
void _onVerticalDragUpdate(DragUpdateDetails details) {
setState(() {
_sheetHeight -= details.delta.dy;
_sheetHeight = _sheetHeight.clamp(widget.minHeight, widget.maxHeight);
});
}
@override
void didUpdateWidget(covariant DraggableBottomSheet oldWidget) {
if (_sheetHeight <= oldWidget.initialHeight) {
setState(() {
isWidgetVisible = !isWidgetVisible;
});
}
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return AnimatedPositioned(
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
bottom: widget.isVisible ? 0 : -widget.maxHeight,
left: 0,
right: 0,
child: GestureDetector(
onVerticalDragUpdate: _onVerticalDragUpdate,
child: Container(
height: _sheetHeight,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(50)),
),
child: Column(
Padding filterWidget() {
return Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
spacing: 16,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
spacing: 16,
children: [
const SizedBox(height: 10),
Container(
width: 40,
height: 5,
width: 100,
height: 64,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadius.circular(5),
color: AppColor.blueLight,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: AppColor.blackLightHover),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text('دامداران', style: AppFonts.yekan10),
Text('183 عدد', style: AppFonts.yekan13Bold),
],
),
),
const SizedBox(height: 10),
Expanded(
child: ListView.builder(
itemCount: 15,
itemBuilder:
(context, index) =>
ListTile(title: Text('Item ${index + 1}')),
Container(
width: 100,
height: 64,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: AppColor.greenLight,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: AppColor.blackLightHover),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text('مرغداران', style: AppFonts.yekan10),
Text('183 عدد', style: AppFonts.yekan13Bold),
],
),
),
Container(
width: 100,
height: 64,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: AppColor.blueLight,
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: AppColor.blackLightHover),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text('اصناف', style: AppFonts.yekan10),
Text('183 عدد', style: AppFonts.yekan13Bold),
],
),
),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 12,
children: [
Text(
'فیلتر نمایش',
textAlign: TextAlign.center,
style: AppFonts.yekan13.copyWith(color: AppColor.blueNormal),
),
ObxValue((data) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 8,
children: [
customChip(
isSelected: data.value == 0,
onTap: (data) {
controller.filterIndex.value = data;
},
index: 0,
title: 'دامداران',
),
customChip(
isSelected: data.value == 1,
title: 'مرغداران',
onTap: (data) {
controller.filterIndex.value = data;
},
index: 1,
),
customChip(
isSelected: data.value == 2,
title: 'اصناف',
onTap: (data) {
controller.filterIndex.value = data;
},
index: 2,
),
],
);
}, controller.filterIndex),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 12,
children: [
Text(
'نمایش',
textAlign: TextAlign.center,
style: AppFonts.yekan13.copyWith(color: AppColor.blueNormal),
),
ObxValue((data) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 8,
children: [
customChip(
isSelected: data.value == 0,
title: 'نمایش همه',
onTap: (data) {
controller.showIndex.value = data;
},
index: 0,
),
customChip(
isSelected: data.value == 1,
title: 'دارای تراکنش',
onTap: (data) {
controller.showIndex.value = data;
},
index: 1,
),
customChip(
isSelected: data.value == 2,
title: 'بازرسی شده ها',
onTap: (data) {
controller.showIndex.value = data;
},
index: 2,
),
customChip(
isSelected: data.value == 3,
title: 'بازرسی نشده ها',
onTap: (data) {
controller.showIndex.value = data;
},
index: 3,
),
customChip(
isSelected: data.value == 4,
title: 'متخلفین',
onTap: (data) {
controller.showIndex.value = data;
},
index: 4,
),
],
),
);
}, controller.showIndex),
],
),
],
),
);
}
}
Widget customChip({
bool isSelected = false,
required String title,
required int index,
required Function(int) onTap,
}) {
return GestureDetector(
onTap: () {
onTap.call(index);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: isSelected ? AppColor.blueNormal : AppColor.whiteGreyNormal,
borderRadius: BorderRadius.circular(8),
border:
isSelected
? Border.fromBorderSide(BorderSide.none)
: Border.all(width: 0.25, color: const Color(0xFFB0B0B0)),
),
child: Text(
title,
textAlign: TextAlign.center,
style:
isSelected
? AppFonts.yekan10.copyWith(color: AppColor.whiteLight)
: AppFonts.yekan10,
),
),
);
}