做搜狗网站点击WordPress图片上传最大尺寸
news/
2025/10/9 2:09:22/
文章来源:
做搜狗网站点击,WordPress图片上传最大尺寸,辽宁好的百度seo公司,win7优化大师下载第一段 第二段 实现思路
通过 GestureDetector 的 Drag 方法#xff0c;动态改变Dialog的高度#xff0c;通过设置一个最大高度和最小高度分成两层进行展示
实现
常用的展示BottomSheet的方法为 showModalBottomSheet
/// 设置最高最好以高度的比例进行设置#xff0c;方…第一段 第二段 实现思路
通过 GestureDetector 的 Drag 方法动态改变Dialog的高度通过设置一个最大高度和最小高度分成两层进行展示
实现
常用的展示BottomSheet的方法为 showModalBottomSheet
/// 设置最高最好以高度的比例进行设置方便不同屏幕适配
final maxHeight MediaQuery.of(context).size.height * maxHeightRatio;
showModalBottomSheet(context: context,builder: (ctx) BottomSheetDialog(minHeight: minHeight, maxHeight: maxHeight),enableDrag: false,isScrollControlled: true,scrollControlDisabledMaxHeightRatio: maxHeightRatio,
);因为上面我们隐藏了自带的 DragHeader 这里自定义一个可拖动的Header
GestureDetector(behavior: HitTestBehavior.opaque,/// 正在拖动onVerticalDragUpdate: (detail) {/// 得到当前的高度double dragOffset _contentHeight - detail.delta.dy;if(dragOffset maxHeight) {dragOffset maxHeight;}if(dragOffset 0) {dragOffset 0;}setContentHeight(dragOffset);},/// 拖动结束onVerticalDragEnd: (detail) {print(onVerticalDragEnd);onDragEnd();},/// 取消拖动当作拖动结束处理onVerticalDragCancel: () {onDragEnd();},child: Container(height: 55,alignment: Alignment.center,child: const Text(Drag),),
),拖动结束处理
void onDragEnd() {/// 以两段中间值为界限回弹到指定的位置final mid (maxHeight - minHeight) / 2 minHeight;if(_contentHeight mid) {setContentHeight(maxHeight);} else if(_contentHeight minHeight / 3 * 2) {setContentHeight(minHeight);} else {/// 当滑动到第一段下面位置时就直接退出BottomSheetNavigator.pop(context);}
}完整代码
import package:ebon_smart_pay/app/core/widgets/bottom_sheet/bottom_sheet_dialog.dart;
import package:flutter/material.dart;
import package:flutter/services.dart;class BottomSheetPage extends StatelessWidget {const BottomSheetPage({Key? key}) : super(key: key);overrideWidget build(BuildContext context) {return AnnotatedRegion(value: const SystemUiOverlayStyle(statusBarColor: Colors.transparent),child: Center(child: FilledButton(onPressed: () BottomSheetDialog.show(context, MediaQuery.of(context).size.height * 0.5, 0.75),child: const Text(ShowBottomSheet),),),);}
}import package:flutter/material.dart;class BottomSheetDialog extends StatefulWidget {/// 设置高度final double minHeight;final double maxHeight;const BottomSheetDialog({Key? key, required this.minHeight, required this.maxHeight}) : super(key: key);static void show(BuildContext context, double minHeight, double maxHeightRatio) {final maxHeight MediaQuery.of(context).size.height * maxHeightRatio;showModalBottomSheet(context: context,builder: (ctx) BottomSheetDialog(minHeight: minHeight, maxHeight: maxHeight),enableDrag: false,isScrollControlled: true,scrollControlDisabledMaxHeightRatio: maxHeightRatio,);}overrideStateBottomSheetDialog createState() _BottomSheetDialogState();
}class _BottomSheetDialogState extends StateBottomSheetDialog {double _contentHeight 0;void setContentHeight(double height) setState(() {_contentHeight height;});overridevoid initState() {setContentHeight(widget.minHeight);super.initState();}overrideWidget build(BuildContext context) {return Container(height: _contentHeight,decoration: const BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)),color: Colors.white),child: SafeArea(child: Column(mainAxisSize: MainAxisSize.min,children: [GestureDetector(behavior: HitTestBehavior.opaque,onVerticalDragUpdate: (detail) {double dragOffset _contentHeight - detail.delta.dy;if(dragOffset maxHeight) {dragOffset maxHeight;}if(dragOffset 0) {dragOffset 0;}setContentHeight(dragOffset);},onVerticalDragEnd: (detail) {print(onVerticalDragEnd);onDragEnd();},onVerticalDragCancel: () {onDragEnd();},child: Container(height: 55,alignment: Alignment.center,child: const Text(Drag),),),const Divider(),Expanded(child: ListView.separated(itemBuilder: (ctx, index) Padding(padding: const EdgeInsets.all(10.0),child: Text(Item - $index),),separatorBuilder: (ctx, index) const Divider(),itemCount: 10))],),),);}void onDragEnd() {final mid (maxHeight - minHeight) / 2 minHeight;if(_contentHeight mid) {setContentHeight(maxHeight);} else if(_contentHeight minHeight / 3 * 2) {setContentHeight(minHeight);} else {Navigator.pop(context);}}double get minHeight widget.minHeight;double get maxHeight widget.maxHeight;}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/932131.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!