Flutter:showModalBottomSheet底部弹出完整页面

dart 复制代码
  // 弹出:商品详情信息页面
  void showInfoBottomSheet(int shopId, int goodsId) {
    showModalBottomSheet(
      context: Get.context!,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      isDismissible: true,
      enableDrag: true,
      builder: (context) {
        return Container(
          height: MediaQuery.of(context).size.height * 0.8,
          decoration: BoxDecoration(
            color: AppTheme.pageBgColor,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(40.w),
              topRight: Radius.circular(40.w),
            ),
          ),
          clipBehavior: Clip.antiAlias,
          child: InfoPage(
            arguments: {
              'shopId': shopId,
              'goodsId': goodsId,
              'customCallback': () {
                // 关闭弹窗
                Get.back();
                // 执行确认后的业务逻辑
                print('用户确认了商品ID: $goodsId');
                showCreateOrderBottomSheet(shopId, goodsId);
              },
            },
          ),
        );
      },
    );
  }

info页面需要接收参数和回调

dart 复制代码
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class InfoController extends GetxController {
  final Map<String, dynamic> arguments;
  InfoController({required this.arguments});
  // ID
  int shopId = 0;
  int goodsId = 0;
  // 自定义回调函数
  VoidCallback? customCallback;

  void _initData() async {
    shopId = arguments['shopId'] ?? 0;
    goodsId = arguments['goodsId'] ?? 0;
    customCallback = arguments['customCallback'];
    update(["info"]);
  }

  // 确认操作
  void onConfirm() {
    customCallback?.call();
  }

}
dart 复制代码
import 'package:ayidaojia/common/index.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:get/get.dart';

import 'index.dart';

class InfoPage extends GetView<InfoController> {
  const InfoPage({super.key, required this.arguments});
  final Map<String, dynamic> arguments;

  // 主视图
  Widget _buildView() {
    return <Widget>[
    ].toColumn();
  }
  // 底部按钮
  Widget _buildBottomBar() {
    var bottomStatusBarHeight = MediaQuery.of(Get.context!).padding.bottom;
    return <Widget>[
      ButtonWidget(
        text: '立即抢购',
        width: 750,
        height: 98,
        borderRadius: 0,
        onTap: () => controller.onConfirm(),
      ),
    ]
    .toRow(mainAxisAlignment: MainAxisAlignment.center)
    .paddingOnly(bottom: bottomStatusBarHeight);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<InfoController>(
      init: InfoController(arguments: arguments),
      id: "info",
      builder: (_) {
        return <Widget>[
          // 主体内容 内部可滚动
          Expanded(
            child: SingleChildScrollView(
              child: _buildView(),
            ),
          ),
          // 固定在底部按钮的按钮
          _buildBottomBar(),
        ].toColumn();
      },
    );
  }
}
相关推荐
星恒随风14 分钟前
从0实现C++ AI大模型接入SDK(八):SessionManager会话管理——智能指针、原子操作、线程安全与懒加载机制
linux·服务器·开发语言·c++·人工智能
yingjie1101 小时前
快榜GEO|官网 AI 可读性自查 12 项(附 Python 检测脚本)
开发语言·人工智能·python
Felven1 小时前
C. Make Them Equal
c语言·开发语言·前端
tryCbest2 小时前
Python 爬虫扩展篇(二):验证码的检测与人工介入——把“拦路虎”当作信号,而不是要征服的对手
开发语言·爬虫·python
风落青芜4 小时前
排序算法(四):归并排序、计数排序与算法总结
c语言·开发语言·数据结构·算法·排序算法
Resean02234 小时前
讲透Java(14)泛型的本质:类型擦除与桥接方法
java·开发语言
apcipot_rain9 小时前
C++开发 面试 1Day速通
开发语言·c++·面试
时间的情敌10 小时前
Three.js GLTF 阀门 / 泵体模型加载、材质修改、状态联动(正常 / 故障 / 告警变色)
开发语言·javascript·three.js·材质
星恒随风10 小时前
从0实现C++ AI大模型接入SDK(七):Ollama本地模型部署、NDJSON流式响应与LLMManager模型管理
linux·开发语言·c++·人工智能·笔记
琳少_11 小时前
java课堂笔记
java·开发语言·数据库·笔记