fix : bottom sheet draggable

This commit is contained in:
2025-04-16 15:16:25 +03:30
parent 363d83430c
commit 75903650b8
2 changed files with 55 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rasadyar_core/data/utils.dart';
import 'package:rasadyar_core/presentation/common/app_color.dart';
import 'package:rasadyar_core/presentation/widget/draggable_bottom_sheet/draggable_bottom_sheet_controller.dart';
class DraggableBottomSheet extends StatelessWidget {
@@ -17,7 +18,7 @@ class DraggableBottomSheet extends StatelessWidget {
super.key,
this.controller,
this.isVisible = false,
this.backgroundColor = Colors.white,
this.backgroundColor = AppColor.lightGreyNormal,
this.initialHeight = 200,
this.minHeight = 0,
this.maxHeight = 700,

View File

@@ -1,6 +1,12 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rasadyar_core/core.dart';
import 'draggable_bottom_sheet.dart';
class DraggableBottomSheetController extends GetxController {
final RxList<DraggableBottomSheet> bottomSheets =
<DraggableBottomSheet>[].obs;
// Observable variables
final RxBool isVisible = false.obs;
final RxDouble currentHeight = 200.0.obs;
@@ -17,7 +23,7 @@ class DraggableBottomSheetController extends GetxController {
this.maxHeight = 700,
}) {
isVisible.value = initialVisibility;
currentHeight.value = 0;
currentHeight.value = initialHeight;
}
// Show the bottom sheet
@@ -72,4 +78,50 @@ class DraggableBottomSheetController extends GetxController {
void collapse() {
currentHeight.value = minHeight;
}
void addBottomSheet({
required Widget child,
required double initHeight,
required double maxHeight,
required double minHeight,
}) {
final controller = DraggableBottomSheetController(
initialVisibility: true,
initialHeight: initHeight,
minHeight: minHeight,
maxHeight: maxHeight,
);
final bottomSheet = DraggableBottomSheet(
controller: controller,
backgroundColor: AppColor.lightGreyLightActive,
child: child,
);
if (bottomSheets.isNotEmpty) {
bottomSheets.removeLast();
}
bottomSheets.add(bottomSheet);
}
void removeLastBottomSheet() {
if (bottomSheets.isNotEmpty) {
bottomSheets.last.controller?.hide();
Future.delayed(Duration(milliseconds: 200), () {
bottomSheets.removeLast();
if(bottomSheets.isNotEmpty){
bottomSheets.last.controller?.show();
}
});
}
}
bool handleBack() {
if (bottomSheets.isNotEmpty) {
removeLastBottomSheet();
return true;
}
return false;
}
}