fix:
1-bottom sheet 2-details filter 3- animated to current location 4-
This commit is contained in:
3
assets/icons/gps.svg
Normal file
3
assets/icons/gps.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M22 11.25H19.96C19.6 7.44 16.56 4.39 12.75 4.04V2C12.75 1.59 12.41 1.25 12 1.25C11.59 1.25 11.25 1.59 11.25 2V4.04C7.44 4.4 4.39 7.44 4.04 11.25H2C1.59 11.25 1.25 11.59 1.25 12C1.25 12.41 1.59 12.75 2 12.75H4.04C4.4 16.56 7.44 19.61 11.25 19.96V22C11.25 22.41 11.59 22.75 12 22.75C12.41 22.75 12.75 22.41 12.75 22V19.96C16.56 19.6 19.61 16.56 19.96 12.75H22C22.41 12.75 22.75 12.41 22.75 12C22.75 11.59 22.41 11.25 22 11.25ZM12 15.12C10.28 15.12 8.88 13.72 8.88 12C8.88 10.28 10.28 8.88 12 8.88C13.72 8.88 15.12 10.28 15.12 12C15.12 13.72 13.72 15.12 12 15.12Z" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 689 B |
BIN
assets/vec/gps.svg.vec
Normal file
BIN
assets/vec/gps.svg.vec
Normal file
Binary file not shown.
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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,12 +46,20 @@ class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
|
||||
.map(
|
||||
(marker) => Marker(
|
||||
point: marker,
|
||||
child: const Icon(
|
||||
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
controller.bottomSheetStep.value =
|
||||
BottomSheetStep.markerSelected;
|
||||
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.location_on,
|
||||
color: Colors.red,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
@@ -61,114 +70,272 @@ class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
|
||||
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 100,
|
||||
child: RFab.smallAdd(
|
||||
bottom: 150,
|
||||
child: ObxValue((data) {
|
||||
return RFab.small(
|
||||
backgroundColor: AppColor.greenNormal,
|
||||
isLoading: data.value,
|
||||
icon: vecWidget(Assets.vecGpsSvg),
|
||||
onPressed: () {
|
||||
controller.isSelected.value = !controller.isSelected.value;
|
||||
controller.isLoading.value = true;
|
||||
controller.determineCurrentPosition().then(
|
||||
(value) =>
|
||||
controller.isLoading.value = !controller.isLoading.value,
|
||||
);
|
||||
},
|
||||
);
|
||||
}, controller.isLoading),
|
||||
),
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 100,
|
||||
child: RFab.small(
|
||||
backgroundColor: AppColor.blueNormal,
|
||||
icon: vecWidget(Assets.vecFilterSvg, width: 24, height: 24),
|
||||
onPressed: () {
|
||||
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)),
|
||||
Padding filterWidget() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
spacing: 16,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
spacing: 16,
|
||||
children: [
|
||||
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: [
|
||||
const SizedBox(height: 10),
|
||||
Text('دامداران', style: AppFonts.yekan10),
|
||||
Text('183 عدد', style: AppFonts.yekan13Bold),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 5,
|
||||
width: 100,
|
||||
height: 64,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[400],
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
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.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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.1.1"
|
||||
flutter_map_animations:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_map_animations
|
||||
sha256: bf583863561861aaaf4854ae7ed8940d79bea7d32918bf7a85d309b25235a09e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.0"
|
||||
flutter_svg:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -12,6 +12,7 @@ dependencies:
|
||||
rasadyar_core:
|
||||
path: ./../../packages/core
|
||||
flutter_map: ^8.1.1
|
||||
flutter_map_animations: ^0.9.0
|
||||
location: ^8.0.0
|
||||
latlong2: ^0.9.1
|
||||
geolocator: ^13.0.4
|
||||
|
||||
@@ -9,6 +9,7 @@ class Assets {
|
||||
static const String iconsDownload = 'assets/icons/download.svg';
|
||||
static const String iconsEdit = 'assets/icons/edit.svg';
|
||||
static const String iconsFilter = 'assets/icons/filter.svg';
|
||||
static const String iconsGps = 'assets/icons/gps.svg';
|
||||
static const String iconsKey = 'assets/icons/key.svg';
|
||||
static const String iconsMap = 'assets/icons/map.svg';
|
||||
static const String iconsMapMarker = 'assets/icons/map_marker.svg';
|
||||
@@ -25,6 +26,7 @@ class Assets {
|
||||
static const String vecDownloadSvg = 'assets/vec/download.svg.vec';
|
||||
static const String vecEditSvg = 'assets/vec/edit.svg.vec';
|
||||
static const String vecFilterSvg = 'assets/vec/filter.svg.vec';
|
||||
static const String vecGpsSvg = 'assets/vec/gps.svg.vec';
|
||||
static const String vecKeySvg = 'assets/vec/key.svg.vec';
|
||||
static const String vecMapMarkerSvg = 'assets/vec/map_marker.svg.vec';
|
||||
static const String vecMapSvg = 'assets/vec/map.svg.vec';
|
||||
|
||||
@@ -9,6 +9,7 @@ class Assets {
|
||||
static const String iconsDownload = 'assets/icons/download.svg';
|
||||
static const String iconsEdit = 'assets/icons/edit.svg';
|
||||
static const String iconsFilter = 'assets/icons/filter.svg';
|
||||
static const String iconsGps = 'assets/icons/gps.svg';
|
||||
static const String iconsKey = 'assets/icons/key.svg';
|
||||
static const String iconsMap = 'assets/icons/map.svg';
|
||||
static const String iconsMapMarker = 'assets/icons/map_marker.svg';
|
||||
@@ -25,6 +26,7 @@ class Assets {
|
||||
static const String vecDownloadSvg = 'assets/vec/download.svg.vec';
|
||||
static const String vecEditSvg = 'assets/vec/edit.svg.vec';
|
||||
static const String vecFilterSvg = 'assets/vec/filter.svg.vec';
|
||||
static const String vecGpsSvg = 'assets/vec/gps.svg.vec';
|
||||
static const String vecKeySvg = 'assets/vec/key.svg.vec';
|
||||
static const String vecMapMarkerSvg = 'assets/vec/map_marker.svg.vec';
|
||||
static const String vecMapSvg = 'assets/vec/map.svg.vec';
|
||||
|
||||
@@ -5,16 +5,15 @@ import 'package:rasadyar_core/presentation/utils/color_utils.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/vec_widget.dart';
|
||||
|
||||
class RFab extends StatefulWidget {
|
||||
|
||||
|
||||
final VoidCallback? onPressed;
|
||||
Color? foregroundColor;
|
||||
Color? backgroundColor;
|
||||
Color? disabledForegroundColor;
|
||||
Color? disabledBackgroundColor;
|
||||
double? radius;
|
||||
double radius;
|
||||
ShapeBorder? shapeBorder;
|
||||
Widget? icon;
|
||||
bool isLoading;
|
||||
|
||||
@override
|
||||
State<RFab> createState() => _RFabState();
|
||||
@@ -177,6 +176,7 @@ class RFab extends StatefulWidget {
|
||||
required this.icon,
|
||||
required this.backgroundColor,
|
||||
super.key,
|
||||
this.isLoading = false,
|
||||
}) : radius = 40.0,
|
||||
foregroundColor = Colors.white;
|
||||
|
||||
@@ -184,6 +184,7 @@ class RFab extends StatefulWidget {
|
||||
required this.onPressed,
|
||||
required this.icon,
|
||||
required this.backgroundColor,
|
||||
this.isLoading = false,
|
||||
super.key,
|
||||
}) : radius = 56.0,
|
||||
foregroundColor = Colors.white;
|
||||
@@ -195,7 +196,7 @@ class _RFabState extends State<RFab> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: widget.onPressed,
|
||||
onPressed: widget.isLoading == false ? widget.onPressed : null,
|
||||
style: ButtonStyle(
|
||||
side: WidgetStateProperty.all(BorderSide.none),
|
||||
backgroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
|
||||
@@ -226,7 +227,19 @@ class _RFabState extends State<RFab> {
|
||||
),
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
),
|
||||
child: widget.icon,
|
||||
child:
|
||||
widget.isLoading
|
||||
? SizedBox(
|
||||
height: widget.radius / 2,
|
||||
width: widget.radius / 2,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
widget.foregroundColor ?? Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: widget.icon,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/draggable_bottom_sheet/draggable_bottom_sheet_controller.dart';
|
||||
|
||||
class DraggableBottomSheet extends StatelessWidget {
|
||||
final DraggableBottomSheetController? controller;
|
||||
final bool isVisible;
|
||||
final double initialHeight;
|
||||
final double minHeight;
|
||||
final double maxHeight;
|
||||
final Widget? child;
|
||||
|
||||
const DraggableBottomSheet({
|
||||
super.key,
|
||||
this.controller,
|
||||
this.isVisible = false,
|
||||
this.initialHeight = 200,
|
||||
this.minHeight = 0,
|
||||
this.maxHeight = 700,
|
||||
this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// If no controller is passed, create one locally
|
||||
final DraggableBottomSheetController bottomSheetController =
|
||||
controller ??
|
||||
Get.put(
|
||||
DraggableBottomSheetController(
|
||||
initialVisibility: false, // always start hidden
|
||||
initialHeight: initialHeight,
|
||||
minHeight: minHeight,
|
||||
maxHeight: maxHeight,
|
||||
),
|
||||
tag: 'local_$hashCode',
|
||||
);
|
||||
|
||||
// Optionally show after first frame if isVisible is true
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (isVisible && !bottomSheetController.isVisible.value) {
|
||||
bottomSheetController.show();
|
||||
}
|
||||
});
|
||||
|
||||
return ObxValue(
|
||||
(data) => AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeOut,
|
||||
bottom: bottomSheetController.isVisible.value ? 0 : -maxHeight,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: GestureDetector(
|
||||
onVerticalDragUpdate: (DragUpdateDetails details) {
|
||||
bottomSheetController.updateHeight(details.delta.dy);
|
||||
},
|
||||
child: Container(
|
||||
height: data.value,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(50)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
|
||||
/* Container(
|
||||
width: 40,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[400],
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),*/
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
bottomSheetController.hide();
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [const Icon(CupertinoIcons.chevron_down)],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(child: child ?? SizedBox.shrink()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomSheetController.currentHeight,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
|
||||
class DraggableBottomSheetController extends GetxController {
|
||||
// Observable variables
|
||||
final RxBool isVisible = false.obs;
|
||||
final RxDouble currentHeight = 200.0.obs;
|
||||
|
||||
// Configuration values
|
||||
final double initialHeight;
|
||||
final double minHeight;
|
||||
final double maxHeight;
|
||||
|
||||
DraggableBottomSheetController({
|
||||
bool initialVisibility = false,
|
||||
this.initialHeight = 200,
|
||||
this.minHeight = 0,
|
||||
this.maxHeight = 700,
|
||||
}) {
|
||||
isVisible.value = initialVisibility;
|
||||
currentHeight.value = initialHeight;
|
||||
}
|
||||
|
||||
// Show the bottom sheet
|
||||
void show() {
|
||||
if (!isVisible.value) {
|
||||
isVisible.value = true;
|
||||
currentHeight.value = initialHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the bottom sheet
|
||||
void hide() {
|
||||
if (isVisible.value) {
|
||||
isVisible.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle visibility
|
||||
void toggle() {
|
||||
isVisible.value = !isVisible.value;
|
||||
if (isVisible.value) {
|
||||
currentHeight.value = initialHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Set a specific height for the bottom sheet
|
||||
void setHeight(double height) {
|
||||
final clampedHeight = height.clamp(minHeight, maxHeight);
|
||||
if (currentHeight.value != clampedHeight) {
|
||||
currentHeight.value = clampedHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// Update height (usually called during drag)
|
||||
void updateHeight(double delta) {
|
||||
final newHeight = currentHeight.value - delta;
|
||||
if(newHeight < minHeight) {
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
currentHeight.value = newHeight.clamp(minHeight, maxHeight);
|
||||
}
|
||||
|
||||
// Expand to maximum height
|
||||
void expandFully() {
|
||||
currentHeight.value = maxHeight;
|
||||
isVisible.value = true;
|
||||
}
|
||||
|
||||
// Collapse to minimum height
|
||||
void collapse() {
|
||||
currentHeight.value = minHeight;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
export 'vec_widget.dart';
|
||||
export 'bottom_navigation/bottom_navigation_1.dart';
|
||||
export 'draggable_bottom_sheet/draggable_bottom_sheet.dart';
|
||||
export 'draggable_bottom_sheet/draggable_bottom_sheet_controller.dart';
|
||||
|
||||
@@ -246,6 +246,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.1.1"
|
||||
flutter_map_animations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_map_animations
|
||||
sha256: bf583863561861aaaf4854ae7ed8940d79bea7d32918bf7a85d309b25235a09e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.0"
|
||||
flutter_svg:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user