fix : bottom sheet draggable
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:rasadyar_core/data/utils.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';
|
import 'package:rasadyar_core/presentation/widget/draggable_bottom_sheet/draggable_bottom_sheet_controller.dart';
|
||||||
|
|
||||||
class DraggableBottomSheet extends StatelessWidget {
|
class DraggableBottomSheet extends StatelessWidget {
|
||||||
@@ -17,7 +18,7 @@ class DraggableBottomSheet extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
this.controller,
|
this.controller,
|
||||||
this.isVisible = false,
|
this.isVisible = false,
|
||||||
this.backgroundColor = Colors.white,
|
this.backgroundColor = AppColor.lightGreyNormal,
|
||||||
this.initialHeight = 200,
|
this.initialHeight = 200,
|
||||||
this.minHeight = 0,
|
this.minHeight = 0,
|
||||||
this.maxHeight = 700,
|
this.maxHeight = 700,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
import 'draggable_bottom_sheet.dart';
|
||||||
|
|
||||||
class DraggableBottomSheetController extends GetxController {
|
class DraggableBottomSheetController extends GetxController {
|
||||||
|
final RxList<DraggableBottomSheet> bottomSheets =
|
||||||
|
<DraggableBottomSheet>[].obs;
|
||||||
|
|
||||||
// Observable variables
|
// Observable variables
|
||||||
final RxBool isVisible = false.obs;
|
final RxBool isVisible = false.obs;
|
||||||
final RxDouble currentHeight = 200.0.obs;
|
final RxDouble currentHeight = 200.0.obs;
|
||||||
@@ -17,7 +23,7 @@ class DraggableBottomSheetController extends GetxController {
|
|||||||
this.maxHeight = 700,
|
this.maxHeight = 700,
|
||||||
}) {
|
}) {
|
||||||
isVisible.value = initialVisibility;
|
isVisible.value = initialVisibility;
|
||||||
currentHeight.value = 0;
|
currentHeight.value = initialHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the bottom sheet
|
// Show the bottom sheet
|
||||||
@@ -72,4 +78,50 @@ class DraggableBottomSheetController extends GetxController {
|
|||||||
void collapse() {
|
void collapse() {
|
||||||
currentHeight.value = minHeight;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user